Made WsockHandler more robust

This commit is contained in:
Sheng
2018-05-26 15:51:53 +08:00
parent 2c36c38653
commit a893507946
3 changed files with 35 additions and 4 deletions
+2 -1
View File
@@ -114,7 +114,8 @@ def run_ssh_server(port=2200, running=True):
chan.send('\r\n\r\nWelcome!\r\n\r\n')
if username == 'bar':
print(chan.recv(1024))
msg = chan.recv(1024)
chan.send(msg)
chan.close()
t.close()
+18
View File
@@ -136,5 +136,23 @@ class TestApp(AsyncHTTPTestCase):
ws = yield tornado.websocket.websocket_connect(ws_url)
msg = yield ws.read_message()
self.assertIn(b'Welcome!', msg)
# message will be ignored silently
yield ws.write_message('hello')
yield ws.write_message('"hello"')
yield ws.write_message('[hello]')
yield ws.write_message(json.dumps({'resize': []}))
yield ws.write_message(json.dumps({'resize': {}}))
yield ws.write_message(json.dumps({'resize': [100]}))
yield ws.write_message(json.dumps({'resize': [100]*10}))
yield ws.write_message(json.dumps({'resize': [-1, -1]}))
yield ws.write_message(json.dumps({'data': [1]}))
yield ws.write_message(json.dumps({'data': (1,)}))
yield ws.write_message(json.dumps({'data': {'a': 2}}))
yield ws.write_message(json.dumps({'data': 1}))
yield ws.write_message(json.dumps({'data': 2.1}))
yield ws.write_message(json.dumps({'key-non-existed': 'hello'}))
yield ws.write_message(json.dumps({'resize': [79, 23], 'data': 'bye'}))
msg = yield ws.read_message()
self.assertEqual(b'bye', msg)
ws.close()