2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-03 15:35:17 +00:00

[#2038] escape commas in kea-admin lease-dump mysql

This commit is contained in:
Andrei Pavel
2022-01-11 19:19:25 +02:00
parent 0d8bcb16a9
commit 8883a639e8
6 changed files with 28 additions and 32 deletions

View File

@@ -1,4 +1,4 @@
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state,user_context
0.0.0.10,32:30,33:30,40,1420067730,50,1,1,one.example.com,0, 0.0.0.10,32:30,33:30,40,1420067730,50,1,1,one.example.com,0,
0.0.0.11,,31:32:33,40,1422837045,50,1,1,,1, 0.0.0.11,,31:32:33,40,1422837045,50,1,1,,1,{}
0.0.0.12,32:32,,40,1425373267,50,1,1,three.example.com,2, 0.0.0.12,32:32,,40,1425373267,50,1,1,three&#x2cexample&#x2ccom,2,{"a":1&#x2c"b":"c"}
Can't render this file because it contains an unexpected character in line 4 and column 67.

View File

@@ -1,4 +1,4 @@
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source
::10,32:30,30,1428099330,40,50,1,60,70,1,1,one.example.com,38:30,0,,90,16 ::10,32:30,30,1428099330,40,50,1,60,70,1,1,one.example.com,38:30,0,,90,16
::11,,30,1430782245,40,50,1,60,70,1,1,,38:30,1,,90,1 ::11,,30,1430782245,40,50,1,60,70,1,1,,38:30,1,{},90,1
::12,32:31,30,1433577667,40,50,1,60,70,1,1,three.example.com,38:30,2,,90,4 ::12,32:31,30,1433577667,40,50,1,60,70,1,1,three&#x2cexample&#x2ccom,38:30,2,{"a":1&#x2c"b":"c"},90,4
Can't render this file because it contains an unexpected character in line 4 and column 79.

View File

@@ -68,10 +68,10 @@ memfile_header_v6() {
# Print data copied from mysql_upgrade_12_to_13_test and pgsql_upgrade_7_0_to_8_0. # Print data copied from mysql_upgrade_12_to_13_test and pgsql_upgrade_7_0_to_8_0.
# @{ # @{
memfile_data_v4() { memfile_data_v4() {
printf '0.0.0.10,32:30,33:30,40,1643757330,50,1,1,one.example.com,0,' printf '0.0.0.10,32:30,33:30,40,1643757330,50,1,1,one&#x2cexample&#x2ccom,0,{ "a": 1&#x2c "b": 2 }'
} }
memfile_data_v6() { memfile_data_v6() {
printf '::10,32:30,30,1643757330,40,50,1,60,70,1,1,one.example.com,38:30,0,,90,16' printf '::10,32:30,30,1643757330,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{ "a": 1&#x2c "b": 2 },90,16'
} }
# @} # @}
@@ -141,7 +141,7 @@ memfile_init_test() {
# Test that Kea accepts the output of lease-dump in memfile. # Test that Kea accepts the output of lease-dump in memfile.
{ {
"memfile_header_v${v}" "memfile_header_v${v}"
printf '\n' >> "${csv}" printf '\n'
"memfile_data_v${v}" "memfile_data_v${v}"
printf '\n' printf '\n'
} > "${csv}" } > "${csv}"
@@ -165,7 +165,7 @@ memfile_init_test() {
clean_up clean_up
clean_exit 1 clean_exit 1
fi fi
kill "${PID}" kill "${PID}" || true # process may have exited early due to errors
if ! wait_for_process_to_stop "${PID}"; then if ! wait_for_process_to_stop "${PID}"; then
clean_up clean_up
clean_exit 2 clean_exit 2

View File

@@ -251,8 +251,6 @@ mysql_upgrade_schema_to_version() {
} }
mysql_upgrade_12_to_13_test() { mysql_upgrade_12_to_13_test() {
mysql_wipe
# Check the output of colonSeparatedHex(). # Check the output of colonSeparatedHex().
run_command \ run_command \
mysql_execute 'SELECT colonSeparatedHex(HEX(0xF123456789));' mysql_execute 'SELECT colonSeparatedHex(HEX(0xF123456789));'
@@ -281,7 +279,7 @@ mysql_upgrade_12_to_13_test() {
# Check lease4Dump*(). # Check lease4Dump*().
run_command \ run_command \
mysql_execute "INSERT INTO lease4 VALUES(10,20,30,40,'2022-02-002 01:15:30',50,1,1,'one.example.com',0,NULL);" mysql_execute "INSERT INTO lease4 VALUES(10,20,30,40,'2022-02-002 01:15:30',50,1,1,'one,example,com',0,'{ \"a\": 1, \"b\": 2 }');"
assert_eq 0 "${EXIT_CODE}" 'INSERT INTO lease4 failed, expected exit code %d, actual %d' assert_eq 0 "${EXIT_CODE}" 'INSERT INTO lease4 failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}" assert_str_eq '' "${OUTPUT}"
@@ -293,12 +291,12 @@ mysql_upgrade_12_to_13_test() {
run_command \ run_command \
mysql_execute "CALL lease4DumpData();" mysql_execute "CALL lease4DumpData();"
assert_eq 0 "${EXIT_CODE}" 'lease4DumpData() failed, expected exit code %d, actual %d' assert_eq 0 "${EXIT_CODE}" 'lease4DumpData() failed, expected exit code %d, actual %d'
output=$(printf '%s' "${OUTPUT}" | xargs) # squash consecutive spaces output=$(printf '%s' "${OUTPUT}" | sed 's/\t/,/g') # turn tabs into commas
assert_str_eq '0.0.0.10 32:30 33:30 40 1643757330 50 1 1 one.example.com 0' "${output}" assert_str_eq '0.0.0.10,32:30,33:30,40,1643757330,50,1,1,one&#x2cexample&#x2ccom,0,{ "a": 1&#x2c "b": 2 }' "${output}"
# Check lease6Dump*(). # Check lease6Dump*().
run_command \ run_command \
mysql_execute "INSERT INTO lease6 VALUES('::10',20,30,'2022-02-02 01:15:30',40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL);" mysql_execute "INSERT INTO lease6 VALUES('::10',20,30,'2022-02-02 01:15:30',40,50,1,60,70,1,1,'one,example,com',80,90,16,0,'{ \"a\": 1, \"b\": 2 }');"
assert_eq 0 "${EXIT_CODE}" 'INSERT INTO lease6 failed, expected exit code %d, actual %d' assert_eq 0 "${EXIT_CODE}" 'INSERT INTO lease6 failed, expected exit code %d, actual %d'
assert_str_eq '' "${OUTPUT}" assert_str_eq '' "${OUTPUT}"
@@ -310,10 +308,8 @@ mysql_upgrade_12_to_13_test() {
run_command \ run_command \
mysql_execute "CALL lease6DumpData();" mysql_execute "CALL lease6DumpData();"
assert_eq 0 "${EXIT_CODE}" 'lease6DumpData() failed, expected exit code %d, actual %d' assert_eq 0 "${EXIT_CODE}" 'lease6DumpData() failed, expected exit code %d, actual %d'
output=$(printf '%s' "${OUTPUT}" | xargs) # squash consecutive spaces output=$(printf '%s' "${OUTPUT}" | sed 's/\t/,/g') # turn tabs into commas
assert_str_eq '::10 32:30 30 1643757330 40 50 1 60 70 1 1 one.example.com 38:30 0 90 16' "${output}" assert_str_eq '::10,32:30,30,1643757330,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{ "a": 1&#x2c "b": 2 },90,16' "${output}"
mysql_wipe
} }
mysql_upgrade_test() { mysql_upgrade_test() {
@@ -416,7 +412,7 @@ mysql_upgrade_test() {
mysql_execute "${qry}" mysql_execute "${qry}"
assert_eq 0 "${EXIT_CODE}" "procedure text fetch for lease4DumpData failed. (returned status code %d, expected %d)" assert_eq 0 "${EXIT_CODE}" "procedure text fetch for lease4DumpData failed. (returned status code %d, expected %d)"
count=$(echo "${OUTPUT}" | grep -Eci 'order by [a-z]*[\.]?address') || true count=$(echo "${OUTPUT}" | grep -Eci 'order by [a-z]*[\.]?address') || true
assert_eq 1 "${count}" "lease4DumpData doesn't have order by clause. (returned count %d, expected %d)" assert_eq 1 "${count}" "lease4DumpData is missing order by clause. (expected count %d, returned %d)"
# verify lease6DumpData has order by lease address # verify lease6DumpData has order by lease address
qry="show create procedure lease6DumpData" qry="show create procedure lease6DumpData"
@@ -999,9 +995,9 @@ mysql_lease4_dump_test() {
# Insert the reference record # Insert the reference record
insert_sql="\ insert_sql="\
insert into lease4 values(10,20,30,40,'2015-01-01 01:15:30',50,1,1,'one.example.com', 0,NULL);\ insert into lease4 values(10,20,30,40,'2015-01-01 01:15:30',50,1,1,'one.example.com',0,NULL);\
insert into lease4 values(11,NULL,123,40,'2015-02-02 02:30:45',50,1,1,'', 1,NULL);\ insert into lease4 values(11,NULL,123,40,'2015-02-02 02:30:45',50,1,1,'',1,'{}');\
insert into lease4 values(12,22,NULL,40,'2015-03-03 11:01:07',50,1,1,'three.example.com', 2,NULL);" insert into lease4 values(12,22,NULL,40,'2015-03-03 11:01:07',50,1,1,'three,example,com',2,'{\"a\":1,\"b\":\"c\"}');"
run_command \ run_command \
mysql_execute "$insert_sql" mysql_execute "$insert_sql"
@@ -1059,8 +1055,8 @@ mysql_lease6_dump_test() {
# Insert the reference record # Insert the reference record
insert_sql="\ insert_sql="\
insert into lease6 values('::10',20,30,'2015-04-04 01:15:30',40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL);\ insert into lease6 values('::10',20,30,'2015-04-04 01:15:30',40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL);\
insert into lease6 values('::11',NULL,30,'2015-05-05 02:30:45',40,50,1,60,70,1,1,'',80,90,1,1,NULL);\ insert into lease6 values('::11',NULL,30,'2015-05-05 02:30:45',40,50,1,60,70,1,1,'',80,90,1,1,'{}');\
insert into lease6 values('::12',21,30,'2015-06-06 11:01:07',40,50,1,60,70,1,1,'three.example.com',80,90,4,2,NULL);" insert into lease6 values('::12',21,30,'2015-06-06 11:01:07',40,50,1,60,70,1,1,'three,example,com',80,90,4,2,'{\"a\":1,\"b\":\"c\"}');"
run_command \ run_command \
mysql_execute "$insert_sql" mysql_execute "$insert_sql"

View File

@@ -4113,9 +4113,9 @@ BEGIN
subnet_id, subnet_id,
fqdn_fwd, fqdn_fwd,
fqdn_rev, fqdn_rev,
hostname, REPLACE(hostname, ',', '&#x2c'),
state, state,
IFNULL(user_context, '') REPLACE(IFNULL(user_context, ''), ',', '&#x2c')
FROM lease4 FROM lease4
ORDER BY address; ORDER BY address;
END $$ END $$
@@ -4147,10 +4147,10 @@ BEGIN
prefix_len, prefix_len,
fqdn_fwd, fqdn_fwd,
fqdn_rev, fqdn_rev,
hostname, REPLACE(hostname, ',', '&#x2c'),
IFNULL(colonSeparatedHex(HEX(hwaddr)), ''), IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
state, state,
IFNULL(user_context, ''), REPLACE(IFNULL(user_context, ''), ',', '&#x2c'),
hwtype, hwtype,
hwaddr_source hwaddr_source
FROM lease6 FROM lease6

View File

@@ -89,9 +89,9 @@ BEGIN
subnet_id, subnet_id,
fqdn_fwd, fqdn_fwd,
fqdn_rev, fqdn_rev,
hostname, REPLACE(hostname, ',', '&#x2c'),
state, state,
IFNULL(user_context, '') REPLACE(IFNULL(user_context, ''), ',', '&#x2c')
FROM lease4 FROM lease4
ORDER BY address; ORDER BY address;
END $$ END $$
@@ -123,10 +123,10 @@ BEGIN
prefix_len, prefix_len,
fqdn_fwd, fqdn_fwd,
fqdn_rev, fqdn_rev,
hostname, REPLACE(hostname, ',', '&#x2c'),
IFNULL(colonSeparatedHex(HEX(hwaddr)), ''), IFNULL(colonSeparatedHex(HEX(hwaddr)), ''),
state, state,
IFNULL(user_context, ''), REPLACE(IFNULL(user_context, ''), ',', '&#x2c'),
hwtype, hwtype,
hwaddr_source hwaddr_source
FROM lease6 FROM lease6