예제 #1
0
 def test_init_with_args(self):
     """
     Test that a QueryResponsePayload object can be constructed with valid
     values.
     """
     query.QueryResponsePayload(
         operations=self.operations,
         object_types=self.object_types,
         vendor_identification=self.vendor_identification,
         server_information=self.server_information,
         application_namespaces=self.application_namespaces,
         extension_information=self.extension_information)
예제 #2
0
파일: engine.py 프로젝트: luis-allan/PyKMIP
    def _process_query(self, payload):
        self._logger.info("Processing operation: Query")

        queries = [x.value for x in payload.query_functions]

        operations = list()
        objects = list()
        vendor_identification = None
        server_information = None
        namespaces = list()
        extensions = list()

        if enums.QueryFunction.QUERY_OPERATIONS in queries:
            operations = list([
                contents.Operation(enums.Operation.CREATE),
                contents.Operation(enums.Operation.CREATE_KEY_PAIR),
                contents.Operation(enums.Operation.REGISTER),
                contents.Operation(enums.Operation.GET),
                contents.Operation(enums.Operation.DESTROY),
                contents.Operation(enums.Operation.QUERY)
            ])

            if self._protocol_version == contents.ProtocolVersion.create(1, 1):
                operations.extend([
                    contents.Operation(enums.Operation.DISCOVER_VERSIONS)
                ])

        if enums.QueryFunction.QUERY_OBJECTS in queries:
            objects = list()
        if enums.QueryFunction.QUERY_SERVER_INFORMATION in queries:
            vendor_identification = misc.VendorIdentification(
                "PyKMIP {0} Software Server".format(kmip.__version__)
            )
            server_information = None
        if enums.QueryFunction.QUERY_APPLICATION_NAMESPACES in queries:
            namespaces = list()
        if enums.QueryFunction.QUERY_EXTENSION_LIST in queries:
            extensions = list()
        if enums.QueryFunction.QUERY_EXTENSION_MAP in queries:
            extensions = list()

        response_payload = query.QueryResponsePayload(
            operations=operations,
            object_types=objects,
            vendor_identification=vendor_identification,
            server_information=server_information,
            application_namespaces=namespaces,
            extension_information=extensions
        )

        return response_payload
예제 #3
0
    def _test_write(self, encoding, operations, object_types,
                    vendor_identification, server_information,
                    application_namespaces, extension_information):
        stream = utils.BytearrayStream()
        payload = query.QueryResponsePayload(operations, object_types,
                                             vendor_identification,
                                             server_information,
                                             application_namespaces,
                                             extension_information)
        payload.write(stream)

        length_expected = len(encoding)
        length_received = len(stream)

        msg = "encoding lengths not equal"
        msg += "; expected {0}, received {1}".format(length_expected,
                                                     length_received)
        self.assertEqual(length_expected, length_received, msg)

        msg = "encoding mismatch"
        msg += ";\nexpected:\n{0}\nreceived:\n{1}".format(encoding, stream)

        self.assertEqual(encoding, stream, msg)
예제 #4
0
 def _create_query_payload(self):
     return query.QueryResponsePayload()
예제 #5
0
    def _test_read(self, stream, operations, object_types,
                   vendor_identification, server_information,
                   application_namespaces, extension_information):
        payload = query.QueryResponsePayload()
        payload.read(stream)

        # Test decoding of all operations.
        expected = len(operations)
        observed = len(payload.operations)

        msg = "operations list decoding mismatch"
        msg += "; expected {0} results, received {1}".format(
            expected, observed)
        self.assertEqual(expected, observed, msg)

        for i in xrange(len(operations)):
            expected = operations[i]
            observed = payload.operations[i]

            msg = "operation decoding mismatch"
            msg += "; expected {0}, received {1}".format(expected, observed)
            self.assertEqual(expected, observed, msg)

        # Test decoding of all object types.
        expected = len(object_types)
        observed = len(payload.object_types)

        msg = "object types list decoding mismatch"
        msg += "; expected {0} results, received {1}".format(
            expected, observed)
        self.assertEqual(expected, observed, msg)

        for i in xrange(len(object_types)):
            expected = object_types[i]
            observed = payload.object_types[i]

            msg = "object type decoding mismatch"
            msg += "; expected {0}, received {1}".format(expected, observed)
            self.assertEqual(expected, observed, msg)

        # Test decoding of vendor identification.
        expected = vendor_identification
        observed = payload.vendor_identification

        msg = "vendor identification decoding mismatch"
        msg += "; expected {0}, received {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        # Test decoding of server information.
        expected = server_information
        observed = payload.server_information

        msg = "server information decoding mismatch"
        msg += "; expected {0}, received {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        # Test decoding of all application namespaces.
        expected = len(application_namespaces)
        observed = len(payload.application_namespaces)

        msg = "application namespaces list decoding mismatch"
        msg += "; expected {0} results, received {1}".format(
            expected, observed)
        self.assertEqual(expected, observed, msg)

        # Test decoding of all extension information.
        expected = len(extension_information)
        observed = len(payload.extension_information)

        msg = "extension information list decoding mismatch"
        msg += "; expected {0} results, received {1}".format(
            expected, observed)
        self.assertEqual(expected, observed, msg)

        for i in xrange(len(extension_information)):
            expected = extension_information[i]
            observed = payload.extension_information[i]

            msg = "extension information decoding mismatch"
            msg += "; expected {0}, received {1}".format(expected, observed)
            self.assertEqual(expected, observed, msg)
예제 #6
0
 def test_init_with_none(self):
     """
     Test that a QueryResponsePayload object can be constructed with no
     specified value.
     """
     query.QueryResponsePayload()