Re-raise InvalidValueError for PasswordRequiredException

static
Sheng 2019-05-19 20:27:44 +08:00
parent e1cd3efdf0
commit 786b42da7e
2 changed files with 8 additions and 4 deletions

View File

@ -170,8 +170,9 @@ class TestIndexHandler(unittest.TestCase):
pkey = IndexHandler.get_specific_pkey(cls, 'x'+key, None) pkey = IndexHandler.get_specific_pkey(cls, 'x'+key, None)
self.assertIsNone(pkey) self.assertIsNone(pkey)
with self.assertRaises(paramiko.PasswordRequiredException): with self.assertRaises(InvalidValueError) as ctx:
pkey = IndexHandler.get_specific_pkey(cls, key, None) pkey = IndexHandler.get_specific_pkey(cls, key, None)
self.assertIn('Need a password', str(ctx.exception))
def test_get_pkey_obj_with_plain_key(self): def test_get_pkey_obj_with_plain_key(self):
fname = 'test_ed25519.key' fname = 'test_ed25519.key'
@ -205,8 +206,9 @@ class TestIndexHandler(unittest.TestCase):
pkey = IndexHandler.get_pkey_obj('x'+key, '', fname) pkey = IndexHandler.get_pkey_obj('x'+key, '', fname)
self.assertIn('Invalid private key', str(ctx.exception)) self.assertIn('Invalid private key', str(ctx.exception))
with self.assertRaises(paramiko.PasswordRequiredException): with self.assertRaises(InvalidValueError) as ctx:
pkey = IndexHandler.get_pkey_obj(key, '', fname) pkey = IndexHandler.get_specific_pkey(cls, key, None)
self.assertIn('Need a password', str(ctx.exception))
class TestWsockHandler(unittest.TestCase): class TestWsockHandler(unittest.TestCase):

View File

@ -226,7 +226,9 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
pkey = pkeycls.from_private_key(io.StringIO(privatekey), pkey = pkeycls.from_private_key(io.StringIO(privatekey),
password=password) password=password)
except paramiko.PasswordRequiredException: except paramiko.PasswordRequiredException:
raise raise InvalidValueError(
'Need a password to decrypt the private key.'
)
except paramiko.SSHException: except paramiko.SSHException:
pass pass
else: else: