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):
...
@@ -69,18 +69,22 @@ class TestApp(AsyncHTTPTestCase):
body
=
'port=7000&username=admin&password'
body
=
'port=7000&username=admin&password'
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
self
.
assertEqual
(
response
.
code
,
400
)
self
.
assertIn
(
b
'Missing argument hostname'
,
response
.
body
)
self
.
assertIn
(
b
'Missing argument hostname'
,
response
.
body
)
body
=
'hostname=127.0.0.1&username=admin&password'
body
=
'hostname=127.0.0.1&username=admin&password'
self
.
assertEqual
(
response
.
code
,
400
)
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
self
.
assertIn
(
b
'Missing argument port'
,
response
.
body
)
self
.
assertIn
(
b
'Missing argument port'
,
response
.
body
)
body
=
'hostname=127.0.0.1&port=7000&password'
body
=
'hostname=127.0.0.1&port=7000&password'
self
.
assertEqual
(
response
.
code
,
400
)
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
self
.
assertIn
(
b
'Missing argument username'
,
response
.
body
)
self
.
assertIn
(
b
'Missing argument username'
,
response
.
body
)
body
=
'hostname=127.0.0.1&port=7000&username=admin'
body
=
'hostname=127.0.0.1&port=7000&username=admin'
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
body
)
self
.
assertEqual
(
response
.
code
,
400
)
self
.
assertIn
(
b
'Missing argument password'
,
response
.
body
)
self
.
assertIn
(
b
'Missing argument password'
,
response
.
body
)
body
=
'hostname=&port=&username=&password'
body
=
'hostname=&port=&username=&password'
...
@@ -370,7 +374,7 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -370,7 +374,7 @@ class TestApp(AsyncHTTPTestCase):
self
.
assertTrue
(
data
[
'status'
]
.
startswith
(
'Invalid private key'
))
self
.
assertTrue
(
data
[
'status'
]
.
startswith
(
'Invalid private key'
))
@tornado.testing.gen_test
@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
(
'/'
)
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
response
=
yield
client
.
fetch
(
url
)
...
@@ -386,16 +390,25 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -386,16 +390,25 @@ class TestApp(AsyncHTTPTestCase):
headers
=
{
headers
=
{
'Content-Type'
:
content_type
,
'content-length'
:
str
(
len
(
body
))
'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
,
@tornado.testing.gen_test
body
=
body
)
def
test_app_auth_with_pubkey_cannot_be_decoded_by_urlencoded_form
(
self
):
data
=
json
.
loads
(
to_str
(
response
.
body
))
url
=
self
.
get_url
(
'/'
)
self
.
assertIsNone
(
data
[
'id'
])
client
=
self
.
get_http_client
()
self
.
assertIsNone
(
data
[
'encoding'
])
response
=
yield
client
.
fetch
(
url
)
self
.
assertIn
(
'Bad Request (Invalid unicode'
,
data
[
'status'
])
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
@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
(
'/'
)
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
response
=
yield
client
.
fetch
(
url
)
...
@@ -409,5 +422,19 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -409,5 +422,19 @@ class TestApp(AsyncHTTPTestCase):
'Content-Type'
:
content_type
,
'content-length'
:
str
(
len
(
body
))
'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
)
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):
...
@@ -233,7 +233,7 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
try
:
try
:
worker
=
yield
future
worker
=
yield
future
except
Exception
as
exc
:
except
ValueError
as
exc
:
status
=
str
(
exc
)
status
=
str
(
exc
)
else
:
else
:
worker_id
=
worker
.
id
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