diff options
author | Christopher Papke <chris.papke@imperva.com> | 2022-04-05 14:54:42 -0700 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2022-04-25 08:07:40 -0400 |
commit | f8036d69ff425b81b7070ce91e31252c72bfe632 (patch) | |
tree | 34bba6bc8f7e3e2910786a628567ad663362e66f | |
parent | 094a5e10982c7d7ef9f17fdf755d755fec9fe19b (diff) |
don't throw exception when comparing PKey to non-PKey
-rw-r--r-- | paramiko/pkey.py | 2 | ||||
-rw-r--r-- | tests/test_pkey.py | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/paramiko/pkey.py b/paramiko/pkey.py index 7865a6ea..f494c80e 100644 --- a/paramiko/pkey.py +++ b/paramiko/pkey.py @@ -140,7 +140,7 @@ class PKey(object): return cmp(self.asbytes(), other.asbytes()) # noqa def __eq__(self, other): - return self._fields == other._fields + return isinstance(other, PKey) and self._fields == other._fields def __hash__(self): return hash(self._fields) diff --git a/tests/test_pkey.py b/tests/test_pkey.py index e652740c..687e776b 100644 --- a/tests/test_pkey.py +++ b/tests/test_pkey.py @@ -622,6 +622,11 @@ class KeyTest(unittest.TestCase): for key1, key2 in self.keys(): assert key1 == key2 + def test_keys_are_not_equal_to_other(self): + for value in [None, True, ""]: + for key1, _ in self.keys(): + assert key1 != value + 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 |