def socket_to_ws(self, data, **kwargs): try: self.logger.info("[<--] To WebSocket endpoint\n{}".format( hex_dump(data))) except Exception as e: #Ignore errors... DumpFilter should not interpose the protocol flow sys.stderr.write("Unable to log filter dump: %s" % str(e)) return data
def test_hex_dump_unicode(self): """ Tests the hex dump function with unicode strings """ size = 16 data = u"Hello World" result = "0000 48 65 6c 6c 6f 20 57 6f 72 6c 64 Hello.Wo rld" self.assertEqual(hex_dump(data, size), result)
def test_hex_dump_binary_data(self): """ Tests the hex dump function passing binary data """ size = 16 data = b"\xff\xfd\x18\xff\xfd\x1f\xff\xfd#\xff\xfd'\xff\xfd$" result = "0000 ff fd 18 ff fd 1f ff fd 23 ff fd 27 ff fd 24 ........ #..'..$" self.assertEqual(hex_dump(data, size), result)
def test_server_dump_filter(self): """ Test the installing of a dump filter into server endpoint """ with NamedTemporaryFile(delete=DELETE_TMPFILE) as logf: server_filter = DumpFilter(handler={"filename": logf.name}) self.srv_tun.install_filter(server_filter) self.client.send_message(self.message, self.on_response_received) self.wait(timeout=ASYNC_TIMEOUT) content = logf.read() for line in hex_dump(self.message).splitlines(): self.assertIn(line, content.decode("utf-8")) self.srv_tun.uninstall_filter(server_filter)