summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2021-11-28 14:56:29 -0500
committerJeff Forcier <jeff@bitprophet.org>2021-11-28 20:24:17 -0500
commit9c49dc721e25992c824035088d5a054715bd0d87 (patch)
treeea9b6915941f3511fa61eeab4332da8d02d9584d
parentbdb5d9a766e30b04c0df0eea8e7b313813ce6e1d (diff)
downloadparamiko-9c49dc721e25992c824035088d5a054715bd0d87.tar.gz
Tests proving #1257
-rw-r--r--tests/test_pkey.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/test_pkey.py b/tests/test_pkey.py
index 9b144d22..94b2492b 100644
--- a/tests/test_pkey.py
+++ b/tests/test_pkey.py
@@ -26,9 +26,18 @@ import os
from binascii import hexlify
from hashlib import md5
-from paramiko import RSAKey, DSSKey, ECDSAKey, Ed25519Key, Message, util
+from paramiko import (
+ RSAKey,
+ DSSKey,
+ ECDSAKey,
+ Ed25519Key,
+ Message,
+ util,
+ SSHException,
+)
from paramiko.py3compat import StringIO, byte_chr, b, bytes, PY2
+from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateNumbers
from mock import patch
import pytest
@@ -163,6 +172,16 @@ class KeyTest(unittest.TestCase):
key2 = RSAKey.from_private_key(s)
self.assertEqual(key, key2)
+ def test_load_rsa_transmutes_crypto_exceptions(self):
+ # TODO: nix unittest for pytest
+ for exception in (TypeError("onoz"), UnsupportedAlgorithm("oops")):
+ with patch(
+ "paramiko.rsakey.serialization.load_der_private_key"
+ ) as loader:
+ loader.side_effect = exception
+ with pytest.raises(SSHException, match=str(exception)):
+ RSAKey.from_private_key_file(_support("test_rsa.key"))
+
def test_load_rsa_password(self):
key = RSAKey.from_private_key_file(
_support("test_rsa_password.key"), "television"
@@ -369,6 +388,17 @@ class KeyTest(unittest.TestCase):
self.assertEqual(PUB_ECDSA_384.split()[1], key.get_base64())
self.assertEqual(384, key.get_bits())
+ def test_load_ecdsa_transmutes_crypto_exceptions(self):
+ path = _support("test_ecdsa_256.key")
+ # TODO: nix unittest for pytest
+ for exception in (TypeError("onoz"), UnsupportedAlgorithm("oops")):
+ with patch(
+ "paramiko.ecdsakey.serialization.load_der_private_key"
+ ) as loader:
+ loader.side_effect = exception
+ with pytest.raises(SSHException, match=str(exception)):
+ ECDSAKey.from_private_key_file(path)
+
def test_compare_ecdsa_384(self):
# verify that the private & public keys compare equal
key = ECDSAKey.from_private_key_file(_support("test_ecdsa_384.key"))