Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑天保
webssh
Commits
bb9d193c
Commit
bb9d193c
authored
Oct 14, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed assertion in rasied exception context
parent
827a0d8a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
test_handler.py
tests/test_handler.py
+18
-8
No files found.
tests/test_handler.py
View file @
bb9d193c
...
@@ -51,14 +51,16 @@ class TestMixinHandler(unittest.TestCase):
...
@@ -51,14 +51,16 @@ class TestMixinHandler(unittest.TestCase):
class
TestIndexHandler
(
unittest
.
TestCase
):
class
TestIndexHandler
(
unittest
.
TestCase
):
def
test_get_specific_pkey_with_plain_key
(
self
):
def
test_get_specific_pkey_with_plain_key
(
self
):
fname
=
'test_rsa.key'
fname
=
'test_rsa.key'
cls
=
paramiko
.
RSAKey
cls
=
paramiko
.
RSAKey
key
=
read_file
(
make_tests_data_path
(
fname
))
key
=
read_file
(
make_tests_data_path
(
fname
))
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
key
,
None
)
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
key
,
None
)
self
.
assertIsInstance
(
pkey
,
cls
)
self
.
assertIsInstance
(
pkey
,
cls
)
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
key
,
'iginored'
)
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
key
,
'iginored'
)
self
.
assertIsInstance
(
pkey
,
cls
)
self
.
assertIsInstance
(
pkey
,
cls
)
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
'x'
+
key
,
None
)
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
'x'
+
key
,
None
)
self
.
assertIsNone
(
pkey
)
self
.
assertIsNone
(
pkey
)
...
@@ -70,6 +72,7 @@ class TestIndexHandler(unittest.TestCase):
...
@@ -70,6 +72,7 @@ class TestIndexHandler(unittest.TestCase):
key
=
read_file
(
make_tests_data_path
(
fname
))
key
=
read_file
(
make_tests_data_path
(
fname
))
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
key
,
password
)
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
key
,
password
)
self
.
assertIsInstance
(
pkey
,
cls
)
self
.
assertIsInstance
(
pkey
,
cls
)
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
'x'
+
key
,
None
)
pkey
=
IndexHandler
.
get_specific_pkey
(
cls
,
'x'
+
key
,
None
)
self
.
assertIsNone
(
pkey
)
self
.
assertIsNone
(
pkey
)
...
@@ -80,26 +83,33 @@ class TestIndexHandler(unittest.TestCase):
...
@@ -80,26 +83,33 @@ class TestIndexHandler(unittest.TestCase):
fname
=
'test_ed25519.key'
fname
=
'test_ed25519.key'
cls
=
paramiko
.
Ed25519Key
cls
=
paramiko
.
Ed25519Key
key
=
read_file
(
make_tests_data_path
(
fname
))
key
=
read_file
(
make_tests_data_path
(
fname
))
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
None
,
fname
)
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
None
,
fname
)
self
.
assertIsInstance
(
pkey
,
cls
)
self
.
assertIsInstance
(
pkey
,
cls
)
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
'iginored'
,
fname
)
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
'iginored'
,
fname
)
self
.
assertIsInstance
(
pkey
,
cls
)
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
)
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
):
def
test_get_pkey_obj_with_encrypted_key
(
self
):
fname
=
'test_ed25519_password.key'
fname
=
'test_ed25519_password.key'
password
=
'abc123'
password
=
'abc123'
cls
=
paramiko
.
Ed25519Key
cls
=
paramiko
.
Ed25519Key
key
=
read_file
(
make_tests_data_path
(
fname
))
key
=
read_file
(
make_tests_data_path
(
fname
))
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
password
,
fname
)
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
password
,
fname
)
self
.
assertIsInstance
(
pkey
,
cls
)
self
.
assertIsInstance
(
pkey
,
cls
)
with
self
.
assertRaises
(
InvalidValueError
)
as
exc
:
with
self
.
assertRaises
(
InvalidValueError
)
as
ctx
:
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
'wrongpass'
,
fname
)
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
'wrongpass'
,
fname
)
self
.
assertIn
(
'Wrong password'
,
str
(
exc
))
self
.
assertIn
(
'Wrong password'
,
str
(
ctx
.
exception
))
with
self
.
assertRaises
(
InvalidValueError
)
as
exc
:
pkey
=
IndexHandler
.
get_pkey_obj
(
'x'
+
key
,
password
,
fname
)
with
self
.
assertRaises
(
InvalidValueError
)
as
ctx
:
self
.
assertIn
(
'Invalid private key'
,
str
(
exc
))
pkey
=
IndexHandler
.
get_pkey_obj
(
'x'
+
key
,
''
,
fname
)
self
.
assertIn
(
'Invalid private key'
,
str
(
ctx
.
exception
))
with
self
.
assertRaises
(
paramiko
.
PasswordRequiredException
):
with
self
.
assertRaises
(
paramiko
.
PasswordRequiredException
):
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
''
,
fname
)
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
''
,
fname
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment