From 3aac716a46f3bac7b1742850bf07256b086daf8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Bal=C3=A1=C5=BEik?= Date: Thu, 21 Dec 2023 20:25:20 +0100 Subject: [PATCH] Extend isctest package with more utility functions 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 | 1 + bin/tests/system/isctest/check.py | 24 ++++++++++++++++++++++++ bin/tests/system/isctest/name.py | 16 ++++++++++++++++ bin/tests/system/isctest/query.py | 6 ++++-- 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 bin/tests/system/isctest/name.py diff --git a/bin/tests/system/isctest/__init__.py b/bin/tests/system/isctest/__init__.py index e0014adbba..de5205e82f 100644 --- a/bin/tests/system/isctest/__init__.py +++ b/bin/tests/system/isctest/__init__.py @@ -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 diff --git a/bin/tests/system/isctest/check.py b/bin/tests/system/isctest/check.py index e6fe020df3..28eb16d5dd 100644 --- a/bin/tests/system/isctest/check.py +++ b/bin/tests/system/isctest/check.py @@ -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 index 0000000000..f5b6de52c3 --- /dev/null +++ b/bin/tests/system/isctest/name.py @@ -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) diff --git a/bin/tests/system/isctest/query.py b/bin/tests/system/isctest/query.py index 329558d272..46fd9b85f9 100644 --- a/bin/tests/system/isctest/query.py +++ b/bin/tests/system/isctest/query.py @@ -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)