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
75770212
Commit
75770212
authored
Aug 24, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move all tests data into a separate directory
parent
74cdb2d3
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
29 additions
and
26 deletions
+29
-26
known_hosts_example
tests/data/known_hosts_example
+0
-0
known_hosts_example2
tests/data/known_hosts_example2
+0
-0
known_hosts_example3
tests/data/known_hosts_example3
+0
-0
test_ed25519.key
tests/data/test_ed25519.key
+0
-0
test_ed25519_password.key
tests/data/test_ed25519_password.key
+0
-0
test_rsa.key
tests/data/test_rsa.key
+0
-0
test_rsa_password.key
tests/data/test_rsa_password.key
+0
-0
user_rsa_key
tests/data/user_rsa_key
+0
-0
sshserver.py
tests/sshserver.py
+3
-4
test_app.py
tests/test_app.py
+3
-4
test_handler.py
tests/test_handler.py
+5
-7
test_policy.py
tests/test_policy.py
+9
-9
test_settings.py
tests/test_settings.py
+3
-2
utils.py
tests/utils.py
+6
-0
No files found.
tests/known_hosts_example
→
tests/
data/
known_hosts_example
View file @
75770212
File moved
tests/known_hosts_example2
→
tests/
data/
known_hosts_example2
View file @
75770212
File moved
tests/known_hosts_example3
→
tests/
data/
known_hosts_example3
View file @
75770212
File moved
tests/test_ed25519.key
→
tests/
data/
test_ed25519.key
View file @
75770212
File moved
tests/test_ed25519_password.key
→
tests/
data/
test_ed25519_password.key
View file @
75770212
File moved
tests/test_rsa.key
→
tests/
data/
test_rsa.key
View file @
75770212
File moved
tests/test_rsa_password.key
→
tests/
data/
test_rsa_password.key
View file @
75770212
File moved
tests/user_rsa_key
→
tests/
data/
user_rsa_key
View file @
75770212
File moved
tests/sshserver.py
View file @
75770212
...
...
@@ -18,7 +18,6 @@
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
import
os.path
import
random
import
socket
# import sys
...
...
@@ -28,13 +27,13 @@ import paramiko
from
binascii
import
hexlify
from
paramiko.py3compat
import
u
,
decodebytes
from
webssh.settings
import
base_dir
from
tests.utils
import
make_tests_data_path
# setup logging
paramiko
.
util
.
log_to_file
(
os
.
path
.
join
(
base_dir
,
'tests'
,
'sshserver.log'
))
paramiko
.
util
.
log_to_file
(
make_tests_data_path
(
'sshserver.log'
))
host_key
=
paramiko
.
RSAKey
(
filename
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'test_rsa.key'
))
# noqa
host_key
=
paramiko
.
RSAKey
(
filename
=
make_tests_data_path
(
'test_rsa.key'
))
# host_key = paramiko.DSSKey(filename='test_dss.key')
print
(
'Read key: '
+
u
(
hexlify
(
host_key
.
get_fingerprint
())))
...
...
tests/test_app.py
View file @
75770212
import
json
import
os.path
import
random
import
threading
import
tornado.websocket
...
...
@@ -10,9 +9,9 @@ from tornado.testing import AsyncHTTPTestCase
from
tornado.httpclient
import
HTTPError
from
tornado.options
import
options
from
tests.sshserver
import
run_ssh_server
,
banner
from
tests.utils
import
encode_multipart_formdata
,
read_file
from
tests.utils
import
encode_multipart_formdata
,
read_file
,
make_tests_data_path
# noqa
from
webssh.main
import
make_app
,
make_handlers
from
webssh.settings
import
get_app_settings
,
max_body_size
,
base_dir
from
webssh.settings
import
get_app_settings
,
max_body_size
from
webssh.utils
import
to_str
...
...
@@ -133,7 +132,7 @@ class TestApp(AsyncHTTPTestCase):
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
privatekey
=
read_file
(
os
.
path
.
join
(
base_dir
,
'tests'
,
'user_rsa_key'
))
privatekey
=
read_file
(
make_tests_data_path
(
'user_rsa_key'
))
files
=
[(
'privatekey'
,
'user_rsa_key'
,
privatekey
)]
content_type
,
body
=
encode_multipart_formdata
(
self
.
body_dict
.
items
(),
files
)
...
...
tests/test_handler.py
View file @
75770212
import
unittest
import
os.path
import
paramiko
from
tornado.httputil
import
HTTPServerRequest
from
tests.utils
import
read_file
from
tests.utils
import
read_file
,
make_tests_data_path
from
webssh.handler
import
MixinHandler
,
IndexHandler
,
parse_encoding
from
webssh.settings
import
base_dir
class
TestHandler
(
unittest
.
TestCase
):
...
...
@@ -53,7 +51,7 @@ class TestIndexHandler(unittest.TestCase):
fname
=
'test_rsa.key'
cls
=
paramiko
.
RSAKey
key
=
read_file
(
os
.
path
.
join
(
base_dir
,
'tests'
,
fname
))
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'
)
...
...
@@ -66,7 +64,7 @@ class TestIndexHandler(unittest.TestCase):
cls
=
paramiko
.
RSAKey
password
=
'television'
key
=
read_file
(
os
.
path
.
join
(
base_dir
,
'tests'
,
fname
))
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
)
...
...
@@ -78,7 +76,7 @@ class TestIndexHandler(unittest.TestCase):
def
test_get_pkey_obj_with_plain_key
(
self
):
fname
=
'test_ed25519.key'
cls
=
paramiko
.
Ed25519Key
key
=
read_file
(
os
.
path
.
join
(
base_dir
,
'tests'
,
fname
))
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
)
...
...
@@ -91,7 +89,7 @@ class TestIndexHandler(unittest.TestCase):
fname
=
'test_ed25519_password.key'
password
=
'abc123'
cls
=
paramiko
.
Ed25519Key
key
=
read_file
(
os
.
path
.
join
(
base_dir
,
'tests'
,
fname
))
key
=
read_file
(
make_tests_data_path
(
fname
))
pkey
=
IndexHandler
.
get_pkey_obj
(
key
,
password
,
fname
)
self
.
assertIsInstance
(
pkey
,
cls
)
with
self
.
assertRaises
(
ValueError
)
as
exc
:
...
...
tests/test_policy.py
View file @
75770212
...
...
@@ -4,11 +4,11 @@ import paramiko
from
shutil
import
copyfile
from
paramiko.client
import
RejectPolicy
,
WarningPolicy
from
tests.utils
import
make_tests_data_path
from
webssh.policy
import
(
AutoAddPolicy
,
get_policy_dictionary
,
load_host_keys
,
get_policy_class
,
check_policy_setting
)
from
webssh.settings
import
base_dir
class
TestPolicy
(
unittest
.
TestCase
):
...
...
@@ -29,7 +29,7 @@ class TestPolicy(unittest.TestCase):
host_keys
=
load_host_keys
(
path
)
self
.
assertFalse
(
host_keys
)
path
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'known_hosts_example'
)
path
=
make_tests_data_path
(
'known_hosts_example'
)
host_keys
=
load_host_keys
(
path
)
self
.
assertEqual
(
host_keys
,
paramiko
.
hostkeys
.
HostKeys
(
path
))
...
...
@@ -45,7 +45,7 @@ class TestPolicy(unittest.TestCase):
get_policy_class
(
key
)
def
test_check_policy_setting
(
self
):
host_keys_filename
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'host_keys_test.db'
)
# noqa
host_keys_filename
=
make_tests_data_path
(
'host_keys_test.db'
)
host_keys_settings
=
dict
(
host_keys
=
paramiko
.
hostkeys
.
HostKeys
(),
system_host_keys
=
paramiko
.
hostkeys
.
HostKeys
(),
...
...
@@ -64,8 +64,8 @@ class TestPolicy(unittest.TestCase):
def
test_is_missing_host_key
(
self
):
client
=
paramiko
.
SSHClient
()
file1
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'known_hosts_example'
)
file2
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'known_hosts_example2'
)
file1
=
make_tests_data_path
(
'known_hosts_example'
)
file2
=
make_tests_data_path
(
'known_hosts_example2'
)
client
.
load_host_keys
(
file1
)
client
.
load_system_host_keys
(
file2
)
...
...
@@ -86,7 +86,7 @@ class TestPolicy(unittest.TestCase):
autoadd
.
is_missing_host_key
(
client
,
hostname
,
key
)
)
file3
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'known_hosts_example3'
)
file3
=
make_tests_data_path
(
'known_hosts_example3'
)
entry
=
paramiko
.
hostkeys
.
HostKeys
(
file3
)
.
_entries
[
0
]
hostname
=
entry
.
hostnames
[
0
]
key
=
entry
.
key
...
...
@@ -95,9 +95,9 @@ class TestPolicy(unittest.TestCase):
def
test_missing_host_key
(
self
):
client
=
paramiko
.
SSHClient
()
file1
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'known_hosts_example'
)
file2
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'known_hosts_example2'
)
filename
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'known_hosts'
)
file1
=
make_tests_data_path
(
'known_hosts_example'
)
file2
=
make_tests_data_path
(
'known_hosts_example2'
)
filename
=
make_tests_data_path
(
'known_hosts'
)
copyfile
(
file1
,
filename
)
client
.
load_host_keys
(
filename
)
n1
=
len
(
client
.
_host_keys
)
...
...
tests/test_settings.py
View file @
75770212
...
...
@@ -3,6 +3,7 @@ import unittest
import
paramiko
import
tornado.options
as
options
from
tests.utils
import
make_tests_data_path
from
webssh.policy
import
load_host_keys
from
webssh.settings
import
(
get_host_keys_settings
,
get_policy_setting
,
base_dir
,
print_version
...
...
@@ -30,8 +31,8 @@ class TestSettings(unittest.TestCase):
load_host_keys
(
os
.
path
.
expanduser
(
'~/.ssh/known_hosts'
))
)
options
.
hostFile
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'known_hosts_example'
)
# noqa
options
.
sysHostFile
=
os
.
path
.
join
(
base_dir
,
'tests'
,
'known_hosts_example2'
)
# noqa
options
.
hostFile
=
make_tests_data_path
(
'known_hosts_example'
)
options
.
sysHostFile
=
make_tests_data_path
(
'known_hosts_example2'
)
dic2
=
get_host_keys_settings
(
options
)
self
.
assertEqual
(
dic2
[
'host_keys'
],
load_host_keys
(
options
.
hostFile
))
self
.
assertEqual
(
dic2
[
'host_keys_filename'
],
options
.
hostFile
)
...
...
tests/utils.py
View file @
75770212
import
mimetypes
import
os.path
from
uuid
import
uuid4
from
webssh.settings
import
base_dir
def
encode_multipart_formdata
(
fields
,
files
):
...
...
@@ -40,3 +42,7 @@ def get_content_type(filename):
def
read_file
(
path
,
encoding
=
'utf-8'
):
return
open
(
path
,
'rb'
)
.
read
()
.
decode
(
encoding
)
def
make_tests_data_path
(
filename
):
return
os
.
path
.
join
(
base_dir
,
'tests'
,
'data'
,
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