]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44048: Fix two hashlib test cases under FIPS mode (GH-26470) (GH-26531)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 4 Jun 2021 18:38:02 +0000 (11:38 -0700)
committerGitHub <noreply@github.com>
Fri, 4 Jun 2021 18:38:02 +0000 (19:38 +0100)
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 a46c220edc5cf716d0b71eb80ac29ecdb4ebb430)

Co-authored-by: stratakis <cstratak@redhat.com>
Co-authored-by: stratakis <cstratak@redhat.com>
Lib/test/test_hashlib.py

index ad2ed69e24b2c4fc0de5e85935dee6a30aa73102..76754b6b8e13da1480b5783d95991c6a809c2cc9 100644 (file)
@@ -909,7 +909,11 @@ class HashLibTestCase(unittest.TestCase):
                 continue
             # all other types have DISALLOW_INSTANTIATION
             for constructor in constructors:
-                h = constructor()
+                # In FIPS mode some algorithms are not available raising ValueError
+                try:
+                    h = constructor()
+                except ValueError:
+                    continue
                 with self.subTest(constructor=constructor):
                     hash_type = type(h)
                     self.assertRaises(TypeError, hash_type)
@@ -930,7 +934,11 @@ class HashLibTestCase(unittest.TestCase):
         for algorithm, constructors in self.constructors_to_test.items():
             # all other types have DISALLOW_INSTANTIATION
             for constructor in constructors:
-                hash_type = type(constructor())
+                # In FIPS mode some algorithms are not available raising ValueError
+                try:
+                    hash_type = type(constructor())
+                except ValueError:
+                    continue
                 with self.subTest(hash_type=hash_type):
                     with self.assertRaisesRegex(TypeError, "immutable type"):
                         hash_type.value = False