]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Rewrite sortlist system test to pytest
authorMichal Nowak <mnowak@isc.org>
Wed, 31 Jan 2024 18:14:25 +0000 (19:14 +0100)
committerMichal Nowak <mnowak@isc.org>
Thu, 22 Feb 2024 17:02:25 +0000 (18:02 +0100)
bin/tests/system/sortlist/clean.sh
bin/tests/system/sortlist/tests.sh [deleted file]
bin/tests/system/sortlist/tests_sh_sortlist.py [deleted file]
bin/tests/system/sortlist/tests_sortlist.py [new file with mode: 0644]

index 3ca616ceccd25e40460e7fadf8a659219428c91f..afbae2d37a2775a60c80f645c36eb4220dd88041 100644 (file)
@@ -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 (file)
index 44c9fe2..0000000
+++ /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 <<EOF >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 <<EOF >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 (file)
index 5a66d7d..0000000
+++ /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 (file)
index 0000000..f5c68c8
--- /dev/null
@@ -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"