|
|
|
@ -51,14 +51,16 @@ class TestMixinHandler(unittest.TestCase):
|
|
|
|
|
class TestIndexHandler(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_get_specific_pkey_with_plain_key(self):
|
|
|
|
|
|
|
|
|
|
fname = 'test_rsa.key'
|
|
|
|
|
cls = paramiko.RSAKey
|
|
|
|
|
key = read_file(make_tests_data_path(fname))
|
|
|
|
|
|
|
|
|
|
pkey = IndexHandler.get_specific_pkey(cls, key, None)
|
|
|
|
|
self.assertIsInstance(pkey, cls)
|
|
|
|
|
|
|
|
|
|
pkey = IndexHandler.get_specific_pkey(cls, key, 'iginored')
|
|
|
|
|
self.assertIsInstance(pkey, cls)
|
|
|
|
|
|
|
|
|
|
pkey = IndexHandler.get_specific_pkey(cls, 'x'+key, None)
|
|
|
|
|
self.assertIsNone(pkey)
|
|
|
|
|
|
|
|
|
@ -70,6 +72,7 @@ class TestIndexHandler(unittest.TestCase):
|
|
|
|
|
key = read_file(make_tests_data_path(fname))
|
|
|
|
|
pkey = IndexHandler.get_specific_pkey(cls, key, password)
|
|
|
|
|
self.assertIsInstance(pkey, cls)
|
|
|
|
|
|
|
|
|
|
pkey = IndexHandler.get_specific_pkey(cls, 'x'+key, None)
|
|
|
|
|
self.assertIsNone(pkey)
|
|
|
|
|
|
|
|
|
@ -80,26 +83,33 @@ class TestIndexHandler(unittest.TestCase):
|
|
|
|
|
fname = 'test_ed25519.key'
|
|
|
|
|
cls = paramiko.Ed25519Key
|
|
|
|
|
key = read_file(make_tests_data_path(fname))
|
|
|
|
|
|
|
|
|
|
pkey = IndexHandler.get_pkey_obj(key, None, fname)
|
|
|
|
|
self.assertIsInstance(pkey, cls)
|
|
|
|
|
|
|
|
|
|
pkey = IndexHandler.get_pkey_obj(key, 'iginored', fname)
|
|
|
|
|
self.assertIsInstance(pkey, cls)
|
|
|
|
|
with self.assertRaises(InvalidValueError) as exc:
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(InvalidValueError) as ctx:
|
|
|
|
|
pkey = IndexHandler.get_pkey_obj('x'+key, None, fname)
|
|
|
|
|
self.assertIn('Invalid private key', str(exc))
|
|
|
|
|
self.assertIn('Invalid private key', str(ctx.exception))
|
|
|
|
|
|
|
|
|
|
def test_get_pkey_obj_with_encrypted_key(self):
|
|
|
|
|
fname = 'test_ed25519_password.key'
|
|
|
|
|
password = 'abc123'
|
|
|
|
|
cls = paramiko.Ed25519Key
|
|
|
|
|
key = read_file(make_tests_data_path(fname))
|
|
|
|
|
|
|
|
|
|
pkey = IndexHandler.get_pkey_obj(key, password, fname)
|
|
|
|
|
self.assertIsInstance(pkey, cls)
|
|
|
|
|
with self.assertRaises(InvalidValueError) as exc:
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(InvalidValueError) as ctx:
|
|
|
|
|
pkey = IndexHandler.get_pkey_obj(key, 'wrongpass', fname)
|
|
|
|
|
self.assertIn('Wrong password', str(exc))
|
|
|
|
|
with self.assertRaises(InvalidValueError) as exc:
|
|
|
|
|
pkey = IndexHandler.get_pkey_obj('x'+key, password, fname)
|
|
|
|
|
self.assertIn('Invalid private key', str(exc))
|
|
|
|
|
self.assertIn('Wrong password', str(ctx.exception))
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(InvalidValueError) as ctx:
|
|
|
|
|
pkey = IndexHandler.get_pkey_obj('x'+key, '', fname)
|
|
|
|
|
self.assertIn('Invalid private key', str(ctx.exception))
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(paramiko.PasswordRequiredException):
|
|
|
|
|
pkey = IndexHandler.get_pkey_obj(key, '', fname)
|
|
|
|
|