From: Martin Basti Date: Wed, 22 Jul 2026 21:47:34 +0000 (+0000) Subject: Migrate digdelv dig +yaml structure checks to pytest X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98cab3a7d559c47ffc9e12543a1ea1c6941a84a1;p=thirdparty%2Fbind9.git Migrate digdelv dig +yaml structure checks to pytest Move the remaining dig checks from tests.sh into tests_dig.py: the structure of +yaml output for an ANY query, the printing of an IPv6 address ending in zeroes, the quoting of qnames containing characters special to YAML, and the quoting of all 256 character values in TXT rdata, whose expected string is now computed instead of spelled out over thirty lines. This completes the dig section of tests.sh, so the dig_with_opts and set_response_sequence helpers are removed with it. Assisted-by: Claude:claude-fable-5 --- diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index a00494dcafa..6bf4eafdbbd 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -19,20 +19,10 @@ set -e status=0 n=0 -dig_with_opts() { - "$DIG" -p "$PORT" "$@" -} - mdig_with_opts() { "$MDIG" -p "$PORT" "$@" } -set_response_sequence() { - SEQUENCE="${1}" - LOGID="${2}" - dig_with_opts @10.53.0.5 "${SEQUENCE}.response-sequence._control" TXT >dig.out.control${LOGID} 2>&1 || ret=1 -} - # Check if response in file $1 has the correct TTL range. # The response record must have RRtype $2 and class IN (CLASS1). # Maximum TTL is given by $3. This works in most cases where TTL is @@ -73,38 +63,6 @@ NOSPLIT="$(sed /dev/null && HAS_PYYAML=1 -if [ -x "$DIG" ]; then - if [ $HAS_PYYAML -ne 0 ]; then - n=$((n + 1)) - echo_i "check dig +yaml ANY output ($n)" - ret=0 - dig_with_opts +qr +yaml @10.53.0.3 any ns2.example >dig.out.test$n 2>&1 || ret=1 - $PYTHON yamlget.py dig.out.test$n 0 message query_message_data status >yamlget.out.test$n 2>&1 || ret=1 - read -r value yamlget.out.test$n 2>&1 || ret=1 - read -r value yamlget.out.test$n 2>&1 || ret=1 - read -r value dig.out.test$n 2>&1 || ret=1 - $PYTHON yamlget.py dig.out.test$n 1 message response_message_data ANSWER_SECTION 0 >yamlget.out.test$n 2>&1 || ret=1 - read -r value dig.out.test$n 2>&1 || ret=1 - $PYTHON yamlget.py dig.out.test$n 0 message query_message_data QUESTION_SECTION 0 >yamlget.out.test$n 2>&1 || ret=1 - read -r value yamlget.out.test$n 2>&1 || ret=1 - read -r value dig.out.test$n 2>&1 || ret=1 - $PYTHON yamlget.py dig.out.test$n 1 message response_message_data ANSWER_SECTION 0 >yamlget.out.test$n 2>&1 || ret=1 - read -r value " "?" "@" "A" "B" "C" "D" "E" "F" "G" "H"' - expected="$expected "'"I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V"' - expected="$expected "'"W" "X" "Y" "Z" "[" "\\" "]" "^" "_" "`" "a" "b" "c" "d"' - expected="$expected "'"e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r"' - expected="$expected "'"s" "t" "u" "v" "w" "x" "y" "z" "{" "|" "}" "~" "\127"' - expected="$expected "'"\128" "\129" "\130" "\131" "\132" "\133" "\134" "\135"' - expected="$expected "'"\136" "\137" "\138" "\139" "\140" "\141" "\142" "\143"' - expected="$expected "'"\144" "\145" "\146" "\147" "\148" "\149" "\150" "\151"' - expected="$expected "'"\152" "\153" "\154" "\155" "\156" "\157" "\158" "\159"' - expected="$expected "'"\160" "\161" "\162" "\163" "\164" "\165" "\166" "\167"' - expected="$expected "'"\168" "\169" "\170" "\171" "\172" "\173" "\174" "\175"' - expected="$expected "'"\176" "\177" "\178" "\179" "\180" "\181" "\182" "\183"' - expected="$expected "'"\184" "\185" "\186" "\187" "\188" "\189" "\190" "\191"' - expected="$expected "'"\192" "\193" "\194" "\195" "\196" "\197" "\198" "\199"' - expected="$expected "'"\200" "\201" "\202" "\203" "\204" "\205" "\206" "\207"' - expected="$expected "'"\208" "\209" "\210" "\211" "\212" "\213" "\214" "\215"' - expected="$expected "'"\216" "\217" "\218" "\219" "\220" "\221" "\222" "\223"' - expected="$expected "'"\224" "\225" "\226" "\227" "\228" "\229" "\230" "\231"' - expected="$expected "'"\232" "\233" "\234" "\235" "\236" "\237" "\238" "\239"' - expected="$expected "'"\240" "\241" "\242" "\243" "\244" "\245" "\246" "\247"' - expected="$expected "'"\248" "\249" "\250" "\251" "\252" "\253" "\254" "\255"' - [ "$value" = "$expected" ] || ret=1 - if [ $ret -ne 0 ]; then echo_i "failed"; fi - status=$((status + ret)) -fi - echo_i "exit status: $status" [ $status -eq 0 ] || exit 1 diff --git a/bin/tests/system/digdelv/tests_dig.py b/bin/tests/system/digdelv/tests_dig.py index 6c1ec1b6798..e1ee7859533 100644 --- a/bin/tests/system/digdelv/tests_dig.py +++ b/bin/tests/system/digdelv/tests_dig.py @@ -1014,3 +1014,60 @@ def test_source_address_both_families_no_crash(dig, ns1): by a signal) is an error. See GL #5609 for more information.""" result = dig(f"@localhost example -b {ns1.ip}", raise_on_exception=False) assert result.rc >= 0 + + +@needs_pyyaml +def test_yaml_any_output(dig, ns3): + """Check the structure of dig +yaml output for an ANY query.""" + result = dig(f"+qr +yaml @{ns3.ip} any ns2.example") + messages = parse_yaml(result.out) + query = messages[0]["message"]["query_message_data"] + assert query["status"] == "NOERROR" + response = messages[1]["message"]["response_message_data"] + assert response["status"] == "NOERROR" + assert response["QUESTION_SECTION"][0] == "ns2.example. IN ANY" + + +@needs_pyyaml +def test_yaml_ipv6_trailing_zeroes(dig, ns3): + """Check dig +yaml output of an IPv6 address ending in zeroes.""" + result = dig(f"+qr +yaml @{ns3.ip} aaaa d.example") + response = parse_yaml(result.out)[1]["message"]["response_message_data"] + answer = response["ANSWER_SECTION"][0] + assert answer == "d.example. 300 IN AAAA fd92:7065:b8e:ffff::0" + + +@needs_pyyaml +@pytest.mark.parametrize( + "qname", ["yaml", "'.yaml", "[.yaml", "{.yaml", "&.yaml", "#.yaml"] +) +def test_yaml_special_characters_in_qname(dig, ns3, qname): + """Check that qnames containing characters special to YAML are quoted + correctly in dig +yaml output.""" + result = dig(f"@{ns3.ip} +yaml {qname}.example TXT +qr") + query = parse_yaml(result.out)[0]["message"]["query_message_data"] + question = query["QUESTION_SECTION"][0] + assert question == f"{qname}.example. IN TXT" + response = parse_yaml(result.out)[1]["message"]["response_message_data"] + answer = response["ANSWER_SECTION"][0] + assert answer == f'{qname}.example. 300 IN TXT "a: b"' + + +@needs_pyyaml +def test_yaml_character_values(dig, ns3): + """Check the quoting of all 256 character values in dig +yaml TXT + output.""" + + def quoted(i): + char = chr(i) + if char in ('"', "\\"): + return f'"\\{char}"' + if 32 <= i <= 126: + return f'"{char}"' + return f'"\\{i:03d}"' + + result = dig(f"@{ns3.ip} +yaml all.yaml.example TXT +qr") + response = parse_yaml(result.out)[1]["message"]["response_message_data"] + answer = response["ANSWER_SECTION"][0] + strings = " ".join(quoted(i) for i in range(256)) + assert answer == f"all.yaml.example. 300 IN TXT {strings}"