]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Migrate digdelv nslookup/host/nsupdate checks to pytest
authorMartin Basti <mbasti@isc.org>
Wed, 22 Jul 2026 12:27:36 +0000 (12:27 +0000)
committerMartin Basti <mbasti@isc.org>
Wed, 29 Jul 2026 11:51:04 +0000 (13:51 +0200)
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
bin/tests/system/digdelv/common.py [new file with mode: 0644]
bin/tests/system/digdelv/tests.sh
bin/tests/system/digdelv/tests_others.py [new file with mode: 0644]
bin/tests/system/digdelv/tests_sh_digdelv.py

diff --git a/bin/tests/system/digdelv/common.py b/bin/tests/system/digdelv/common.py
new file mode 100644 (file)
index 0000000..dc1bb20
--- /dev/null
@@ -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",
+]
index 17587f7ab90f772ab424b383f9f9a7e846c5a648..1d3c0c8514567fa7633abcaf3df575b6e72ff48e 100644 (file)
@@ -73,36 +73,6 @@ NOSPLIT="$(sed <ns2/keydata -e 's/+/[+]/g' -e 's/ //g')"
 HAS_PYYAML=0
 $PYTHON -c "import yaml" 2>/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 <<EOF >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 (file)
index 0000000..3b097c6
--- /dev/null
@@ -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
index 2b3a72644b7509bfb78baf800bd5df9c7b777c88..0b304f36309e0b2ec829071ef232a27c6dbcf213 100644 (file)
@@ -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.*",