bpo-40637: Fix test_pbkdf2_hmac_py for missing sha1 (#20422)

This commit is contained in:
Christian Heimes 2020-05-26 12:26:29 +02:00 committed by GitHub
parent af7553ac95
commit be63019ed7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 9 deletions

View File

@ -1004,14 +1004,28 @@ 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)
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])