From 4a203dcb9368b5e5e3e6066db6fa9ec25d7e669d Mon Sep 17 00:00:00 2001 From: Michal Nowak Date: Wed, 31 Jan 2024 19:11:16 +0100 Subject: [PATCH 1/3] Support "source" parameter in isctest.query.(tcp|udp) --- bin/tests/system/isctest/query.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/tests/system/isctest/query.py b/bin/tests/system/isctest/query.py index 5da1ef8423..329558d272 100644 --- a/bin/tests/system/isctest/query.py +++ b/bin/tests/system/isctest/query.py @@ -20,16 +20,22 @@ QUERY_TIMEOUT = 10 def udp( - message: dns.message.Message, ip: str, port: Optional[int] = None + message: dns.message.Message, + ip: str, + port: Optional[int] = None, + source: Optional[str] = None, ) -> dns.message.Message: if port is None: port = int(os.environ["PORT"]) - return dns.query.udp(message, ip, QUERY_TIMEOUT, port=port) + return dns.query.udp(message, ip, QUERY_TIMEOUT, port=port, source=source) def tcp( - message: dns.message.Message, ip: str, port: Optional[int] = None + message: dns.message.Message, + ip: str, + port: Optional[int] = None, + source: Optional[str] = None, ) -> dns.message.Message: if port is None: port = int(os.environ["PORT"]) - return dns.query.tcp(message, ip, QUERY_TIMEOUT, port=port) + return dns.query.tcp(message, ip, QUERY_TIMEOUT, port=port, source=source) From e7b5cf7f794fba5763438236d2223eec43c3bb92 Mon Sep 17 00:00:00 2001 From: Michal Nowak Date: Wed, 31 Jan 2024 19:14:25 +0100 Subject: [PATCH 2/3] Rewrite sortlist system test to pytest --- bin/tests/system/sortlist/clean.sh | 1 - bin/tests/system/sortlist/tests.sh | 52 ------------------ .../system/sortlist/tests_sh_sortlist.py | 14 ----- bin/tests/system/sortlist/tests_sortlist.py | 53 +++++++++++++++++++ 4 files changed, 53 insertions(+), 67 deletions(-) delete mode 100644 bin/tests/system/sortlist/tests.sh delete mode 100644 bin/tests/system/sortlist/tests_sh_sortlist.py create mode 100644 bin/tests/system/sortlist/tests_sortlist.py diff --git a/bin/tests/system/sortlist/clean.sh b/bin/tests/system/sortlist/clean.sh index 3ca616cecc..afbae2d37a 100644 --- a/bin/tests/system/sortlist/clean.sh +++ b/bin/tests/system/sortlist/clean.sh @@ -11,7 +11,6 @@ # See the COPYRIGHT file distributed with this work for additional # information regarding copyright ownership. -rm -f *.dig *.good *.out rm -f */named.memstats rm -f */named.run rm -f */named.conf diff --git a/bin/tests/system/sortlist/tests.sh b/bin/tests/system/sortlist/tests.sh deleted file mode 100644 index 44c9fe22d9..0000000000 --- a/bin/tests/system/sortlist/tests.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh - -# Copyright (C) Internet Systems Consortium, Inc. ("ISC") -# -# SPDX-License-Identifier: MPL-2.0 -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, you can obtain one at https://mozilla.org/MPL/2.0/. -# -# See the COPYRIGHT file distributed with this work for additional -# information regarding copyright ownership. - -set -e - -. ../conf.sh - -DIGOPTS="+tcp +noadd +nosea +nostat +noquest +noauth +nocomm +nocmd -p ${PORT}" - -status=0 - -echo_i "test 2-element sortlist statement" -cat <test1.good -a.example. 300 IN A 192.168.3.1 -a.example. 300 IN A 192.168.1.1 -a.example. 300 IN A 1.1.1.5 -a.example. 300 IN A 1.1.1.1 -a.example. 300 IN A 1.1.1.3 -a.example. 300 IN A 1.1.1.2 -a.example. 300 IN A 1.1.1.4 -EOF -$DIG $DIGOPTS a.example. @10.53.0.1 -b 10.53.0.1 >test1.dig || status=1 -# Note that this can't use digcomp.pl because here, the ordering of the -# result RRs is significant. -diff test1.dig test1.good || status=1 - -echo_i "test 1-element sortlist statement and undocumented BIND 8 features" -cat <test2.good -b.example. 300 IN A 10.53.0.$n -EOF - -$DIG $DIGOPTS b.example. @10.53.0.1 -b 10.53.0.2 | sed 1q \ - | grep -E '10.53.0.(2|3)$' >test2.out \ - && $DIG $DIGOPTS b.example. @10.53.0.1 -b 10.53.0.3 | sed 1q \ - | grep -E '10.53.0.(2|3)$' >>test2.out \ - && $DIG $DIGOPTS b.example. @10.53.0.1 -b 10.53.0.4 | sed 1q \ - | grep -E '10.53.0.4$' >>test2.out \ - && $DIG $DIGOPTS b.example. @10.53.0.1 -b 10.53.0.5 | sed 1q \ - | grep -E '10.53.0.5$' >>test2.out || status=1 - -echo_i "exit status: $status" -[ $status -eq 0 ] || exit 1 diff --git a/bin/tests/system/sortlist/tests_sh_sortlist.py b/bin/tests/system/sortlist/tests_sh_sortlist.py deleted file mode 100644 index 5a66d7dde9..0000000000 --- a/bin/tests/system/sortlist/tests_sh_sortlist.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (C) Internet Systems Consortium, Inc. ("ISC") -# -# SPDX-License-Identifier: MPL-2.0 -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, you can obtain one at https://mozilla.org/MPL/2.0/. -# -# See the COPYRIGHT file distributed with this work for additional -# information regarding copyright ownership. - - -def test_sortlist(run_tests_sh): - run_tests_sh() diff --git a/bin/tests/system/sortlist/tests_sortlist.py b/bin/tests/system/sortlist/tests_sortlist.py new file mode 100644 index 0000000000..f5c68c86af --- /dev/null +++ b/bin/tests/system/sortlist/tests_sortlist.py @@ -0,0 +1,53 @@ +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +import dns.message + +import pytest + +import isctest + + +def test_sortlist(): + """Test two-element sortlist statement""" + msg = dns.message.make_query("a.example.", "A") + resp = isctest.query.tcp(msg, "10.53.0.1", source="10.53.0.1") + sortlist = [ + "192.168.3.1", + "192.168.1.1", + "1.1.1.5", + "1.1.1.1", + "1.1.1.3", + "1.1.1.2", + "1.1.1.4", + ] + rrset = dns.rrset.from_text_list("a.example.", 300, "IN", "A", sortlist) + assert len(resp.answer) == 1 + assert resp.answer[0] == rrset + assert list(resp.answer[0].items) == list(rrset.items) + + +@pytest.mark.parametrize( + "source_ip,possible_results", + [ + ("10.53.0.2", ["10.53.0.2", "10.53.0.3"]), + ("10.53.0.3", ["10.53.0.2", "10.53.0.3"]), + ("10.53.0.4", ["10.53.0.4"]), + ("10.53.0.5", ["10.53.0.5"]), + ], +) +def test_sortlist_compat(possible_results, source_ip): + """Test one-element sortlist statement and undocumented BIND 8 features""" + msg = dns.message.make_query("b.example.", "A") + resp = isctest.query.tcp(msg, "10.53.0.1", source=source_ip) + assert ( + resp.answer[0][0].to_text() in possible_results + ), f"{possible_results} not found" From bcbe34e22dd30a7235417ab6c38541a1556fa4bd Mon Sep 17 00:00:00 2001 From: Michal Nowak Date: Wed, 21 Feb 2024 18:02:05 +0100 Subject: [PATCH 3/3] Make pytest a bit more verbose The "-vv" option gives us full untruncated diffs of compared data strustures. --- bin/tests/system/pytest.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/tests/system/pytest.ini b/bin/tests/system/pytest.ini index a8733cefb6..ff17998e35 100644 --- a/bin/tests/system/pytest.ini +++ b/bin/tests/system/pytest.ini @@ -10,7 +10,7 @@ # information regarding copyright ownership. [pytest] -addopts = --tb=short -rA +addopts = --tb=short -rA -vv log_format = %(asctime)s %(levelname)s:%(name)s %(message)s log_date_format = %Y-%m-%d %H:%M:%S log_cli = 1