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
251fd90e
Commit
251fd90e
authored
Apr 23, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more unittests to test_policy.py
parent
af6b134b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
1 deletions
+43
-1
test_policy.py
tests/test_policy.py
+43
-1
No files found.
tests/test_policy.py
View file @
251fd90e
import
os
import
unittest
import
paramiko
from
paramiko.client
import
RejectPolicy
,
WarningPolicy
from
webssh.policy
import
AutoAddPolicy
,
get_policy_dictionary
from
webssh.policy
import
AutoAddPolicy
,
get_policy_dictionary
,
load_host_keys
from
webssh.policy
import
get_policy_class
,
check_policy_setting
class
TestPolicy
(
unittest
.
TestCase
):
...
...
@@ -11,3 +15,41 @@ class TestPolicy(unittest.TestCase):
for
cls
in
classes
:
val
=
dic
[
cls
.
__name__
.
lower
()]
self
.
assertIs
(
cls
,
val
)
def
test_load_host_keys
(
self
):
path
=
'/path-not-exists'
host_keys
=
load_host_keys
(
path
)
self
.
assertFalse
(
host_keys
)
path
=
'/tmp'
host_keys
=
load_host_keys
(
path
)
self
.
assertFalse
(
host_keys
)
def
test_get_policy_class
(
self
):
keys
=
[
'autoadd'
,
'reject'
,
'warning'
]
vals
=
[
AutoAddPolicy
,
RejectPolicy
,
WarningPolicy
]
for
key
,
val
in
zip
(
keys
,
vals
):
cls
=
get_policy_class
(
key
)
self
.
assertIs
(
cls
,
val
)
key
=
'non-exists'
with
self
.
assertRaises
(
ValueError
):
get_policy_class
(
key
)
def
test_check_policy_setting
(
self
):
host_keys_filename
=
'./webssh/host_keys_test.db'
host_keys_settings
=
dict
(
host_keys
=
paramiko
.
hostkeys
.
HostKeys
(),
system_host_keys
=
paramiko
.
hostkeys
.
HostKeys
(),
host_keys_filename
=
host_keys_filename
)
with
self
.
assertRaises
(
ValueError
):
check_policy_setting
(
RejectPolicy
,
host_keys_settings
)
try
:
os
.
unlink
(
host_keys_filename
)
except
OSError
:
pass
check_policy_setting
(
AutoAddPolicy
,
host_keys_settings
)
self
.
assertEqual
(
os
.
path
.
exists
(
host_keys_filename
),
True
)
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