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
df26d0e6
Commit
df26d0e6
authored
Aug 25, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch ValueError instead of Exception for post method
parent
9fd8d136
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
10 deletions
+37
-10
test_app.py
tests/test_app.py
+36
-9
handler.py
webssh/handler.py
+1
-1
No files found.
tests/test_app.py
View file @
df26d0e6
...
...
@@ -69,18 +69,22 @@ class TestApp(AsyncHTTPTestCase):
body
=
'port=7000&username=admin&password'
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
self
.
assertEqual
(
response
.
code
,
400
)
self
.
assertIn
(
b
'Missing argument hostname'
,
response
.
body
)
body
=
'hostname=127.0.0.1&username=admin&password'
self
.
assertEqual
(
response
.
code
,
400
)
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
self
.
assertIn
(
b
'Missing argument port'
,
response
.
body
)
body
=
'hostname=127.0.0.1&port=7000&password'
self
.
assertEqual
(
response
.
code
,
400
)
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
self
.
assertIn
(
b
'Missing argument username'
,
response
.
body
)
body
=
'hostname=127.0.0.1&port=7000&username=admin'
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
self
.
assertEqual
(
response
.
code
,
400
)
self
.
assertIn
(
b
'Missing argument password'
,
response
.
body
)
body
=
'hostname=&port=&username=&password'
...
...
@@ -370,7 +374,7 @@ class TestApp(AsyncHTTPTestCase):
self
.
assertTrue
(
data
[
'status'
]
.
startswith
(
'Invalid private key'
))
@tornado.testing.gen_test
def
test_app_auth_with_pubkey_cannot_be_decoded
(
self
):
def
test_app_auth_with_pubkey_cannot_be_decoded
_by_multipart_form
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
...
...
@@ -386,16 +390,25 @@ class TestApp(AsyncHTTPTestCase):
headers
=
{
'Content-Type'
:
content_type
,
'content-length'
:
str
(
len
(
body
))
}
with
self
.
assertRaises
(
HTTPError
)
as
exc
:
yield
client
.
fetch
(
url
,
method
=
'POST'
,
headers
=
headers
,
body
=
body
)
self
.
assertIn
(
'Bad Request (Invalid unicode'
,
exc
.
msg
)
response
=
yield
client
.
fetch
(
url
,
method
=
'POST'
,
headers
=
headers
,
body
=
body
)
data
=
json
.
loads
(
to_str
(
response
.
body
))
self
.
assertIsNone
(
data
[
'id'
])
self
.
assertIsNone
(
data
[
'encoding'
])
self
.
assertIn
(
'Bad Request (Invalid unicode'
,
data
[
'status'
])
@tornado.testing.gen_test
def
test_app_auth_with_pubkey_cannot_be_decoded_by_urlencoded_form
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
privatekey
=
b
'h'
*
1024
+
b
'
\xb4\xed\xce\xf3
'
body
=
self
.
body
.
encode
()
+
b
'&privatekey='
+
privatekey
with
self
.
assertRaises
(
HTTPError
)
as
exc
:
yield
client
.
fetch
(
url
,
method
=
'POST'
,
body
=
body
)
self
.
assertIn
(
'Bad Request (Invalid unicode'
,
exc
.
msg
)
@tornado.testing.gen_test
def
test_app_post_form_with_large_body_size
(
self
):
def
test_app_post_form_with_large_body_size
_by_multipart_form
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
...
...
@@ -409,5 +422,19 @@ class TestApp(AsyncHTTPTestCase):
'Content-Type'
:
content_type
,
'content-length'
:
str
(
len
(
body
))
}
with
self
.
assertRaises
(
HTTPError
):
with
self
.
assertRaises
(
HTTPError
)
as
exc
:
yield
client
.
fetch
(
url
,
method
=
'POST'
,
headers
=
headers
,
body
=
body
)
self
.
assertIsNone
(
exc
.
msg
)
@tornado.testing.gen_test
def
test_app_post_form_with_large_body_size_by_urlencoded_form
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
privatekey
=
'h'
*
(
2
*
max_body_size
)
body
=
self
.
body
+
'&privatekey='
+
privatekey
with
self
.
assertRaises
(
HTTPError
)
as
exc
:
yield
client
.
fetch
(
url
,
method
=
'POST'
,
body
=
body
)
self
.
assertIsNone
(
exc
.
msg
)
webssh/handler.py
View file @
df26d0e6
...
...
@@ -233,7 +233,7 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
try
:
worker
=
yield
future
except
Exception
as
exc
:
except
ValueError
as
exc
:
status
=
str
(
exc
)
else
:
worker_id
=
worker
.
id
...
...
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