]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Extend isctest package with more utility functions
authorŠtěpán Balážik <stepan@isc.org>
Thu, 21 Dec 2023 19:25:20 +0000 (20:25 +0100)
committerPetr Špaček <pspacek@isc.org>
Fri, 2 Aug 2024 11:22:56 +0000 (11:22 +0000)
Check for more rcodes and various properties needed in the wildcard
test. Add a `name` module for various dns.name.Name operations (with
`prepend_label` function only now).

Expose `timeout` as a parameter of `query.tcp`/`query.udp`.

(cherry picked from commit e7d46ad8ba17725a934ec84512644f837513b8d3)

bin/tests/system/isctest/__init__.py
bin/tests/system/isctest/check.py
bin/tests/system/isctest/name.py [new file with mode: 0644]
bin/tests/system/isctest/query.py

index e0014adbba6eb817245da505a89a8a01e802dbb6..de5205e82fec14aef4bc66cdc28c5c3d359308e6 100644 (file)
@@ -12,6 +12,7 @@
 from . import check
 from . import instance
 from . import query
+from . import name
 from . import rndc
 from . import run
 from . import log
index e6fe020df370ffa9e5432b3bf65a51df56a4165f..28eb16d5dd42af1c00eedd58c71dca99b159255b 100644 (file)
@@ -9,6 +9,7 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
+import shutil
 from typing import Any, Optional
 
 import dns.rcode
@@ -95,3 +96,26 @@ def zones_equal(
                 )
                 assert found_rdataset
                 assert found_rdataset.ttl == rdataset.ttl
+
+
+def is_executable(cmd: str, errmsg: str) -> None:
+    executable = shutil.which(cmd)
+    assert executable is not None, errmsg
+
+
+def nxdomain(message: dns.message.Message) -> None:
+    rcode(message, dns.rcode.NXDOMAIN)
+
+
+def single_question(message: dns.message.Message) -> None:
+    assert len(message.question) == 1, str(message)
+
+
+def empty_answer(message: dns.message.Message) -> None:
+    assert not message.answer, str(message)
+
+
+def is_response_to(response: dns.message.Message, query: dns.message.Message) -> None:
+    single_question(response)
+    single_question(query)
+    assert query.is_response(response), str(response)
diff --git a/bin/tests/system/isctest/name.py b/bin/tests/system/isctest/name.py
new file mode 100644 (file)
index 0000000..f5b6de5
--- /dev/null
@@ -0,0 +1,16 @@
+# 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.name
+
+
+def prepend_label(label: str, name: dns.name.Name) -> dns.name.Name:
+    return dns.name.Name((label,) + name.labels)
index 329558d272775ea2b815a918a4c418e1b9cf6b13..46fd9b85f921a7edce933947fcab8f2ed249474e 100644 (file)
@@ -24,10 +24,11 @@ def udp(
     ip: str,
     port: Optional[int] = None,
     source: Optional[str] = None,
+    timeout: int = QUERY_TIMEOUT,
 ) -> dns.message.Message:
     if port is None:
         port = int(os.environ["PORT"])
-    return dns.query.udp(message, ip, QUERY_TIMEOUT, port=port, source=source)
+    return dns.query.udp(message, ip, timeout, port=port, source=source)
 
 
 def tcp(
@@ -35,7 +36,8 @@ def tcp(
     ip: str,
     port: Optional[int] = None,
     source: Optional[str] = None,
+    timeout: int = QUERY_TIMEOUT,
 ) -> dns.message.Message:
     if port is None:
         port = int(os.environ["PORT"])
-    return dns.query.tcp(message, ip, QUERY_TIMEOUT, port=port, source=source)
+    return dns.query.tcp(message, ip, timeout, port=port, source=source)