mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 22:15:20 +00:00
Merge branch 'mnowak/pytest_rewrite_sortlist' into 'main'
Rewrite sortlist system test to pytest See merge request isc-projects/bind9!8684
This commit is contained in:
@@ -20,16 +20,22 @@ QUERY_TIMEOUT = 10
|
|||||||
|
|
||||||
|
|
||||||
def udp(
|
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:
|
) -> dns.message.Message:
|
||||||
if port is None:
|
if port is None:
|
||||||
port = int(os.environ["PORT"])
|
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(
|
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:
|
) -> dns.message.Message:
|
||||||
if port is None:
|
if port is None:
|
||||||
port = int(os.environ["PORT"])
|
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)
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
# information regarding copyright ownership.
|
# information regarding copyright ownership.
|
||||||
|
|
||||||
[pytest]
|
[pytest]
|
||||||
addopts = --tb=short -rA
|
addopts = --tb=short -rA -vv
|
||||||
log_format = %(asctime)s %(levelname)s:%(name)s %(message)s
|
log_format = %(asctime)s %(levelname)s:%(name)s %(message)s
|
||||||
log_date_format = %Y-%m-%d %H:%M:%S
|
log_date_format = %Y-%m-%d %H:%M:%S
|
||||||
log_cli = 1
|
log_cli = 1
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
# See the COPYRIGHT file distributed with this work for additional
|
# See the COPYRIGHT file distributed with this work for additional
|
||||||
# information regarding copyright ownership.
|
# information regarding copyright ownership.
|
||||||
|
|
||||||
rm -f *.dig *.good *.out
|
|
||||||
rm -f */named.memstats
|
rm -f */named.memstats
|
||||||
rm -f */named.run
|
rm -f */named.run
|
||||||
rm -f */named.conf
|
rm -f */named.conf
|
||||||
|
@@ -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
|
|
@@ -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()
|
|
53
bin/tests/system/sortlist/tests_sortlist.py
Normal file
53
bin/tests/system/sortlist/tests_sortlist.py
Normal file
@@ -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"
|
Reference in New Issue
Block a user