summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2021-11-27 23:13:31 -0500
committerJeff Forcier <jeff@bitprophet.org>2021-11-28 20:24:17 -0500
commit0344146de514ab1f2643bad5bfce0a92d4dcf1ee (patch)
tree408f18d641da41cebf777a9f0a9014e8f9f3ce62
parentaca7613171937334c47377faf0cf2e4a9126c0d4 (diff)
downloadparamiko-0344146de514ab1f2643bad5bfce0a92d4dcf1ee.tar.gz
Enhance tests of existing/general key cmp/hash behavior
Not sure why these were never explicitly tested
-rw-r--r--tests/test_pkey.py22
1 files changed, 22 insertions, 0 deletions
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(