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
af60cd1c
Commit
af60cd1c
authored
Oct 16, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tested app with 403 and 404 requests
parent
e94c8463
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
+46
-2
test_app.py
tests/test_app.py
+44
-0
handler.py
webssh/handler.py
+2
-2
No files found.
tests/test_app.py
View file @
af60cd1c
...
@@ -561,3 +561,47 @@ class TestAppWithRejectPolicy(OtherTestBase):
...
@@ -561,3 +561,47 @@ class TestAppWithRejectPolicy(OtherTestBase):
self
.
assertIsNone
(
data
[
'encoding'
])
self
.
assertIsNone
(
data
[
'encoding'
])
message
=
'Connection to {}:{} is not allowed.'
.
format
(
self
.
body
[
'hostname'
],
self
.
sshserver_port
)
# noqa
message
=
'Connection to {}:{} is not allowed.'
.
format
(
self
.
body
[
'hostname'
],
self
.
sshserver_port
)
# noqa
self
.
assertEqual
(
message
,
data
[
'status'
])
self
.
assertEqual
(
message
,
data
[
'status'
])
class
TestAppWithTrustedStream
(
OtherTestBase
):
tdstream
=
'127.0.0.2'
def
test_with_forbidden_get_request
(
self
):
response
=
self
.
fetch
(
'/'
,
method
=
'GET'
)
self
.
assertEqual
(
response
.
code
,
403
)
self
.
assertIn
(
b
'403: Forbidden'
,
response
.
body
)
def
test_with_forbidden_post_request
(
self
):
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
urlencode
(
self
.
body
),
headers
=
self
.
headers
)
self
.
assertEqual
(
response
.
code
,
200
)
self
.
assertIn
(
b
'"status": "Forbidden"'
,
response
.
body
)
def
test_with_forbidden_put_request
(
self
):
response
=
self
.
fetch
(
'/'
,
method
=
'PUT'
,
body
=
urlencode
(
self
.
body
),
headers
=
self
.
headers
)
self
.
assertEqual
(
response
.
code
,
403
)
self
.
assertIn
(
b
'403: Forbidden'
,
response
.
body
)
class
TestAppNotFoundHandler
(
OtherTestBase
):
def
test_with_not_found_get_request
(
self
):
response
=
self
.
fetch
(
'/pathnotfound'
,
method
=
'GET'
)
self
.
assertEqual
(
response
.
code
,
404
)
self
.
assertEqual
(
response
.
headers
[
'Server'
],
'TornadoServer'
)
self
.
assertIn
(
b
'404: Not Found'
,
response
.
body
)
def
test_with_not_found_post_request
(
self
):
response
=
self
.
fetch
(
'/pathnotfound'
,
method
=
'POST'
,
body
=
urlencode
(
self
.
body
),
headers
=
self
.
headers
)
self
.
assertEqual
(
response
.
code
,
404
)
self
.
assertEqual
(
response
.
headers
[
'Server'
],
'TornadoServer'
)
self
.
assertIn
(
b
'404: Not Found'
,
response
.
body
)
def
test_with_not_found_put_request
(
self
):
response
=
self
.
fetch
(
'/pathnotfound'
,
method
=
'PUT'
,
body
=
urlencode
(
self
.
body
),
headers
=
self
.
headers
)
self
.
assertEqual
(
response
.
code
,
404
)
self
.
assertEqual
(
response
.
headers
[
'Server'
],
'TornadoServer'
)
self
.
assertIn
(
b
'404: Not Found'
,
response
.
body
)
webssh/handler.py
View file @
af60cd1c
...
@@ -54,7 +54,7 @@ class MixinHandler(object):
...
@@ -54,7 +54,7 @@ class MixinHandler(object):
lst
=
context
.
trusted_downstream
lst
=
context
.
trusted_downstream
if
lst
and
ip
not
in
lst
:
if
lst
and
ip
not
in
lst
:
logging
.
info
(
logging
.
warning
(
'IP {!r} not found in trusted downstream {!r}'
.
format
(
ip
,
lst
)
'IP {!r} not found in trusted downstream {!r}'
.
format
(
ip
,
lst
)
)
)
return
True
return
True
...
@@ -62,7 +62,7 @@ class MixinHandler(object):
...
@@ -62,7 +62,7 @@ class MixinHandler(object):
if
context
.
_orig_protocol
==
'http'
:
if
context
.
_orig_protocol
==
'http'
:
ipaddr
=
to_ip_address
(
ip
)
ipaddr
=
to_ip_address
(
ip
)
if
not
ipaddr
.
is_private
:
if
not
ipaddr
.
is_private
:
logging
.
info
(
'Public non-https request is forbidden.'
)
logging
.
warning
(
'Public non-https request is forbidden.'
)
return
True
return
True
def
set_default_headers
(
self
):
def
set_default_headers
(
self
):
...
...
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