Issue #18582: skip test of _hashlib.pbkdf2_hmac if OpenSSL is not available or too old

This commit is contained in:
Christian Heimes 2013-10-19 19:40:49 +02:00
parent 55e092f545
commit 0fbd94ced9
1 changed files with 8 additions and 11 deletions

View File

@ -548,8 +548,7 @@ class HashLibTestCase(unittest.TestCase):
self.assertEqual(expected_hash, hasher.hexdigest()) self.assertEqual(expected_hash, hasher.hexdigest())
class KDFTests: class KDFTests(unittest.TestCase):
hashlibmod = None
pbkdf2_test_vectors = [ pbkdf2_test_vectors = [
(b'password', b'salt', 1, None), (b'password', b'salt', 1, None),
@ -600,9 +599,7 @@ class KDFTests:
(bytes.fromhex('9d9e9c4cd21fe4be24d5b8244c759665'), None),], (bytes.fromhex('9d9e9c4cd21fe4be24d5b8244c759665'), None),],
} }
def test_pbkdf2_hmac(self): def _test_pbkdf2_hmac(self, pbkdf2):
pbkdf2 = self.hashlibmod.pbkdf2_hmac
for digest_name, results in self.pbkdf2_results.items(): for digest_name, results in self.pbkdf2_results.items():
for i, vector in enumerate(self.pbkdf2_test_vectors): for i, vector in enumerate(self.pbkdf2_test_vectors):
password, salt, rounds, dklen = vector password, salt, rounds, dklen = vector
@ -631,13 +628,13 @@ class KDFTests:
with self.assertRaisesRegex(ValueError, 'unsupported hash type'): with self.assertRaisesRegex(ValueError, 'unsupported hash type'):
pbkdf2('unknown', b'pass', b'salt', 1) pbkdf2('unknown', b'pass', b'salt', 1)
def test_pbkdf2_hmac_py(self):
self._test_pbkdf2_hmac(py_hashlib.pbkdf2_hmac)
class PyKDFTests(KDFTests, unittest.TestCase): @unittest.skipUnless(hasattr(c_hashlib, 'pbkdf2_hmac'),
hashlibmod = py_hashlib ' test requires OpenSSL > 1.0')
def test_pbkdf2_hmac_c(self):
self._test_pbkdf2_hmac(c_hashlib.pbkdf2_hmac)
class CKDFTests(KDFTests, unittest.TestCase):
hashlibmod = c_hashlib
if __name__ == "__main__": if __name__ == "__main__":