]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Move multi-subdomain name generator into shared utilities
authorPetr Špaček <pspacek@isc.org>
Wed, 21 May 2025 12:55:45 +0000 (14:55 +0200)
committerPetr Špaček <pspacek@isc.org>
Tue, 29 Jul 2025 08:00:36 +0000 (10:00 +0200)
bin/tests/system/dnssec/tests_nsec3.py
bin/tests/system/isctest/hypothesis/strategies.py

index 1a7dbe71eed5023dfa024eedb2a980e0f84512a8..83e63a7059ed0b7c4319874308f2f608959ae3d5 100755 (executable)
@@ -161,17 +161,10 @@ def test_dnssec_nsec3_nxdomain(server, name: dns.name.Name, named_port: int) ->
     noqname_test(server, name, named_port)
 
 
-@strategies.composite
-def generate_subdomain_of_existing_name(draw):
-    existing = draw(strategies.sampled_from(sorted(KNOWN_NAMES)))
-    subdomain = draw(isctest.hypothesis.strategies.dns_names(suffix=existing))
-    return subdomain
-
-
 @pytest.mark.parametrize(
     "server", [pytest.param(AUTH, id="ns3"), pytest.param(RESOLVER, id="ns4")]
 )
-@given(name=generate_subdomain_of_existing_name())
+@given(name=dns_names(suffix=KNOWN_NAMES))
 def test_dnssec_nsec3_subdomain_nxdomain(
     server, name: dns.name.Name, named_port: int
 ) -> None:
index 08284963600140a4f95c7416dd19b2a59bac29c5..a3f9eac2b27c47f91ed92a5c72d94430f443a03f 100644 (file)
@@ -11,7 +11,8 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-from typing import List
+import collections.abc
+from typing import List, Union
 from warnings import warn
 
 from hypothesis.strategies import (
@@ -22,6 +23,7 @@ from hypothesis.strategies import (
     just,
     nothing,
     permutations,
+    sampled_from,
 )
 
 import dns.name
@@ -37,7 +39,9 @@ def dns_names(
     draw,
     *,
     prefix: dns.name.Name = dns.name.empty,
-    suffix: dns.name.Name = dns.name.root,
+    suffix: Union[
+        dns.name.Name, collections.abc.Iterable[dns.name.Name]
+    ] = dns.name.root,
     min_labels: int = 1,
     max_labels: int = 128,
 ) -> dns.name.Name:
@@ -71,6 +75,14 @@ def dns_names(
     """
 
     prefix = prefix.relativize(dns.name.root)
+    # Python str is iterable, but that's most probably not what user actually wanted
+    if isinstance(suffix, str):
+        raise NotImplementedError(
+            "ambiguous API use, convert suffix to Name or list to express intent"
+        )
+    if isinstance(suffix, collections.abc.Iterable):
+        suffix = draw(sampled_from(sorted(suffix)))
+    assert isinstance(suffix, dns.name.Name)
     suffix = suffix.derelativize(dns.name.root)
 
     try: