def test_ping_rate_limiting(self): """ Test the PingHandler allows a ping from a connection who has not finished authorization and returns a PingResponse. Also test that if that connection sends another ping in a short time period, the connection is deemed malicious, an AuthorizationViolation is returned, and the connection is closed. """ ping = PingRequest() network = MockNetwork({}, connection_status={"connection_id": None}) handler = PingHandler(network) handler_status = handler.handle("connection_id", ping.SerializeToString()) self.assertEqual(handler_status.status, HandlerStatus.RETURN) self.assertEqual( handler_status.message_type, validator_pb2.Message.PING_RESPONSE) handler_status = handler.handle("connection_id", ping.SerializeToString()) self.assertEqual(handler_status.status, HandlerStatus.RETURN_AND_CLOSE) self.assertEqual( handler_status.message_type, validator_pb2.Message.AUTHORIZATION_VIOLATION)
def test_ping_handler(self): """ Test the PingHandler allows a ping from a connection who has not finished authorization and returns a NetworkAck. Also test that if that connection sends another ping in a short time period, the connection is deemed malicious, an AuthorizationViolation is returned, and the connection is closed. """ ping = PingRequest() network = MockNetwork({}, connection_status={"connection_id": None}) handler = PingHandler(network) handler_status = handler.handle("connection_id", ping.SerializeToString()) self.assertEqual(handler_status.status, HandlerStatus.RETURN) self.assertEqual( handler_status.message_type, validator_pb2.Message.PING_RESPONSE) handler_status = handler.handle("connection_id", ping.SerializeToString()) self.assertEqual(handler_status.status, HandlerStatus.RETURN_AND_CLOSE) self.assertEqual( handler_status.message_type, validator_pb2.Message.AUTHORIZATION_VIOLATION)
def do_ping_handler(): """ Test the PingHandler returns a NetworkAck if the connection has has finished authorization. """ ping = PingRequest() network = MockNetwork( {}, connection_status={"connection_id": ConnectionStatus.CONNECTED}) handler = PingHandler(network) handler_status = handler.handle("connection_id", ping.SerializeToString()) return handler_status
def test_ping_handler(self): """ Test the PingHandler returns a NetworkAck if the connection has has finished authorization. """ ping = PingRequest() network = MockNetwork( {}, connection_status={"connection_id": ConnectionStatus.CONNECTED}) handler = PingHandler(network) handler_status = handler.handle("connection_id", ping.SerializeToString()) self.assertEqual(handler_status.status, HandlerStatus.RETURN) self.assertEqual(handler_status.message_type, validator_pb2.Message.PING_RESPONSE)
def test_ping_handler(self): """ Test the PingHandler returns a NetworkAck if the connection has has finished authorization. """ ping = PingRequest() network = MockNetwork( {}, connection_status={ "connection_id": ConnectionStatus.CONNECTED }) handler = PingHandler(network) handler_status = handler.handle("connection_id", ping.SerializeToString()) self.assertEqual(handler_status.status, HandlerStatus.RETURN) self.assertEqual( handler_status.message_type, validator_pb2.Message.PING_RESPONSE)