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
33014548
Commit
33014548
authored
Apr 27, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated test_app.py and sshserver.py
parent
de0a903d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
sshserver.py
tests/sshserver.py
+6
-2
test_app.py
tests/test_app.py
+21
-1
No files found.
tests/sshserver.py
View file @
33014548
...
@@ -55,7 +55,7 @@ class Server (paramiko.ServerInterface):
...
@@ -55,7 +55,7 @@ class Server (paramiko.ServerInterface):
return
paramiko
.
OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
return
paramiko
.
OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
def
check_auth_password
(
self
,
username
,
password
):
def
check_auth_password
(
self
,
username
,
password
):
if
(
username
==
'robey'
)
and
(
password
==
'foo'
):
if
(
username
in
[
'robey'
,
'bar'
]
)
and
(
password
==
'foo'
):
return
paramiko
.
AUTH_SUCCESSFUL
return
paramiko
.
AUTH_SUCCESSFUL
return
paramiko
.
AUTH_FAILED
return
paramiko
.
AUTH_FAILED
...
@@ -104,7 +104,8 @@ def run_ssh_server(port=2200, running=True):
...
@@ -104,7 +104,8 @@ def run_ssh_server(port=2200, running=True):
print
(
'*** No channel.'
)
print
(
'*** No channel.'
)
continue
continue
print
(
'Authenticated!'
)
username
=
t
.
get_username
()
print
(
'{} Authenticated!'
.
format
(
username
))
server
.
event
.
wait
(
10
)
server
.
event
.
wait
(
10
)
if
not
server
.
event
.
is_set
():
if
not
server
.
event
.
is_set
():
...
@@ -112,6 +113,9 @@ def run_ssh_server(port=2200, running=True):
...
@@ -112,6 +113,9 @@ def run_ssh_server(port=2200, running=True):
continue
continue
chan
.
send
(
'
\r\n\r\n
Welcome!
\r\n\r\n
'
)
chan
.
send
(
'
\r\n\r\n
Welcome!
\r\n\r\n
'
)
if
username
==
'bar'
:
print
(
chan
.
recv
(
1024
))
chan
.
close
()
try
:
try
:
sock
.
close
()
sock
.
close
()
...
...
tests/test_app.py
View file @
33014548
...
@@ -102,7 +102,7 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -102,7 +102,7 @@ class TestApp(AsyncHTTPTestCase):
ws
.
close
()
ws
.
close
()
@tornado.testing.gen_test
@tornado.testing.gen_test
def
test_app_with_correct_credentials_
welcome
(
self
):
def
test_app_with_correct_credentials_
user_robey
(
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
)
...
@@ -118,3 +118,23 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -118,3 +118,23 @@ class TestApp(AsyncHTTPTestCase):
msg
=
yield
ws
.
read_message
()
msg
=
yield
ws
.
read_message
()
self
.
assertIn
(
'Welcome!'
,
msg
)
self
.
assertIn
(
'Welcome!'
,
msg
)
ws
.
close
()
ws
.
close
()
@tornado.testing.gen_test
def
test_app_with_correct_credentials_user_bar
(
self
):
url
=
self
.
get_url
(
'/'
)
client
=
self
.
get_http_client
()
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
body
=
self
.
body
.
replace
(
'robey'
,
'bar'
)
response
=
yield
client
.
fetch
(
url
,
method
=
"POST"
,
body
=
body
)
worker_id
=
json
.
loads
(
response
.
body
.
decode
(
'utf-8'
))[
'id'
]
self
.
assertIsNotNone
(
worker_id
)
url
=
url
.
replace
(
'http'
,
'ws'
)
ws_url
=
url
+
'ws?id='
+
worker_id
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
msg
=
yield
ws
.
read_message
()
self
.
assertIn
(
'Welcome!'
,
msg
)
yield
ws
.
write_message
(
'bye'
)
ws
.
close
()
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