Skip to content

Commit

Permalink
Re-raise InvalidValueError for PasswordRequiredException
Browse files Browse the repository at this point in the history
  • Loading branch information
huashengdun committed May 19, 2019
1 parent e1cd3ef commit 786b42d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ def test_get_specific_pkey_with_encrypted_key(self):
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'
Expand Down Expand Up @@ -205,8 +206,9 @@ def test_get_pkey_obj_with_encrypted_key(self):
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):
Expand Down
4 changes: 3 additions & 1 deletion webssh/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ def get_specific_pkey(cls, pkeycls, privatekey, password):
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:
Expand Down

0 comments on commit 786b42d

Please sign in to comment.