Skip to content

Commit 3f4d801

Browse files
bpo-44048: Fix two hashlib test cases under FIPS mode (GH-26470) (GH-26531)
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. (cherry picked from commit a46c220) Co-authored-by: stratakis <[email protected]> Co-authored-by: stratakis <[email protected]>
1 parent e53f72a commit 3f4d801

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
hash_type = type(h)
915919
self.assertRaises(TypeError, hash_type)
@@ -930,7 +934,11 @@ def test_readonly_types(self):
930934
for algorithm, constructors in self.constructors_to_test.items():
931935
# all other types have DISALLOW_INSTANTIATION
932936
for constructor in constructors:
933-
hash_type = type(constructor())
937+
# In FIPS mode some algorithms are not available raising ValueError
938+
try:
939+
hash_type = type(constructor())
940+
except ValueError:
941+
continue
934942
with self.subTest(hash_type=hash_type):
935943
with self.assertRaisesRegex(TypeError, "immutable type"):
936944
hash_type.value = False

0 commit comments

Comments
 (0)