# 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
+++ /dev/null
-#!/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
+++ /dev/null
-# 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()
--- /dev/null
+# 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"