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
f3d9d297
Commit
f3d9d297
authored
Aug 25, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated tests
parent
75770212
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
71 deletions
+102
-71
test_app.py
tests/test_app.py
+98
-70
utils.py
tests/utils.py
+4
-1
No files found.
tests/test_app.py
View file @
f3d9d297
...
...
@@ -14,6 +14,11 @@ from webssh.main import make_app, make_handlers
from
webssh.settings
import
get_app_settings
,
max_body_size
from
webssh.utils
import
to_str
try
:
from
urllib.parse
import
urlencode
except
ImportError
:
from
urllib
import
urlencode
handler
.
DELAY
=
0.1
...
...
@@ -123,10 +128,102 @@ class TestApp(AsyncHTTPTestCase):
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
msg
=
yield
ws
.
read_message
()
self
.
assertIsNone
(
msg
)
self
.
assertEqual
(
ws
.
close_reason
,
'Websocket authentication failed.'
)
@tornado.testing.gen_test
def
test_app_with_correct_credentials_user_robey
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
response
=
yield
client
.
fetch
(
url
,
method
=
'POST'
,
body
=
self
.
body
)
data
=
json
.
loads
(
to_str
(
response
.
body
))
self
.
assertIsNone
(
data
[
'status'
])
self
.
assertIsNotNone
(
data
[
'id'
])
self
.
assertIsNotNone
(
data
[
'encoding'
])
url
=
url
.
replace
(
'http'
,
'ws'
)
ws_url
=
url
+
'ws?id='
+
data
[
'id'
]
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
to_str
(
msg
,
data
[
'encoding'
]),
banner
)
ws
.
close
()
@tornado.testing.gen_test
def
test_app_with_correct_credentials_user_bar
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
body
=
self
.
body
.
replace
(
'robey'
,
'bar'
)
response
=
yield
client
.
fetch
(
url
,
method
=
'POST'
,
body
=
body
)
data
=
json
.
loads
(
to_str
(
response
.
body
))
self
.
assertIsNone
(
data
[
'status'
])
self
.
assertIsNotNone
(
data
[
'id'
])
self
.
assertIsNotNone
(
data
[
'encoding'
])
url
=
url
.
replace
(
'http'
,
'ws'
)
ws_url
=
url
+
'ws?id='
+
data
[
'id'
]
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
to_str
(
msg
,
data
[
'encoding'
]),
banner
)
# messages below will be ignored silently
yield
ws
.
write_message
(
'hello'
)
yield
ws
.
write_message
(
'"hello"'
)
yield
ws
.
write_message
(
'[hello]'
)
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[]}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
{}}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
'ab'
}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
'a'
,
'b'
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
{
'a'
:
1
,
'b'
:
2
}}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
100
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
100
]
*
10
}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
-
1
,
-
1
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
[
1
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
(
1
,)}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
{
'a'
:
2
}}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
1
}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
2.1
}))
yield
ws
.
write_message
(
json
.
dumps
({
'key-non-existed'
:
'hello'
}))
# end - those just for testing webssh websocket stablity
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
79
,
23
]}))
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
b
'resized'
,
msg
)
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
'bye'
}))
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
b
'bye'
,
msg
)
ws
.
close
()
@tornado.testing.gen_test
def
test_app_auth_with_valid_pubkey_by_urlencoded_form
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
privatekey
=
read_file
(
make_tests_data_path
(
'user_rsa_key'
))
self
.
body_dict
.
update
(
privatekey
=
privatekey
)
body
=
urlencode
(
self
.
body_dict
)
response
=
yield
client
.
fetch
(
url
,
method
=
'POST'
,
body
=
body
)
data
=
json
.
loads
(
to_str
(
response
.
body
))
self
.
assertIsNone
(
data
[
'status'
])
self
.
assertIsNotNone
(
data
[
'id'
])
self
.
assertIsNotNone
(
data
[
'encoding'
])
url
=
url
.
replace
(
'http'
,
'ws'
)
ws_url
=
url
+
'ws?id='
+
data
[
'id'
]
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
to_str
(
msg
,
data
[
'encoding'
]),
banner
)
ws
.
close
()
@tornado.testing.gen_test
def
test_app_auth_with_valid_pubkey_
for_user_robey
(
self
):
def
test_app_auth_with_valid_pubkey_
by_multipart_form
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
...
...
@@ -237,72 +334,3 @@ class TestApp(AsyncHTTPTestCase):
with
self
.
assertRaises
(
HTTPError
):
yield
client
.
fetch
(
url
,
method
=
'POST'
,
headers
=
headers
,
body
=
body
)
@tornado.testing.gen_test
def
test_app_with_correct_credentials_user_robey
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
response
=
yield
client
.
fetch
(
url
,
method
=
'POST'
,
body
=
self
.
body
)
data
=
json
.
loads
(
to_str
(
response
.
body
))
self
.
assertIsNone
(
data
[
'status'
])
self
.
assertIsNotNone
(
data
[
'id'
])
self
.
assertIsNotNone
(
data
[
'encoding'
])
url
=
url
.
replace
(
'http'
,
'ws'
)
ws_url
=
url
+
'ws?id='
+
data
[
'id'
]
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
to_str
(
msg
,
data
[
'encoding'
]),
banner
)
ws
.
close
()
@tornado.testing.gen_test
def
test_app_with_correct_credentials_user_bar
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
body
=
self
.
body
.
replace
(
'robey'
,
'bar'
)
response
=
yield
client
.
fetch
(
url
,
method
=
'POST'
,
body
=
body
)
data
=
json
.
loads
(
to_str
(
response
.
body
))
self
.
assertIsNone
(
data
[
'status'
])
self
.
assertIsNotNone
(
data
[
'id'
])
self
.
assertIsNotNone
(
data
[
'encoding'
])
url
=
url
.
replace
(
'http'
,
'ws'
)
ws_url
=
url
+
'ws?id='
+
data
[
'id'
]
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
to_str
(
msg
,
data
[
'encoding'
]),
banner
)
# messages below will be ignored silently
yield
ws
.
write_message
(
'hello'
)
yield
ws
.
write_message
(
'"hello"'
)
yield
ws
.
write_message
(
'[hello]'
)
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[]}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
{}}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
'ab'
}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
'a'
,
'b'
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
{
'a'
:
1
,
'b'
:
2
}}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
100
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
100
]
*
10
}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
-
1
,
-
1
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
[
1
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
(
1
,)}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
{
'a'
:
2
}}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
1
}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
2.1
}))
yield
ws
.
write_message
(
json
.
dumps
({
'key-non-existed'
:
'hello'
}))
# end - those just for testing webssh websocket stablity
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
79
,
23
]}))
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
b
'resized'
,
msg
)
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
'bye'
}))
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
b
'bye'
,
msg
)
ws
.
close
()
tests/utils.py
View file @
f3d9d297
...
...
@@ -41,7 +41,10 @@ def get_content_type(filename):
def
read_file
(
path
,
encoding
=
'utf-8'
):
return
open
(
path
,
'rb'
)
.
read
()
.
decode
(
encoding
)
data
=
open
(
path
,
'rb'
)
.
read
()
if
encoding
is
None
:
return
data
return
data
.
decode
(
encoding
)
def
make_tests_data_path
(
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