From 2b4825dbad33618b165925209325c3d03a493a69 Mon Sep 17 00:00:00 2001 From: Colin Vidal Date: Fri, 10 Oct 2025 09:35:05 +0200 Subject: [PATCH] fix random failure on synthrecord system test 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.) --- .../system/synthrecord/tests_synthrecord.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/tests/system/synthrecord/tests_synthrecord.py b/bin/tests/system/synthrecord/tests_synthrecord.py index 7fd05e8b59..3af7b3d57a 100644 --- a/bin/tests/system/synthrecord/tests_synthrecord.py +++ b/bin/tests/system/synthrecord/tests_synthrecord.py @@ -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