webssh

Web based ssh client https://github.com/huashengdun/webssh webssh.huashengdun.org/
git clone http://git.hanabi.in/repos/webssh.git
Log | Files | Refs | README | LICENSE

commit bb9d193cae7e647d03a16b6ba3739456df227dde
parent 827a0d8a9dd10f78abfd83ebd8d58c31aba81c01
Author: Sheng <webmaster0115@gmail.com>
Date:   Sun, 14 Oct 2018 16:42:29 +0800

Fixed assertion in rasied exception context

Diffstat:
Mtests/test_handler.py | 26++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/tests/test_handler.py b/tests/test_handler.py @@ -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)