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
99d4b5fb
Commit
99d4b5fb
authored
Apr 23, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated test_policy.py
parent
7b715bea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
known_hosts_example3
tests/known_hosts_example3
+1
-0
test_policy.py
tests/test_policy.py
+51
-0
No files found.
tests/known_hosts_example3
0 → 100644
View file @
99d4b5fb
192.168.1.196 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINwZGQmNFADnAAlm5uFLQTrdxqpNxHdgg4JPbB3sR2jr
tests/test_policy.py
View file @
99d4b5fb
...
@@ -2,6 +2,7 @@ import os
...
@@ -2,6 +2,7 @@ import os
import
unittest
import
unittest
import
paramiko
import
paramiko
from
shutil
import
copyfile
from
paramiko.client
import
RejectPolicy
,
WarningPolicy
from
paramiko.client
import
RejectPolicy
,
WarningPolicy
from
policy
import
(
AutoAddPolicy
,
get_policy_dictionary
,
load_host_keys
,
from
policy
import
(
AutoAddPolicy
,
get_policy_dictionary
,
load_host_keys
,
get_policy_class
,
check_policy_setting
)
get_policy_class
,
check_policy_setting
)
...
@@ -57,3 +58,53 @@ class TestPolicy(unittest.TestCase):
...
@@ -57,3 +58,53 @@ class TestPolicy(unittest.TestCase):
pass
pass
check_policy_setting
(
AutoAddPolicy
,
host_keys_settings
)
check_policy_setting
(
AutoAddPolicy
,
host_keys_settings
)
self
.
assertEqual
(
os
.
path
.
exists
(
host_keys_filename
),
True
)
self
.
assertEqual
(
os
.
path
.
exists
(
host_keys_filename
),
True
)
def
test_is_missing_host_key
(
self
):
client
=
paramiko
.
SSHClient
()
file1
=
'tests/known_hosts_example'
file2
=
'tests/known_hosts_example2'
client
.
load_host_keys
(
file1
)
client
.
load_system_host_keys
(
file2
)
autoadd
=
AutoAddPolicy
()
for
f
in
[
file1
,
file2
]:
entry
=
paramiko
.
hostkeys
.
HostKeys
(
f
)
.
_entries
[
0
]
hostname
=
entry
.
hostnames
[
0
]
key
=
entry
.
key
self
.
assertIsNone
(
autoadd
.
is_missing_host_key
(
client
,
hostname
,
key
)
)
for
f
in
[
file1
,
file2
]:
entry
=
paramiko
.
hostkeys
.
HostKeys
(
f
)
.
_entries
[
0
]
hostname
=
entry
.
hostnames
[
0
][
1
:]
key
=
entry
.
key
self
.
assertTrue
(
autoadd
.
is_missing_host_key
(
client
,
hostname
,
key
)
)
file3
=
'tests/known_hosts_example3'
entry
=
paramiko
.
hostkeys
.
HostKeys
(
file3
)
.
_entries
[
0
]
hostname
=
entry
.
hostnames
[
0
]
key
=
entry
.
key
with
self
.
assertRaises
(
paramiko
.
BadHostKeyException
):
autoadd
.
is_missing_host_key
(
client
,
hostname
,
key
)
def
test_missing_host_key
(
self
):
client
=
paramiko
.
SSHClient
()
file1
=
'tests/known_hosts_example'
file2
=
'tests/known_hosts_example2'
filename
=
'tests/known_hosts'
copyfile
(
file1
,
filename
)
client
.
load_host_keys
(
filename
)
n1
=
len
(
client
.
_host_keys
)
autoadd
=
AutoAddPolicy
()
entry
=
paramiko
.
hostkeys
.
HostKeys
(
file2
)
.
_entries
[
0
]
hostname
=
entry
.
hostnames
[
0
]
key
=
entry
.
key
autoadd
.
missing_host_key
(
client
,
hostname
,
key
)
self
.
assertEqual
(
len
(
client
.
_host_keys
),
n1
+
1
)
self
.
assertEqual
(
paramiko
.
hostkeys
.
HostKeys
(
filename
),
client
.
_host_keys
)
os
.
unlink
(
filename
)
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