From: Martin Basti Date: Wed, 22 Jul 2026 12:27:36 +0000 (+0000) Subject: Migrate digdelv nslookup/host/nsupdate checks to pytest X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f2f83a768ca3c90a60af2db6950edcd18d0dbdad;p=thirdparty%2Fbind9.git Migrate digdelv nslookup/host/nsupdate checks to pytest Move the UPDATE-opcode rejection checks for nslookup, host and nsupdate from tests.sh into a new tests_others.py module, which holds the checks for the look-up tools other than dig, delv and mdig. The new tests assert on the exact stream (stdout or stderr) each tool prints to, instead of the combined output the shell version grepped. Assisted-by: Claude:claude-fable-5 --- diff --git a/bin/tests/system/digdelv/common.py b/bin/tests/system/digdelv/common.py new file mode 100644 index 0000000000..dc1bb200f8 --- /dev/null +++ b/bin/tests/system/digdelv/common.py @@ -0,0 +1,27 @@ +# 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. + +""" +Helpers shared by the digdelv test modules. +""" + +ARTIFACTS = [ + "ans*/ans.run", + "ns*/anchor.*", + "ns*/dsset-*", + "ns*/keydata", + "ns*/keyid", + "ns*/K*.key", + "ns*/K*.private", + "ns1/root.db", + "ns2/example.db", + "ns2/example.tld.db", +] diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index 17587f7ab9..1d3c0c8514 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -73,36 +73,6 @@ NOSPLIT="$(sed /dev/null && HAS_PYYAML=1 -n=$((n + 1)) -echo_i "check nslookup handles UPDATE response ($n)" -ret=0 -"$NSLOOKUP" -q=CNAME -timeout=1 "-port=$PORT" foo.bar 10.53.0.6 >nslookup.out.test$n 2>&1 && ret=1 -grep "Opcode mismatch" nslookup.out.test$n >/dev/null || ret=1 -if [ $ret -ne 0 ]; then echo_i "failed"; fi -status=$((status + ret)) - -n=$((n + 1)) -echo_i "check host handles UPDATE response ($n)" -ret=0 -"$HOST" -W 1 -t CNAME -p $PORT foo.bar 10.53.0.6 >host.out.test$n 2>&1 && ret=1 -grep "Opcode mismatch" host.out.test$n >/dev/null || ret=1 -if [ $ret -ne 0 ]; then echo_i "failed"; fi -status=$((status + ret)) - -n=$((n + 1)) -echo_i "check nsupdate handles UPDATE response to QUERY ($n)" -ret=0 -res=0 -$NSUPDATE <nsupdate.out.test$n 2>&1 || res=$? -server 10.53.0.6 ${PORT} -add x.example.com 300 in a 1.2.3.4 -send -EOF -test $res -eq 1 || ret=1 -grep "invalid OPCODE in response to SOA query" nsupdate.out.test$n >/dev/null || ret=1 -if [ $ret -ne 0 ]; then echo_i "failed"; fi -status=$((status + ret)) - if [ -x "$DIG" ]; then n=$((n + 1)) echo_i "check dig handles UPDATE response ($n)" diff --git a/bin/tests/system/digdelv/tests_others.py b/bin/tests/system/digdelv/tests_others.py new file mode 100644 index 0000000000..3b097c62b2 --- /dev/null +++ b/bin/tests/system/digdelv/tests_others.py @@ -0,0 +1,73 @@ +# 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. + +""" +Tests for the look-up tools other than dig, delv and mdig: nslookup, +host and nsupdate. +""" + +from textwrap import dedent + +import os + +import pytest + +from digdelv.common import ARTIFACTS + +import isctest + +pytestmark = pytest.mark.extra_artifacts(ARTIFACTS) + + +@pytest.mark.skipif( + not os.access(os.environ.get("NSLOOKUP", ""), os.X_OK), + reason="nslookup executable not available", +) +def test_nslookup_update_response(named_port, ans6): + """Check that nslookup rejects a response with the UPDATE opcode.""" + nslookup = isctest.run.EnvCmd("NSLOOKUP") + result = nslookup( + f"-port={named_port} -q=CNAME -timeout=1 foo.bar {ans6.ip}", + raise_on_exception=False, + ) + assert result.rc != 0 + assert "Opcode mismatch" in result.out + + +@pytest.mark.skipif( + not os.access(os.environ.get("HOST", ""), os.X_OK), + reason="host executable not available", +) +def test_host_update_response(named_port, ans6): + """Check that host rejects a response with the UPDATE opcode.""" + host = isctest.run.EnvCmd("HOST") + result = host( + f"-p {named_port} -W 1 -t CNAME foo.bar {ans6.ip}", raise_on_exception=False + ) + assert result.rc != 0 + assert "Opcode mismatch" in result.out + + +@pytest.mark.skipif( + not os.access(os.environ.get("NSUPDATE", ""), os.X_OK), + reason="nsupdate executable not available", +) +def test_nsupdate_update_response(named_port, ans6): + """Check that nsupdate rejects an UPDATE response to its SOA query.""" + nsupdate = isctest.run.EnvCmd("NSUPDATE") + commands = dedent(f"""\ + server {ans6.ip} {named_port} + add x.example.com 300 in a 1.2.3.4 + send + """) + result = nsupdate("", input_text=commands.encode(), raise_on_exception=False) + assert result.rc == 1 + assert "invalid OPCODE in response to SOA query" in result.err diff --git a/bin/tests/system/digdelv/tests_sh_digdelv.py b/bin/tests/system/digdelv/tests_sh_digdelv.py index 2b3a72644b..0b304f3630 100644 --- a/bin/tests/system/digdelv/tests_sh_digdelv.py +++ b/bin/tests/system/digdelv/tests_sh_digdelv.py @@ -15,9 +15,6 @@ pytestmark = pytest.mark.extra_artifacts( [ "delv.out.*", "dig.out.*", - "host.out.*", - "nslookup.out.*", - "nsupdate.out.*", "yamlget.out.*", "ans*/ans.run", "ns*/anchor.*",