Example #1
0
    def test_authorization_trust_request_bad_last_message(self):
        """
        Test the AuthorizationTrustRequestHandler returns an
        AuthorizationViolation and closes the connection if the last message
        was not a ConnectionRequest.
        """
        auth_trust_request = AuthorizationTrustRequest(
            roles=[RoleType.Value("NETWORK")],
            public_key="public_key")

        roles = {"network": AuthorizationType.TRUST}

        network = MockNetwork(
            roles,
            connection_status={"connection_id":
                               "other"})
        permission_verifer = MockPermissionVerifier()
        gossip = MockGossip()
        handler = AuthorizationTrustRequestHandler(
            network, permission_verifer, gossip)
        handler_status = handler.handle(
            "connection_id",
            auth_trust_request.SerializeToString())
        self.assertEqual(handler_status.status, HandlerStatus.RETURN_AND_CLOSE)
        self.assertEqual(
            handler_status.message_type,
            validator_pb2.Message.AUTHORIZATION_VIOLATION)
Example #2
0
    def test_authorization_trust_request_not_permitted(self):
        """
        Test the AuthorizationTrustRequestHandler returns an
        AuthorizationViolation and closes the connection if the permission
        verifier does not permit the connections public key.
        """
        auth_trust_request = AuthorizationTrustRequest(
            roles=[RoleType.Value("NETWORK")],
            public_key="public_key")

        roles = {"network": AuthorizationType.TRUST}

        network = MockNetwork(
            roles,
            connection_status={"connection_id":
                               ConnectionStatus.CONNECTION_REQUEST})
        # say that connection is not permitted
        permission_verifer = MockPermissionVerifier(allow=False)
        gossip = MockGossip()

        handler = AuthorizationTrustRequestHandler(
            network, permission_verifer, gossip)

        handler_status = handler.handle(
            "connection_id",
            auth_trust_request.SerializeToString())

        self.assertEqual(handler_status.status, HandlerStatus.RETURN_AND_CLOSE)
        self.assertEqual(
            handler_status.message_type,
            validator_pb2.Message.AUTHORIZATION_VIOLATION)
Example #3
0
    def test_authorization_trust_request(self):
        """
        Test the AuthorizationTrustRequestHandler returns an
        AuthorizationTrustResponse if the AuthorizationTrustRequest should be
        approved.
        """
        auth_trust_request = AuthorizationTrustRequest(
            roles=[RoleType.Value("NETWORK")],
            public_key="public_key")

        roles = {"network": AuthorizationType.TRUST}

        network = MockNetwork(
            roles,
            connection_status={"connection_id":
                               ConnectionStatus.CONNECTION_REQUEST})
        permission_verifer = MockPermissionVerifier()
        gossip = MockGossip()
        handler = AuthorizationTrustRequestHandler(
            network, permission_verifer, gossip)
        handler_status = handler.handle(
            "connection_id",
            auth_trust_request.SerializeToString())
        self.assertEqual(handler_status.status, HandlerStatus.RETURN)
        self.assertEqual(
            handler_status.message_type,
            validator_pb2.Message.AUTHORIZATION_TRUST_RESPONSE)
Example #4
0
    def test_authorization_trust_request_not_permitted(self):
        """
        Test the AuthorizationTrustRequestHandler returns an
        AuthorizationViolation and closes the connection if the permission
        verifier does not permit the connections public key.
        """
        auth_trust_request = AuthorizationTrustRequest(
            roles=[RoleType.Value("NETWORK")], public_key="public_key")

        roles = {"network": AuthorizationType.TRUST}

        network = MockNetwork(roles,
                              connection_status={
                                  "connection_id":
                                  ConnectionStatus.CONNECTION_REQUEST
                              })
        # say that connection is not permitted
        permission_verifer = MockPermissionVerifier(allow=False)
        gossip = MockGossip()

        handler = AuthorizationTrustRequestHandler(network, permission_verifer,
                                                   gossip)

        handler_status = handler.handle("connection_id",
                                        auth_trust_request.SerializeToString())

        self.assertEqual(handler_status.status, HandlerStatus.RETURN_AND_CLOSE)
        self.assertEqual(handler_status.message_type,
                         validator_pb2.Message.AUTHORIZATION_VIOLATION)
Example #5
0
    def test_authorization_trust_request(self):
        """
        Test the AuthorizationTrustRequestHandler returns an
        AuthorizationTrustResponse if the AuthorizationTrustRequest should be
        approved.
        """
        auth_trust_request = AuthorizationTrustRequest(
            roles=[RoleType.Value("NETWORK")], public_key="public_key")

        roles = {"network": AuthorizationType.TRUST}

        network = MockNetwork(roles,
                              connection_status={
                                  "connection_id":
                                  ConnectionStatus.CONNECTION_REQUEST
                              })
        permission_verifer = MockPermissionVerifier()
        gossip = MockGossip()
        handler = AuthorizationTrustRequestHandler(network, permission_verifer,
                                                   gossip)
        handler_status = handler.handle("connection_id",
                                        auth_trust_request.SerializeToString())
        self.assertEqual(handler_status.status, HandlerStatus.RETURN)
        self.assertEqual(handler_status.message_type,
                         validator_pb2.Message.AUTHORIZATION_TRUST_RESPONSE)
Example #6
0
    def test_authorization_trust_request_bad_last_message(self):
        """
        Test the AuthorizationTrustRequestHandler returns an
        AuthorizationViolation and closes the connection if the last message
        was not a ConnectionRequest.
        """
        auth_trust_request = AuthorizationTrustRequest(
            roles=[RoleType.Value("NETWORK")],
            public_key="public_key")

        roles = {"network": AuthorizationType.TRUST}

        network = MockNetwork(
            roles,
            connection_status={"connection_id":
                               "other"})
        permission_verifer = MockPermissionVerifier()
        gossip = MockGossip()
        handler = AuthorizationTrustRequestHandler(
            network, permission_verifer, gossip)
        handler_status = handler.handle(
            "connection_id",
            auth_trust_request.SerializeToString())
        self.assertEqual(handler_status.status, HandlerStatus.RETURN_AND_CLOSE)
        self.assertEqual(
            handler_status.message_type,
            validator_pb2.Message.AUTHORIZATION_VIOLATION)
def do_authorization_trust_request():
    """
    Test the AuthorizationTrustRequestHandler returns an
    AuthorizationTrustResponse if the AuthorizationTrustRequest should be
    approved.
    """
    auth_trust_request = AuthorizationTrustRequest(
        roles=[RoleType.Value("NETWORK")], public_key="public_key")

    roles = {"network": AuthorizationType.TRUST}

    network = MockNetwork(roles,
                          connection_status={
                              "connection_id":
                              ConnectionStatus.CONNECTION_REQUEST
                          })
    permission_verifer = MockPermissionVerifier()
    gossip = MockGossip()
    handler = AuthorizationTrustRequestHandler(network, permission_verifer,
                                               gossip)
    handler_status = handler.handle("connection_id",
                                    auth_trust_request.SerializeToString())

    return handler_status