コード例 #1
0
ファイル: test.py プロジェクト: jjason/sawtooth-core
    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)
コード例 #2
0
    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)
コード例 #3
0
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
コード例 #4
0
 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)
コード例 #5
0
ファイル: test.py プロジェクト: jjason/sawtooth-core
 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)