From be63019ed726b2da045bf232782062830bb6c27d Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 26 May 2020 12:26:29 +0200 Subject: [PATCH] bpo-40637: Fix test_pbkdf2_hmac_py for missing sha1 (#20422) --- Lib/test/test_hashlib.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index d40acd58899..6088307f841 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -1004,17 +1004,31 @@ class KDFTests(unittest.TestCase): self.assertEqual(out, expected, (digest_name, password, salt, rounds)) - self.assertRaises(TypeError, pbkdf2, b'sha1', b'pass', b'salt', 1) - self.assertRaises(TypeError, pbkdf2, 'sha1', 'pass', 'salt', 1) - self.assertRaises(ValueError, pbkdf2, 'sha1', b'pass', b'salt', 0) - self.assertRaises(ValueError, pbkdf2, 'sha1', b'pass', b'salt', -1) - self.assertRaises(ValueError, pbkdf2, 'sha1', b'pass', b'salt', 1, 0) - self.assertRaises(ValueError, pbkdf2, 'sha1', b'pass', b'salt', 1, -1) with self.assertRaisesRegex(ValueError, 'unsupported hash type'): pbkdf2('unknown', b'pass', b'salt', 1) - out = pbkdf2(hash_name='sha1', password=b'password', salt=b'salt', - iterations=1, dklen=None) - self.assertEqual(out, self.pbkdf2_results['sha1'][0][0]) + + if 'sha1' in supported: + self.assertRaises( + TypeError, pbkdf2, b'sha1', b'pass', b'salt', 1 + ) + self.assertRaises( + TypeError, pbkdf2, 'sha1', 'pass', 'salt', 1 + ) + self.assertRaises( + ValueError, pbkdf2, 'sha1', b'pass', b'salt', 0 + ) + self.assertRaises( + ValueError, pbkdf2, 'sha1', b'pass', b'salt', -1 + ) + self.assertRaises( + ValueError, pbkdf2, 'sha1', b'pass', b'salt', 1, 0 + ) + self.assertRaises( + ValueError, pbkdf2, 'sha1', b'pass', b'salt', 1, -1 + ) + out = pbkdf2(hash_name='sha1', password=b'password', salt=b'salt', + iterations=1, dklen=None) + self.assertEqual(out, self.pbkdf2_results['sha1'][0][0]) def test_pbkdf2_hmac_py(self): self._test_pbkdf2_hmac(py_hashlib.pbkdf2_hmac, builtin_hashes)