From 0344146de514ab1f2643bad5bfce0a92d4dcf1ee Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Sat, 27 Nov 2021 23:13:31 -0500 Subject: Enhance tests of existing/general key cmp/hash behavior Not sure why these were never explicitly tested --- tests/test_pkey.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_pkey.py b/tests/test_pkey.py index caa6d7b3..9b144d22 100644 --- a/tests/test_pkey.py +++ b/tests/test_pkey.py @@ -567,6 +567,28 @@ class KeyTest(unittest.TestCase): ) assert original != generated + def keys(self): + for key_class, filename in [ + (RSAKey, "test_rsa.key"), + (DSSKey, "test_dss.key"), + (ECDSAKey, "test_ecdsa_256.key"), + (Ed25519Key, "test_ed25519.key"), + ]: + key1 = key_class.from_private_key_file(_support(filename)) + key2 = key_class.from_private_key_file(_support(filename)) + yield key1, key2 + + def test_keys_are_comparable(self): + for key1, key2 in self.keys(): + assert key1 == key2 + + def test_keys_are_hashable(self): + # NOTE: this isn't a great test due to hashseed randomization under + # Python 3 preventing use of static values, but it does still prove + # that __hash__ is implemented/doesn't explode & works across instances + for key1, key2 in self.keys(): + assert hash(key1) == hash(key2) + def test_ed25519_nonbytes_password(self): # https://github.com/paramiko/paramiko/issues/1039 Ed25519Key.from_private_key_file( -- cgit v1.2.3