Exemplo n.º 1
0
 def test_get_pkey_obj_with_plain_key(self):
     fname = 'test_ed25519.key'
     cls = paramiko.Ed25519Key
     key = read_file(os.path.join(base_dir, 'tests', fname))
     pkey = IndexHandler.get_pkey_obj(key, None)
     self.assertIsInstance(pkey, cls)
     pkey = IndexHandler.get_pkey_obj(key, 'iginored')
     self.assertIsInstance(pkey, cls)
     with self.assertRaises(ValueError):
         pkey = IndexHandler.get_pkey_obj('x' + key, None)
Exemplo n.º 2
0
 def test_get_pkey_obj_with_plain_key(self):
     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(InvalidException) as exc:
         pkey = IndexHandler.get_pkey_obj('x' + key, None, fname)
         self.assertIn('Invalid private key', str(exc))
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 def test_get_pkey_obj_with_encrypted_key(self):
     fname = 'test_ed25519_password.key'
     password = '******'
     cls = paramiko.Ed25519Key
     key = read_file(os.path.join(base_dir, 'tests', fname))
     pkey = IndexHandler.get_pkey_obj(key, password)
     self.assertIsInstance(pkey, cls)
     with self.assertRaises(ValueError):
         pkey = IndexHandler.get_pkey_obj(key, 'wrongpass')
     with self.assertRaises(ValueError):
         pkey = IndexHandler.get_pkey_obj('x' + key, password)
Exemplo n.º 5
0
    def test_get_specific_pkey_with_plain_key(self):

        fname = 'test_rsa.key'
        cls = paramiko.RSAKey
        key = read_file(os.path.join(base_dir, 'tests', 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)
Exemplo n.º 6
0
 def test_get_pkey_obj_with_encrypted_key(self):
     fname = 'test_ed25519_password.key'
     password = '******'
     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(InvalidException) as exc:
         pkey = IndexHandler.get_pkey_obj(key, 'wrongpass', fname)
         self.assertIn('Wrong password', str(exc))
     with self.assertRaises(InvalidException) as exc:
         pkey = IndexHandler.get_pkey_obj('x' + key, password, fname)
         self.assertIn('Invalid private key', str(exc))
Exemplo n.º 7
0
    def test_get_specific_pkey_with_encrypted_key(self):
        fname = 'test_rsa_password.key'
        cls = paramiko.RSAKey
        password = '******'

        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)

        with self.assertRaises(paramiko.PasswordRequiredException):
            pkey = IndexHandler.get_specific_pkey(cls, key, None)
Exemplo n.º 8
0
    def test_get_specific_pkey_with_encrypted_key(self):
        fname = 'test_rsa_password.key'
        cls = paramiko.RSAKey
        password = '******'

        key = read_file(os.path.join(base_dir, 'tests', 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)

        with self.assertRaises(ValueError):
            pkey = IndexHandler.get_specific_pkey(cls, key, None)
Exemplo n.º 9
0
    def test_get_specific_pkey_with_encrypted_key(self):
        fname = 'test_rsa_password.key'
        cls = paramiko.RSAKey
        password = '******'

        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)

        with self.assertRaises(InvalidValueError) as ctx:
            pkey = IndexHandler.get_specific_pkey(cls, key, None)
        self.assertIn('Need a password', str(ctx.exception))