--- /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.
+
+"""
+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",
+]
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)"
--- /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.
+
+"""
+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