Skip to content

Commit a46c220

Browse files
authored
bpo-44048: Fix two hashlib test cases under FIPS mode (GH-26470)
test_disallow_instantiation and test_readonly_types try to test all the available digests, however under FIPS mode, while the algorithms are available, trying to use them will fail with a ValueError.
1 parent 6ab65c6 commit a46c220

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Lib/test/test_hashlib.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,11 @@ def test_disallow_instantiation(self):
909909
continue
910910
# all other types have DISALLOW_INSTANTIATION
911911
for constructor in constructors:
912-
h = constructor()
912+
# In FIPS mode some algorithms are not available raising ValueError
913+
try:
914+
h = constructor()
915+
except ValueError:
916+
continue
913917
with self.subTest(constructor=constructor):
914918
support.check_disallow_instantiation(self, type(h))
915919

@@ -923,7 +927,11 @@ def test_readonly_types(self):
923927
for algorithm, constructors in self.constructors_to_test.items():
924928
# all other types have DISALLOW_INSTANTIATION
925929
for constructor in constructors:
926-
hash_type = type(constructor())
930+
# In FIPS mode some algorithms are not available raising ValueError
931+
try:
932+
hash_type = type(constructor())
933+
except ValueError:
934+
continue
927935
with self.subTest(hash_type=hash_type):
928936
with self.assertRaisesRegex(TypeError, "immutable type"):
929937
hash_type.value = False

0 commit comments

Comments
 (0)