]> 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>
Tue, 28 May 2024 12:12:16 +0000 (12:12 +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`.

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 73ac41301325f56474221eefaf72758c97cc9208..afeb55bf79172ea947be584f3a7b6bb99b8ced9f 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 2ef37ed05ed9b0fb5cc669d4dc674bfd0e73edc2..28eb16d5dd42af1c00eedd58c71dca99b159255b 100644 (file)
@@ -101,3 +101,21 @@ def zones_equal(
 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)