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
e1fbc417
Commit
e1fbc417
authored
Aug 26, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test for bad authentication type
parent
105c1f62
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
sshserver.py
tests/sshserver.py
+3
-1
test_app.py
tests/test_app.py
+20
-4
No files found.
tests/sshserver.py
View file @
e1fbc417
...
...
@@ -72,11 +72,13 @@ class Server(paramiko.ServerInterface):
def
check_auth_publickey
(
self
,
username
,
key
):
print
(
'Auth attempt with username: {!r} & key: {!r}'
.
format
(
username
,
u
(
hexlify
(
key
.
get_fingerprint
()))))
# noqa
if
(
username
==
'robey'
)
and
(
key
==
self
.
good_pub_key
):
if
(
username
in
[
'robey'
,
'keyonly'
]
)
and
(
key
==
self
.
good_pub_key
):
return
paramiko
.
AUTH_SUCCESSFUL
return
paramiko
.
AUTH_FAILED
def
get_allowed_auths
(
self
,
username
):
if
username
==
'keyonly'
:
return
'publickey'
return
'password,publickey'
def
check_channel_exec_request
(
self
,
channel
,
command
):
...
...
tests/test_app.py
View file @
e1fbc417
...
...
@@ -28,14 +28,14 @@ class TestApp(AsyncHTTPTestCase):
running
=
[
True
]
sshserver_port
=
2200
body
=
'hostname=127.0.0.1&port={}&username=robey&password=foo'
.
format
(
sshserver_port
)
# noqa
body_dict
=
{
def
get_app
(
self
):
self
.
body_dict
=
{
'hostname'
:
'127.0.0.1'
,
'port'
:
str
(
sshserver_port
),
'port'
:
str
(
self
.
sshserver_port
),
'username'
:
'robey'
,
'password'
:
''
}
def
get_app
(
self
):
loop
=
self
.
io_loop
options
.
debug
=
False
options
.
policy
=
random
.
choice
([
'warning'
,
'autoadd'
])
...
...
@@ -449,3 +449,19 @@ class TestApp(AsyncHTTPTestCase):
yield
client
.
fetch
(
url
,
method
=
'POST'
,
body
=
body
)
self
.
assertEqual
(
ctx
.
exception
.
code
,
400
)
self
.
assertIn
(
'Bad Request'
,
ctx
.
exception
.
message
)
@tornado.testing.gen_test
def
test_app_with_user_keyonly_for_bad_authentication_type
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
self
.
body_dict
.
update
(
username
=
'keyonly'
,
password
=
'foo'
)
body
=
urlencode
(
self
.
body_dict
)
response
=
yield
client
.
fetch
(
url
,
method
=
'POST'
,
body
=
body
)
self
.
assertEqual
(
response
.
code
,
200
)
data
=
json
.
loads
(
to_str
(
response
.
body
))
self
.
assertIsNone
(
data
[
'id'
])
self
.
assertIsNone
(
data
[
'encoding'
])
self
.
assertIn
(
'Bad authentication type'
,
data
[
'status'
])
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