From 786b42da7e6f3b83e47bd9a357e9fbd9957e4d6d Mon Sep 17 00:00:00 2001 From: Sheng Date: Sun, 19 May 2019 20:27:44 +0800 Subject: [PATCH] Re-raise InvalidValueError for PasswordRequiredException --- tests/test_handler.py | 8 +++++--- webssh/handler.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_handler.py b/tests/test_handler.py index a35b858..bdc3389 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -170,8 +170,9 @@ class TestIndexHandler(unittest.TestCase): pkey = IndexHandler.get_specific_pkey(cls, 'x'+key, None) self.assertIsNone(pkey) - with self.assertRaises(paramiko.PasswordRequiredException): + with self.assertRaises(InvalidValueError) as ctx: 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): fname = 'test_ed25519.key' @@ -205,8 +206,9 @@ class TestIndexHandler(unittest.TestCase): 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) + with self.assertRaises(InvalidValueError) as ctx: + pkey = IndexHandler.get_specific_pkey(cls, key, None) + self.assertIn('Need a password', str(ctx.exception)) class TestWsockHandler(unittest.TestCase): diff --git a/webssh/handler.py b/webssh/handler.py index c8cdfbc..05bc0ee 100644 --- a/webssh/handler.py +++ b/webssh/handler.py @@ -226,7 +226,9 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): pkey = pkeycls.from_private_key(io.StringIO(privatekey), password=password) except paramiko.PasswordRequiredException: - raise + raise InvalidValueError( + 'Need a password to decrypt the private key.' + ) except paramiko.SSHException: pass else: