Skip to content

Commit ffece55

Browse files
authored
pythongh-128192: mark new tests with skips based on hashlib algorithm availability (pythongh-128324)
Puts the _hashlib get_fips_mode logic check into test.support rather than spreading it out among other tests.
1 parent c9159b7 commit ffece55

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Lib/test/support/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,3 +2969,11 @@ def run_yielding_async_fn(async_fn, /, *args, **kwargs):
29692969
return e.value
29702970
finally:
29712971
coro.close()
2972+
2973+
2974+
def is_libssl_fips_mode():
2975+
try:
2976+
from _hashlib import get_fips_mode # ask _hashopenssl.c
2977+
except ImportError:
2978+
return False # more of a maybe, unless we add this to the _ssl module.
2979+
return get_fips_mode() != 0

Lib/test/test_urllib2.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import urllib.error
2828
import http.client
2929

30+
3031
support.requires_working_socket(module=True)
3132

3233
# XXX
@@ -1963,20 +1964,29 @@ def test_parse_proxy(self):
19631964
self.assertRaises(ValueError, _parse_proxy, 'file:/ftp.example.com'),
19641965

19651966

1966-
class TestDigestAlgorithms(unittest.TestCase):
1967+
skip_libssl_fips_mode = unittest.skipIf(
1968+
support.is_libssl_fips_mode(),
1969+
"conservative skip due to OpenSSL FIPS mode possible algorithm nerfing",
1970+
)
1971+
1972+
1973+
class TestDigestAuthAlgorithms(unittest.TestCase):
19671974
def setUp(self):
19681975
self.handler = AbstractDigestAuthHandler()
19691976

1977+
@skip_libssl_fips_mode
19701978
def test_md5_algorithm(self):
19711979
H, KD = self.handler.get_algorithm_impls('MD5')
19721980
self.assertEqual(H("foo"), "acbd18db4cc2f85cedef654fccc4a4d8")
19731981
self.assertEqual(KD("foo", "bar"), "4e99e8c12de7e01535248d2bac85e732")
19741982

1983+
@skip_libssl_fips_mode
19751984
def test_sha_algorithm(self):
19761985
H, KD = self.handler.get_algorithm_impls('SHA')
19771986
self.assertEqual(H("foo"), "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
19781987
self.assertEqual(KD("foo", "bar"), "54dcbe67d21d5eb39493d46d89ae1f412d3bd6de")
19791988

1989+
@skip_libssl_fips_mode
19801990
def test_sha256_algorithm(self):
19811991
H, KD = self.handler.get_algorithm_impls('SHA-256')
19821992
self.assertEqual(H("foo"), "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae")

0 commit comments

Comments
 (0)