From 0a14901e94831513dad0e250fe995e951e698175 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 20 May 2016 11:08:10 -0700 Subject: [PATCH] full coverage of websocket --- src/wormhole/server/rendezvous_websocket.py | 2 +- src/wormhole/test/test_server.py | 25 ++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/wormhole/server/rendezvous_websocket.py b/src/wormhole/server/rendezvous_websocket.py index e37fb6b..b0fb10a 100644 --- a/src/wormhole/server/rendezvous_websocket.py +++ b/src/wormhole/server/rendezvous_websocket.py @@ -130,7 +130,7 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol): if mtype == "close": return self.handle_close(msg, server_rx) - raise Error("Unknown type") + raise Error("unknown type") except Error as e: self.send("error", error=e._explain, orig=msg) diff --git a/src/wormhole/test/test_server.py b/src/wormhole/test/test_server.py index 5627a1c..4bd1167 100644 --- a/src/wormhole/test/test_server.py +++ b/src/wormhole/test/test_server.py @@ -349,6 +349,10 @@ class WSClient(websocket.WebSocketClientProtocol): payload = json.dumps(kwargs).encode("utf-8") self.sendMessage(payload, False) + def send_notype(self, **kwargs): + payload = json.dumps(kwargs).encode("utf-8") + self.sendMessage(payload, False) + @inlineCallbacks def sync(self): ping = next(self.ping_counter) @@ -486,6 +490,21 @@ class WebSocketAPI(ServerBase, unittest.TestCase): self.assertEqual(err[u"type"], u"error") self.assertEqual(err[u"error"], u"already bound") + c1.send_notype(other="misc") # missing 'type' + err = yield c1.next_non_ack() + self.assertEqual(err[u"type"], u"error") + self.assertEqual(err[u"error"], u"missing 'type'") + + c1.send("___unknown") # unknown type + err = yield c1.next_non_ack() + self.assertEqual(err[u"type"], u"error") + self.assertEqual(err[u"error"], u"unknown type") + + c1.send("ping") # missing 'ping' + err = yield c1.next_non_ack() + self.assertEqual(err[u"type"], u"error") + self.assertEqual(err[u"error"], u"ping requires 'ping'") + @inlineCallbacks def test_list(self): c1 = yield self.make_client() @@ -704,12 +723,8 @@ class WebSocketAPI(ServerBase, unittest.TestCase): m = yield c1.next_non_ack() self.assertEqual(m[u"type"], u"closed") - return - print("doing last close") - c1.send(u"close", mood=u"mood") # already closed # XXX not getting through - print("did last close") + c1.send(u"close", mood=u"mood") # already closed err = yield c1.next_non_ack() - print("done") self.assertEqual(err[u"type"], u"error") self.assertEqual(err[u"error"], u"must open mailbox before closing")