]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Ensure supported version of hypothesis is available
authorNicki Křížek <nicki@isc.org>
Mon, 5 May 2025 16:00:07 +0000 (18:00 +0200)
committerNicki Křížek <nicki@isc.org>
Thu, 29 May 2025 08:29:13 +0000 (10:29 +0200)
On FIPS-enabled platforms, we need to ensure a minimal version of
hypothesis which no longer uses MD5. This doesn't need to be enforced
for other platforms.

Move the import magic to a utility module to avoid copy-pasting the
boilerplate code around.

bin/tests/system/isctest/__init__.py
bin/tests/system/isctest/hypothesis/__init__.py
bin/tests/system/tsig/tests_tsig_hypothesis.py
bin/tests/system/wildcard/tests_wildcard.py

index b2fb77d001778b06f6f0041d2e76a51b6e46344c..c3e65d8866a75a9311f995e6011e729d7df5a564 100644 (file)
@@ -19,7 +19,10 @@ from . import run
 from . import template
 from . import log
 from . import vars  # pylint: disable=redefined-builtin
-from . import hypothesis
+
+# isctest.hypothesis is intentionally NOT imported, because it detects proper
+# hypothesis support and instructs pytest to skip the tests otherwise. It
+# should be manually imported only in the modules that require hypothesis.
 
 # isctest.mark module is intentionally NOT imported, because it relies on
 # environment variables which might not be set at the time of import of the
index 3ae0deeb24d3de1b79a59a87fa30bea719bc8f20..4cedd8866af7aa65a75504d061000511bc1f18db 100644 (file)
@@ -9,10 +9,20 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-try:
-    import hypothesis as _
-except ImportError:
-    pass
-else:
-    from . import settings
-    from . import strategies
+# This ensures we're using a suitable hypothesis version. A newer version is
+# required for FIPS-enabled platforms.
+
+import hashlib
+
+import pytest
+
+MIN_HYPOTHESIS_VERSION = None
+
+if "md5" not in hashlib.algorithms_available:
+    # FIPS mode is enabled, use hypothesis 4.41.2 which doesn't use md5
+    MIN_HYPOTHESIS_VERSION = "4.41.2"
+
+pytest.importorskip("hypothesis", minversion=MIN_HYPOTHESIS_VERSION)
+
+from . import settings
+from . import strategies
index a0e18d59c827d7cc312570fb63aa9a61a773c354..39dcc8914f9aa830dc2a9e3e59ba7696fc680136 100644 (file)
@@ -17,15 +17,6 @@ import pytest
 
 pytest.importorskip("dns", minversion="2.7.0")  # TSIG parsing without validation
 
-# in FIPs mode md5 fails so we need 4.41.2 or later which does not use md5
-try:
-    import hashlib
-
-    hashlib.md5(b"1234")
-    pytest.importorskip("hypothesis")
-except ValueError:
-    pytest.importorskip("hypothesis", minversion="4.41.2")
-
 import dns.exception
 import dns.message
 import dns.name
@@ -35,12 +26,12 @@ import dns.rdtypes.ANY.TSIG
 import dns.rrset
 import dns.tsig
 
-from hypothesis import assume, example, given
-from hypothesis.strategies import binary, booleans, composite, just, sampled_from
-
 import isctest
 from isctest.hypothesis.strategies import dns_names, uint
 
+from hypothesis import assume, example, given
+from hypothesis.strategies import binary, booleans, composite, just, sampled_from
+
 
 pytestmark = pytest.mark.extra_artifacts(
     [
index 37a4d15b2d83769f847ba06faec0e986544fff46..cad2eb075787c0f61c92d0fd413bda96f6518a2e 100755 (executable)
@@ -38,17 +38,9 @@ import dns.rdataclass
 import dns.rdatatype
 import dns.rrset
 
-# in FIPs mode md5 fails so we need 4.41.2 or later which does not use md5
-try:
-    import hashlib
-
-    hashlib.md5(b"1234")
-    pytest.importorskip("hypothesis")
-except ValueError:
-    pytest.importorskip("hypothesis", minversion="4.41.2")
+from isctest.hypothesis.strategies import dns_names, dns_rdatatypes_without_meta
 from hypothesis import assume, example, given, settings
 
-from isctest.hypothesis.strategies import dns_names, dns_rdatatypes_without_meta
 import isctest.check
 import isctest.name
 import isctest.query