コード例 #1
0
    def handle(self, connection_id, message_content):
        response_proto = client_batch_submit_pb2.ClientBatchSubmitResponse

        def make_response(out_status):
            return HandlerResult(
                status=HandlerStatus.RETURN,
                message_out=response_proto(status=out_status),
                message_type=Message.CLIENT_BATCH_SUBMIT_RESPONSE)

        try:
            request = client_batch_submit_pb2.ClientBatchSubmitRequest()
            request.ParseFromString(message_content)
            for batch in request.batches:
                if batch.trace:
                    LOGGER.debug("TRACE %s: %s", batch.header_signature,
                                 self.__class__.__name__)
            if not all(
                    self._verifier.check_off_chain_batch_roles(batch)
                    for batch in request.batches):
                return make_response(response_proto.INVALID_BATCH)

            if not all(
                    self._verifier.is_batch_signer_authorized(batch)
                    for batch in request.batches):
                return make_response(response_proto.INVALID_BATCH)

        except DecodeError:
            return make_response(response_proto.INTERNAL_ERROR)

        return HandlerResult(status=HandlerStatus.PASS)
コード例 #2
0
    def test_batch_submit_without_wait(self):
        """Verifies finisher simply returns OK when not set to wait.

        Expects to find:
            - a response status of OK
            - no batch_statuses
        """
        response = self._handle(
            client_batch_submit_pb2.ClientBatchSubmitRequest(
                batches=[make_mock_batch('new')]))

        self.assertEqual(self.status.OK, response.status)
コード例 #3
0
def client_batch_submit_request_preprocessor(message_content_bytes):
    request = client_batch_submit_pb2.ClientBatchSubmitRequest()

    try:
        request.ParseFromString(message_content_bytes)
    except DecodeError:
        LOGGER.error('ClientBatchSubmitRequest failed to deserialize')

        return PreprocessorResult(
            status=HandlerStatus.RETURN,
            message_out=ClientBatchSubmitResponse(
                status=ClientBatchSubmitResponse.INTERNAL_ERROR),
            message_type=validator_pb2.Message.CLIENT_BATCH_SUBMIT_RESPONSE)

    return PreprocessorResult(content=request)
コード例 #4
0
    def test_batch_submit_bad_request(self):
        """Verifies preprocessor breaks properly when sent a bad request.

        Expects to find:
            - a response status of INTERNAL_ERROR
        """

        request = client_batch_submit_pb2.ClientBatchSubmitRequest(
            batches=[make_mock_batch('new')]).SerializeToString()[0:-1]

        result = handlers.client_batch_submit_request_preprocessor(request)

        self.assertEqual(
            client_batch_submit_pb2.ClientBatchSubmitResponse.INTERNAL_ERROR,
            result.message_out.status)
コード例 #5
0
 def batch_submit():
     setUp()
     batch_submit = client_batch_submit_pb2.ClientBatchSubmitRequest(
         batches=[make_mock_batch('new')])
     return clientHanlerTestCase._handle(batch_submit)