def test3_new_device_group_disconnect_invalid_id(self): id = str(uuid.uuid4()) msg = json.dumps({ "message_type": "new_device_group_request", "id": id, "group_name": "Group", "vendor": "BeeeOn", "devices": [{ "device_id": "123", "product_name": "Internal Pressure v1.0", "refresh_time": 30, "module_types": [{ "type": "pressure", "attributes": [{ "attribute": "inner" }] }] }] }) self.ws.send(msg) assureIsClosed(self, self.ws)
def test3_send_random_data_without_registration(self): ws = websocket.WebSocket() ws.connect(config.gws_ws_uri) ws.send("hello") assureIsClosed(self, ws) ws.close()
def test3_device_list_disconnect_bad_prefix(self): id = str(uuid.uuid4()) msg = json.dumps({ "message_type": "device_list_request", "id": id, "device_prefix": "Cool" }) self.ws.send(msg) assureIsClosed(self, self.ws)
def test2_register_fail_bad_id(self): ws = websocket.WebSocket() ws.connect(config.gws_ws_uri) msg = json.dumps({ "gateway_id": "123", "ip_address": "192.168.1.1", "message_type": "gateway_register", "version": "v1.0" }) ws.send(msg) assureIsClosed(self, ws)
def test3_notice_key_invalid(self): id = str(uuid.uuid4()) msg = json.dumps({ "id": id, "message_type": "notice_request", "at": 1546363722908213, "severity": "info", "key": "<script>alert('attack')</script>" }) self.ws.send(msg) assureIsClosed(self, self.ws)
def test6_notice_context_too_deep(self): id = str(uuid.uuid4()) msg = json.dumps({ "id": id, "message_type": "notice_request", "at": 1546363722908213, "severity": "info", "key": "some_message", "context": { "gateway": { "id": config.gateway_id } } }) self.ws.send(msg) assureIsClosed(self, self.ws)
def test4_register_success_repeatedly(self): ws0 = websocket.WebSocket() ws1 = websocket.WebSocket() msg = json.dumps({ "gateway_id": config.gateway_id, "ip_address": "192.168.1.1", "message_type": "gateway_register", "version": "v1.0" }) ws0.connect(config.gws_ws_uri) ws0.send(msg) response = json.loads(ws0.recv()) self.assertEqual("gateway_accepted", response["message_type"]) assureNotClosed(self, ws0) event = self.zmq.pop_data() self.assertEqual("on-connected", event["event"]) self.assertEqual(config.gateway_id, event["gateway_id"]) ws1.connect(config.gws_ws_uri) ws1.send(msg) response = json.loads(ws1.recv()) self.assertEqual("gateway_accepted", response["message_type"]) assureIsClosed(self, ws0) assureNotClosed(self, ws1) event = self.zmq.pop_data() self.assertEqual("on-reconnected", event["event"]) self.assertEqual(config.gateway_id, event["gateway_id"]) ws1.close() event = self.zmq.pop_data() self.assertEqual("on-disconnected", event["event"]) self.assertEqual(config.gateway_id, event["gateway_id"])
def test3_too_long_frame(self): self.ws.ping("X" * 1024) assureIsClosed(self, self.ws)
def test2_unhandled_data(self): self.ws.send("should close connection due to opcode", opcode=websocket.ABNF.OPCODE_CONT) assureIsClosed(self, self.ws)
def test1_unhandled_control(self): self.ws.pong("short but should close connection") assureIsClosed(self, self.ws)