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
de0a903d
Commit
de0a903d
authored
Apr 27, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated test_app.py and sshserver.py
parent
e88ecb28
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
15 deletions
+16
-15
sshserver.py
tests/sshserver.py
+2
-2
test_app.py
tests/test_app.py
+14
-13
No files found.
tests/sshserver.py
View file @
de0a903d
...
@@ -77,11 +77,11 @@ class Server (paramiko.ServerInterface):
...
@@ -77,11 +77,11 @@ class Server (paramiko.ServerInterface):
return
True
return
True
def
run_ssh_server
(
running
=
True
):
def
run_ssh_server
(
port
=
2200
,
running
=
True
):
# now connect
# now connect
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
sock
.
bind
((
'127.0.0.1'
,
2200
))
sock
.
bind
((
'127.0.0.1'
,
port
))
sock
.
listen
(
100
)
sock
.
listen
(
100
)
while
running
:
while
running
:
...
...
tests/test_app.py
View file @
de0a903d
...
@@ -18,6 +18,8 @@ handler.DELAY = 0.1
...
@@ -18,6 +18,8 @@ handler.DELAY = 0.1
class
TestApp
(
AsyncHTTPTestCase
):
class
TestApp
(
AsyncHTTPTestCase
):
_is_running
=
False
_is_running
=
False
sshserver_port
=
2200
body
=
u'hostname=127.0.0.1&port={}&username=robey&password=foo'
.
format
(
sshserver_port
)
# noqa
def
get_app
(
self
):
def
get_app
(
self
):
loop
=
self
.
io_loop
loop
=
self
.
io_loop
...
@@ -29,6 +31,14 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -29,6 +31,14 @@ class TestApp(AsyncHTTPTestCase):
return
app
return
app
@classmethod
@classmethod
def
setUpClass
(
cls
):
t
=
threading
.
Thread
(
target
=
run_ssh_server
,
args
=
(
cls
.
sshserver_port
,
cls
)
)
t
.
setDaemon
(
True
)
t
.
start
()
@classmethod
def
tearDownClass
(
cls
):
def
tearDownClass
(
cls
):
cls
.
_is_running
=
True
cls
.
_is_running
=
True
...
@@ -62,15 +72,13 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -62,15 +72,13 @@ class TestApp(AsyncHTTPTestCase):
def
test_app_with_wrong_credentials
(
self
):
def
test_app_with_wrong_credentials
(
self
):
response
=
self
.
fetch
(
'/'
)
response
=
self
.
fetch
(
'/'
)
self
.
assertEqual
(
response
.
code
,
200
)
self
.
assertEqual
(
response
.
code
,
200
)
body
=
u'hostname=127.0.0.1&port=2200&username=robey&password=foos'
response
=
self
.
fetch
(
'/'
,
method
=
"POST"
,
body
=
self
.
body
+
u's'
)
response
=
self
.
fetch
(
'/'
,
method
=
"POST"
,
body
=
body
)
self
.
assertIn
(
b
'Authentication failed.'
,
response
.
body
)
self
.
assertIn
(
b
'Authentication failed.'
,
response
.
body
)
def
test_app_with_correct_credentials
(
self
):
def
test_app_with_correct_credentials
(
self
):
response
=
self
.
fetch
(
'/'
)
response
=
self
.
fetch
(
'/'
)
self
.
assertEqual
(
response
.
code
,
200
)
self
.
assertEqual
(
response
.
code
,
200
)
body
=
u'hostname=127.0.0.1&port=2200&username=robey&password=foo'
response
=
self
.
fetch
(
'/'
,
method
=
"POST"
,
body
=
self
.
body
)
response
=
self
.
fetch
(
'/'
,
method
=
"POST"
,
body
=
body
)
worker_id
=
json
.
loads
(
response
.
body
.
decode
(
'utf-8'
))[
'id'
]
worker_id
=
json
.
loads
(
response
.
body
.
decode
(
'utf-8'
))[
'id'
]
self
.
assertIsNotNone
(
worker_id
)
self
.
assertIsNotNone
(
worker_id
)
...
@@ -81,8 +89,7 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -81,8 +89,7 @@ class TestApp(AsyncHTTPTestCase):
response
=
yield
client
.
fetch
(
url
)
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
self
.
assertEqual
(
response
.
code
,
200
)
body
=
u'hostname=127.0.0.1&port=2200&username=robey&password=foo'
response
=
yield
client
.
fetch
(
url
,
method
=
"POST"
,
body
=
self
.
body
)
response
=
yield
client
.
fetch
(
url
,
method
=
"POST"
,
body
=
body
)
worker_id
=
json
.
loads
(
response
.
body
.
decode
(
'utf-8'
))[
'id'
]
worker_id
=
json
.
loads
(
response
.
body
.
decode
(
'utf-8'
))[
'id'
]
self
.
assertIsNotNone
(
worker_id
)
self
.
assertIsNotNone
(
worker_id
)
...
@@ -101,8 +108,7 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -101,8 +108,7 @@ class TestApp(AsyncHTTPTestCase):
response
=
yield
client
.
fetch
(
url
)
response
=
yield
client
.
fetch
(
url
)
self
.
assertEqual
(
response
.
code
,
200
)
self
.
assertEqual
(
response
.
code
,
200
)
body
=
u'hostname=127.0.0.1&port=2200&username=robey&password=foo'
response
=
yield
client
.
fetch
(
url
,
method
=
"POST"
,
body
=
self
.
body
)
response
=
yield
client
.
fetch
(
url
,
method
=
"POST"
,
body
=
body
)
worker_id
=
json
.
loads
(
response
.
body
.
decode
(
'utf-8'
))[
'id'
]
worker_id
=
json
.
loads
(
response
.
body
.
decode
(
'utf-8'
))[
'id'
]
self
.
assertIsNotNone
(
worker_id
)
self
.
assertIsNotNone
(
worker_id
)
...
@@ -112,8 +118,3 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -112,8 +118,3 @@ 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
()
t
=
threading
.
Thread
(
target
=
run_ssh_server
,
args
=
(
TestApp
,))
t
.
setDaemon
(
True
)
t
.
start
()
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