summaryrefslogtreecommitdiffhomepage
path: root/tests/test_pkey.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_pkey.py')
-rw-r--r--tests/test_pkey.py67
1 files changed, 34 insertions, 33 deletions
diff --git a/tests/test_pkey.py b/tests/test_pkey.py
index 42d8e6bb..1827d2a9 100644
--- a/tests/test_pkey.py
+++ b/tests/test_pkey.py
@@ -30,7 +30,8 @@ import base64
from paramiko import RSAKey, DSSKey, ECDSAKey, Ed25519Key, Message, util
from paramiko.py3compat import StringIO, byte_chr, b, bytes, PY2
-from tests.util import test_path
+from .util import _support
+
# from openssh's ssh-keygen
PUB_RSA = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA049W6geFpmsljTwfvI1UmKWWJPNFI74+vNKTk4dmzkQY2yAMs6FhlvhlI8ysU4oj71ZsRYMecHbBbxdN79+JRFVYTKaLqjwGENeTd+yv4q+V2PvZv3fLnzApI3l7EJCqhWwJUHJ1jAkZzqDx0tyOL4uoZpww3nmE0kb3y21tH4c='
@@ -138,7 +139,7 @@ class KeyTest(unittest.TestCase):
self.assertEqual(exp, key)
def test_2_load_rsa(self):
- key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
+ key = RSAKey.from_private_key_file(_support('test_rsa.key'))
self.assertEqual('ssh-rsa', key.get_name())
exp_rsa = b(FINGER_RSA.split()[1].replace(':', ''))
my_rsa = hexlify(key.get_fingerprint())
@@ -154,7 +155,7 @@ class KeyTest(unittest.TestCase):
self.assertEqual(key, key2)
def test_3_load_rsa_password(self):
- key = RSAKey.from_private_key_file(test_path('test_rsa_password.key'), 'television')
+ key = RSAKey.from_private_key_file(_support('test_rsa_password.key'), 'television')
self.assertEqual('ssh-rsa', key.get_name())
exp_rsa = b(FINGER_RSA.split()[1].replace(':', ''))
my_rsa = hexlify(key.get_fingerprint())
@@ -163,7 +164,7 @@ class KeyTest(unittest.TestCase):
self.assertEqual(1024, key.get_bits())
def test_4_load_dss(self):
- key = DSSKey.from_private_key_file(test_path('test_dss.key'))
+ key = DSSKey.from_private_key_file(_support('test_dss.key'))
self.assertEqual('ssh-dss', key.get_name())
exp_dss = b(FINGER_DSS.split()[1].replace(':', ''))
my_dss = hexlify(key.get_fingerprint())
@@ -179,7 +180,7 @@ class KeyTest(unittest.TestCase):
self.assertEqual(key, key2)
def test_5_load_dss_password(self):
- key = DSSKey.from_private_key_file(test_path('test_dss_password.key'), 'television')
+ key = DSSKey.from_private_key_file(_support('test_dss_password.key'), 'television')
self.assertEqual('ssh-dss', key.get_name())
exp_dss = b(FINGER_DSS.split()[1].replace(':', ''))
my_dss = hexlify(key.get_fingerprint())
@@ -189,7 +190,7 @@ class KeyTest(unittest.TestCase):
def test_6_compare_rsa(self):
# verify that the private & public keys compare equal
- key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
+ key = RSAKey.from_private_key_file(_support('test_rsa.key'))
self.assertEqual(key, key)
pub = RSAKey(data=key.asbytes())
self.assertTrue(key.can_sign())
@@ -198,7 +199,7 @@ class KeyTest(unittest.TestCase):
def test_7_compare_dss(self):
# verify that the private & public keys compare equal
- key = DSSKey.from_private_key_file(test_path('test_dss.key'))
+ key = DSSKey.from_private_key_file(_support('test_dss.key'))
self.assertEqual(key, key)
pub = DSSKey(data=key.asbytes())
self.assertTrue(key.can_sign())
@@ -207,7 +208,7 @@ class KeyTest(unittest.TestCase):
def test_8_sign_rsa(self):
# verify that the rsa private key can sign and verify
- key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
+ key = RSAKey.from_private_key_file(_support('test_rsa.key'))
msg = key.sign_ssh_data(b'ice weasels')
self.assertTrue(type(msg) is Message)
msg.rewind()
@@ -220,7 +221,7 @@ class KeyTest(unittest.TestCase):
def test_9_sign_dss(self):
# verify that the dss private key can sign and verify
- key = DSSKey.from_private_key_file(test_path('test_dss.key'))
+ key = DSSKey.from_private_key_file(_support('test_dss.key'))
msg = key.sign_ssh_data(b'ice weasels')
self.assertTrue(type(msg) is Message)
msg.rewind()
@@ -275,7 +276,7 @@ class KeyTest(unittest.TestCase):
self.assertEqual(key.get_name(), 'ecdsa-sha2-nistp521')
def test_10_load_ecdsa_256(self):
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_256.key'))
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_256.key'))
self.assertEqual('ecdsa-sha2-nistp256', key.get_name())
exp_ecdsa = b(FINGER_ECDSA_256.split()[1].replace(':', ''))
my_ecdsa = hexlify(key.get_fingerprint())
@@ -291,7 +292,7 @@ class KeyTest(unittest.TestCase):
self.assertEqual(key, key2)
def test_11_load_ecdsa_password_256(self):
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_password_256.key'), b'television')
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_password_256.key'), b'television')
self.assertEqual('ecdsa-sha2-nistp256', key.get_name())
exp_ecdsa = b(FINGER_ECDSA_256.split()[1].replace(':', ''))
my_ecdsa = hexlify(key.get_fingerprint())
@@ -301,7 +302,7 @@ class KeyTest(unittest.TestCase):
def test_12_compare_ecdsa_256(self):
# verify that the private & public keys compare equal
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_256.key'))
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_256.key'))
self.assertEqual(key, key)
pub = ECDSAKey(data=key.asbytes())
self.assertTrue(key.can_sign())
@@ -310,7 +311,7 @@ class KeyTest(unittest.TestCase):
def test_13_sign_ecdsa_256(self):
# verify that the rsa private key can sign and verify
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_256.key'))
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_256.key'))
msg = key.sign_ssh_data(b'ice weasels')
self.assertTrue(type(msg) is Message)
msg.rewind()
@@ -325,7 +326,7 @@ class KeyTest(unittest.TestCase):
self.assertTrue(pub.verify_ssh_sig(b'ice weasels', msg))
def test_14_load_ecdsa_384(self):
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_384.key'))
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_384.key'))
self.assertEqual('ecdsa-sha2-nistp384', key.get_name())
exp_ecdsa = b(FINGER_ECDSA_384.split()[1].replace(':', ''))
my_ecdsa = hexlify(key.get_fingerprint())
@@ -341,7 +342,7 @@ class KeyTest(unittest.TestCase):
self.assertEqual(key, key2)
def test_15_load_ecdsa_password_384(self):
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_password_384.key'), b'television')
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_password_384.key'), b'television')
self.assertEqual('ecdsa-sha2-nistp384', key.get_name())
exp_ecdsa = b(FINGER_ECDSA_384.split()[1].replace(':', ''))
my_ecdsa = hexlify(key.get_fingerprint())
@@ -351,7 +352,7 @@ class KeyTest(unittest.TestCase):
def test_16_compare_ecdsa_384(self):
# verify that the private & public keys compare equal
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_384.key'))
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_384.key'))
self.assertEqual(key, key)
pub = ECDSAKey(data=key.asbytes())
self.assertTrue(key.can_sign())
@@ -360,7 +361,7 @@ class KeyTest(unittest.TestCase):
def test_17_sign_ecdsa_384(self):
# verify that the rsa private key can sign and verify
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_384.key'))
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_384.key'))
msg = key.sign_ssh_data(b'ice weasels')
self.assertTrue(type(msg) is Message)
msg.rewind()
@@ -375,7 +376,7 @@ class KeyTest(unittest.TestCase):
self.assertTrue(pub.verify_ssh_sig(b'ice weasels', msg))
def test_18_load_ecdsa_521(self):
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_521.key'))
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_521.key'))
self.assertEqual('ecdsa-sha2-nistp521', key.get_name())
exp_ecdsa = b(FINGER_ECDSA_521.split()[1].replace(':', ''))
my_ecdsa = hexlify(key.get_fingerprint())
@@ -394,7 +395,7 @@ class KeyTest(unittest.TestCase):
self.assertEqual(key, key2)
def test_19_load_ecdsa_password_521(self):
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_password_521.key'), b'television')
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_password_521.key'), b'television')
self.assertEqual('ecdsa-sha2-nistp521', key.get_name())
exp_ecdsa = b(FINGER_ECDSA_521.split()[1].replace(':', ''))
my_ecdsa = hexlify(key.get_fingerprint())
@@ -404,7 +405,7 @@ class KeyTest(unittest.TestCase):
def test_20_compare_ecdsa_521(self):
# verify that the private & public keys compare equal
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_521.key'))
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_521.key'))
self.assertEqual(key, key)
pub = ECDSAKey(data=key.asbytes())
self.assertTrue(key.can_sign())
@@ -413,7 +414,7 @@ class KeyTest(unittest.TestCase):
def test_21_sign_ecdsa_521(self):
# verify that the rsa private key can sign and verify
- key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_521.key'))
+ key = ECDSAKey.from_private_key_file(_support('test_ecdsa_521.key'))
msg = key.sign_ssh_data(b'ice weasels')
self.assertTrue(type(msg) is Message)
msg.rewind()
@@ -429,7 +430,7 @@ class KeyTest(unittest.TestCase):
def test_salt_size(self):
# Read an existing encrypted private key
- file_ = test_path('test_rsa_password.key')
+ file_ = _support('test_rsa_password.key')
password = 'television'
newfile = file_ + '.new'
newpassword = 'radio'
@@ -446,20 +447,20 @@ class KeyTest(unittest.TestCase):
os.remove(newfile)
def test_stringification(self):
- key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
+ key = RSAKey.from_private_key_file(_support('test_rsa.key'))
comparable = TEST_KEY_BYTESTR_2 if PY2 else TEST_KEY_BYTESTR_3
self.assertEqual(str(key), comparable)
def test_ed25519(self):
- key1 = Ed25519Key.from_private_key_file(test_path('test_ed25519.key'))
+ key1 = Ed25519Key.from_private_key_file(_support('test_ed25519.key'))
key2 = Ed25519Key.from_private_key_file(
- test_path('test_ed25519_password.key'), b'abc123'
+ _support('test_ed25519_password.key'), b'abc123'
)
self.assertNotEqual(key1.asbytes(), key2.asbytes())
def test_ed25519_compare(self):
# verify that the private & public keys compare equal
- key = Ed25519Key.from_private_key_file(test_path('test_ed25519.key'))
+ key = Ed25519Key.from_private_key_file(_support('test_ed25519.key'))
self.assertEqual(key, key)
pub = Ed25519Key(data=key.asbytes())
self.assertTrue(key.can_sign())
@@ -469,7 +470,7 @@ class KeyTest(unittest.TestCase):
def test_ed25519_nonbytes_password(self):
# https://github.com/paramiko/paramiko/issues/1039
key = Ed25519Key.from_private_key_file(
- test_path('test_ed25519_password.key'),
+ _support('test_ed25519_password.key'),
# NOTE: not a bytes. Amusingly, the test above for same key DOES
# explicitly cast to bytes...code smell!
'abc123',
@@ -477,14 +478,14 @@ class KeyTest(unittest.TestCase):
# No exception -> it's good. Meh.
def test_ed25519_load_from_file_obj(self):
- with open(test_path('test_ed25519.key')) as pkey_fileobj:
+ with open(_support('test_ed25519.key')) as pkey_fileobj:
key = Ed25519Key.from_private_key(pkey_fileobj)
self.assertEqual(key, key)
self.assertTrue(key.can_sign())
def test_keyfile_is_actually_encrypted(self):
# Read an existing encrypted private key
- file_ = test_path('test_rsa_password.key')
+ file_ = _support('test_rsa_password.key')
password = 'television'
newfile = file_ + '.new'
newpassword = 'radio'
@@ -502,10 +503,10 @@ class KeyTest(unittest.TestCase):
# test_client.py; this and nearby cert tests are more about the gritty
# details.
# PKey.load_certificate
- key_path = test_path(os.path.join('cert_support', 'test_rsa.key'))
+ key_path = _support(os.path.join('cert_support', 'test_rsa.key'))
key = RSAKey.from_private_key_file(key_path)
self.assertTrue(key.public_blob is None)
- cert_path = test_path(
+ cert_path = _support(
os.path.join('cert_support', 'test_rsa.key-cert.pub')
)
key.load_certificate(cert_path)
@@ -524,10 +525,10 @@ class KeyTest(unittest.TestCase):
self.assertEqual(msg.get_int64(), 1234)
# Prevented from loading certificate that doesn't match
- key_path = test_path(os.path.join('cert_support', 'test_ed25519.key'))
+ key_path = _support(os.path.join('cert_support', 'test_ed25519.key'))
key1 = Ed25519Key.from_private_key_file(key_path)
self.assertRaises(
ValueError,
key1.load_certificate,
- test_path('test_rsa.key-cert.pub'),
+ _support('test_rsa.key-cert.pub'),
)