]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
fix random failure on synthrecord system test
authorColin Vidal <colin@isc.org>
Fri, 10 Oct 2025 07:35:05 +0000 (09:35 +0200)
committerEvan Hunt <each@isc.org>
Fri, 17 Oct 2025 19:28:04 +0000 (12:28 -0700)
One of the synthrecord system tests uses a test function to generate an
expected name based on some randomly generated IPv6 (using Hypothesis).
Turns out the test function generating the name didn't handle the case
where the label which encodes the IPv6 could have a leading or trailing
'-' character. (The plugin needs to add a leading or trailing 0 so as
not to break IDN compatibility.)

bin/tests/system/synthrecord/tests_synthrecord.py

index 7fd05e8b59fc90973f6af28dd0f9d7f13e355e5a..3af7b3d57a5fc941b6d9fc734e0a21b58ab2d80f 100644 (file)
@@ -24,7 +24,7 @@ from dns.reversename import ipv6_reverse_domain
 import isctest
 from isctest.hypothesis.strategies import dns_names
 
-from hypothesis import assume, given
+from hypothesis import assume, given, example
 from hypothesis.strategies import ip_addresses
 
 SERVER = "10.53.0.1"
@@ -287,9 +287,12 @@ def build_synthetic_name_v4(prefix, ip, domain):
 
 
 def build_synthetic_name_v6(prefix, ip, domain):
-    return dns.name.from_text(
-        "{0}{1}.{2}".format(prefix, format(ip).replace(":", "-"), domain)
-    )
+    ipencoded = format(ip).replace(":", "-")
+    if ipencoded[:1] == "-":
+        ipencoded = f"0{ipencoded}"
+    if ipencoded[-1:] == "-":
+        ipencoded = f"{ipencoded}0"
+    return dns.name.from_text(f"{prefix}{ipencoded}.{domain}")
 
 
 example_domain = dns.name.from_text("example.")
@@ -364,9 +367,13 @@ def test_synthreverse_idn_compat(addr, expected):
     ]
 
 
+# `@example(ip="::")` ensure the IP `::` is always generated. Just to make sure
+# the way we generate a name based on a prefix, IPv6 and domain is correct
+# regarding the expected generated value from the plugin: because of IDN, a
+# label can't have a leading or trailing '-'.
+@example(ip=IPv6Address("::"))
 @given(ip=ip_addresses(network="cafe:cafe::/32"))
 def test_sythreverse_noerror_hasdata_v6(ip):
-    assume(not ip == IPv6Address("cafe:cafe::"))
     query = dns.message.make_query(ip.reverse_pointer, "PTR")
     res = isctest.query.udp(query, SERVER)
     assert res.rcode() == dns.rcode.NOERROR