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
f4351318
Commit
f4351318
authored
Aug 29, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated tests
parent
6401e82e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
17 deletions
+21
-17
test_app.py
tests/test_app.py
+21
-17
No files found.
tests/test_app.py
View file @
f4351318
...
@@ -67,11 +67,13 @@ class TestAppBasic(AsyncHTTPTestCase):
...
@@ -67,11 +67,13 @@ class TestAppBasic(AsyncHTTPTestCase):
options
.
update
(
max_body_size
=
max_body_size
)
options
.
update
(
max_body_size
=
max_body_size
)
return
options
return
options
def
my_assertIn
(
self
,
part
,
whol
e
):
def
assert_response
(
self
,
bstr
,
respons
e
):
if
swallow_http_errors
:
if
swallow_http_errors
:
self
.
assertIn
(
part
,
whole
)
self
.
assertEqual
(
response
.
code
,
200
)
self
.
assertIn
(
bstr
,
response
.
body
)
else
:
else
:
self
.
assertIn
(
b
'Bad Request'
,
whole
)
self
.
assertEqual
(
response
.
code
,
400
)
self
.
assertIn
(
b
'Bad Request'
,
response
.
body
)
def
sync_post
(
self
,
body
,
headers
=
{},
url
=
'/'
,
method
=
'POST'
):
def
sync_post
(
self
,
body
,
headers
=
{},
url
=
'/'
,
method
=
'POST'
):
headers
.
update
(
self
.
headers
)
headers
.
update
(
self
.
headers
)
...
@@ -88,44 +90,44 @@ class TestAppBasic(AsyncHTTPTestCase):
...
@@ -88,44 +90,44 @@ class TestAppBasic(AsyncHTTPTestCase):
body
=
'port=7000&username=admin&password&_xsrf=yummy'
body
=
'port=7000&username=admin&password&_xsrf=yummy'
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Missing argument hostname'
,
response
.
body
)
self
.
assert_response
(
b
'Missing argument hostname'
,
response
)
body
=
'hostname=127.0.0.1&username=admin&password&_xsrf=yummy'
body
=
'hostname=127.0.0.1&username=admin&password&_xsrf=yummy'
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Missing argument port'
,
response
.
body
)
self
.
assert_response
(
b
'Missing argument port'
,
response
)
body
=
'hostname=127.0.0.1&port=7000&password&_xsrf=yummy'
body
=
'hostname=127.0.0.1&port=7000&password&_xsrf=yummy'
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Missing argument username'
,
response
.
body
)
self
.
assert_response
(
b
'Missing argument username'
,
response
)
body
=
'hostname=&port=&username=&password&_xsrf=yummy'
body
=
'hostname=&port=&username=&password&_xsrf=yummy'
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Missing value hostname'
,
response
.
body
)
self
.
assert_response
(
b
'Missing value hostname'
,
response
)
body
=
'hostname=127.0.0.1&port=&username=&password&_xsrf=yummy'
body
=
'hostname=127.0.0.1&port=&username=&password&_xsrf=yummy'
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Missing value port'
,
response
.
body
)
self
.
assert_response
(
b
'Missing value port'
,
response
)
body
=
'hostname=127.0.0.1&port=7000&username=&password&_xsrf=yummy'
body
=
'hostname=127.0.0.1&port=7000&username=&password&_xsrf=yummy'
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Missing value username'
,
response
.
body
)
self
.
assert_response
(
b
'Missing value username'
,
response
)
def
test_app_with_invalid_form_for_invalid_value
(
self
):
def
test_app_with_invalid_form_for_invalid_value
(
self
):
body
=
'hostname=127.0.0&port=22&username=&password&_xsrf=yummy'
body
=
'hostname=127.0.0&port=22&username=&password&_xsrf=yummy'
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Invalid hostname'
,
response
.
body
)
self
.
assert_response
(
b
'Invalid hostname'
,
response
)
body
=
'hostname=http://www.googe.com&port=22&username=&password&_xsrf=yummy'
# noqa
body
=
'hostname=http://www.googe.com&port=22&username=&password&_xsrf=yummy'
# noqa
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Invalid hostname'
,
response
.
body
)
self
.
assert_response
(
b
'Invalid hostname'
,
response
)
body
=
'hostname=127.0.0.1&port=port&username=&password&_xsrf=yummy'
body
=
'hostname=127.0.0.1&port=port&username=&password&_xsrf=yummy'
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Invalid port'
,
response
.
body
)
self
.
assert_response
(
b
'Invalid port'
,
response
)
body
=
'hostname=127.0.0.1&port=70000&username=&password&_xsrf=yummy'
body
=
'hostname=127.0.0.1&port=70000&username=&password&_xsrf=yummy'
response
=
self
.
sync_post
(
body
)
response
=
self
.
sync_post
(
body
)
self
.
my_assertIn
(
b
'Invalid port'
,
response
.
body
)
self
.
assert_response
(
b
'Invalid port'
,
response
)
def
test_app_with_wrong_hostname_ip
(
self
):
def
test_app_with_wrong_hostname_ip
(
self
):
body
=
'hostname=127.0.0.1&port=7000&username=admin&_xsrf=yummy'
body
=
'hostname=127.0.0.1&port=7000&username=admin&_xsrf=yummy'
...
@@ -466,15 +468,17 @@ class TestAppInDebug(OtherTestBase):
...
@@ -466,15 +468,17 @@ class TestAppInDebug(OtherTestBase):
debug
=
True
debug
=
True
def
my_assertIn
(
self
,
part
,
whol
e
):
def
assert_response
(
self
,
bstr
,
respons
e
):
if
swallow_http_errors
:
if
swallow_http_errors
:
self
.
assertIn
(
part
,
whole
)
self
.
assertEqual
(
response
.
code
,
200
)
self
.
assertIn
(
bstr
,
response
.
body
)
else
:
else
:
self
.
assertIn
(
b
'Uncaught exception'
,
whole
)
self
.
assertEqual
(
response
.
code
,
500
)
self
.
assertIn
(
b
'Uncaught exception'
,
response
.
body
)
def
test_server_error
(
self
):
def
test_server_error
(
self
):
response
=
self
.
fetch
(
'/?error=generate'
,
method
=
'GET'
)
response
=
self
.
fetch
(
'/?error=generate'
,
method
=
'GET'
)
self
.
my_assertIn
(
b
'"status": "Internal Server Error"'
,
response
.
body
)
self
.
assert_response
(
b
'"status": "Internal Server Error"'
,
response
)
def
test_html
(
self
):
def
test_html
(
self
):
response
=
self
.
fetch
(
'/'
,
method
=
'GET'
)
response
=
self
.
fetch
(
'/'
,
method
=
'GET'
)
...
...
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