def _test_read(self, stream, extension_name, extension_tag,
                   extension_type):
        extension_information = ExtensionInformation()
        extension_information.read(stream)

        if extension_name is None:
            extension_name = ExtensionName()

        msg = "extension name encoding mismatch"
        msg += "; expected {0}, observed {1}".format(
            extension_name,
            extension_information.extension_name)
        self.assertEqual(
            extension_name,
            extension_information.extension_name, msg)

        msg = "extension tag encoding mismatch"
        msg += "; expected {0}, observed {1}".format(
            extension_tag,
            extension_information.extension_tag)
        self.assertEqual(
            extension_tag,
            extension_information.extension_tag, msg)

        msg = "extension type encoding mismatch"
        msg += "; expected {0}, observed {1}".format(
            extension_type,
            extension_information.extension_type)
        self.assertEqual(
            extension_type,
            extension_information.extension_type, msg)
    def _test_read(self, stream, extension_name, extension_tag,
                   extension_type):
        extension_information = ExtensionInformation()
        extension_information.read(stream)

        if extension_name is None:
            extension_name = ExtensionName()

        msg = "extension name encoding mismatch"
        msg += "; expected {0}, observed {1}".format(
            extension_name, extension_information.extension_name)
        self.assertEqual(extension_name, extension_information.extension_name,
                         msg)

        msg = "extension tag encoding mismatch"
        msg += "; expected {0}, observed {1}".format(
            extension_tag, extension_information.extension_tag)
        self.assertEqual(extension_tag, extension_information.extension_tag,
                         msg)

        msg = "extension type encoding mismatch"
        msg += "; expected {0}, observed {1}".format(
            extension_type, extension_information.extension_type)
        self.assertEqual(extension_type, extension_information.extension_type,
                         msg)
    def test_not_equal_on_equal_and_empty(self):
        """
        Test that the inequality operator returns False when comparing two
        ExtensionInformation objects with no internal data.
        """
        a = ExtensionInformation()
        b = ExtensionInformation()

        self.assertFalse(a != b)
        self.assertFalse(b != a)
    def test_equal_on_equal_and_empty(self):
        """
        Test that the equality operator returns True when comparing two
        ExtensionInformation objects with no internal data.
        """
        a = ExtensionInformation()
        b = ExtensionInformation()

        self.assertTrue(a == b)
        self.assertTrue(b == a)
    def test_not_equal_on_not_equal(self):
        """
        Test that the inequality operator returns True when comparing two
        ExtensionInformation objects with the different sets of internal data.
        """
        a = ExtensionInformation(extension_name=self.extension_name_c,
                                 extension_tag=self.extension_tag_c,
                                 extension_type=self.extension_type_c)
        b = ExtensionInformation()

        self.assertTrue(a != b)
        self.assertTrue(b != a)
    def test_equal_on_equal(self):
        """
        Test that the equality operator returns True when comparing two
        ExtensionInformation objects with the same internal data.
        """
        a = ExtensionInformation(extension_name=self.extension_name_c,
                                 extension_tag=self.extension_tag_c,
                                 extension_type=self.extension_type_c)
        b = ExtensionInformation(extension_name=self.extension_name_c,
                                 extension_tag=self.extension_tag_c,
                                 extension_type=self.extension_type_c)

        self.assertTrue(a == b)
        self.assertTrue(b == a)
    def _test_create(self, extension_name, extension_tag, extension_type):
        extension_information = ExtensionInformation.create(
            extension_name=extension_name,
            extension_tag=extension_tag,
            extension_type=extension_type)

        self.assertIsInstance(extension_information, ExtensionInformation)

        expected = ExtensionName(extension_name)
        observed = extension_information.extension_name

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        expected = ExtensionTag(extension_tag)
        observed = extension_information.extension_tag

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        expected = ExtensionType(extension_type)
        observed = extension_information.extension_type

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
    def _test_create(self, extension_name, extension_tag, extension_type):
        extension_information = ExtensionInformation.create(
            extension_name=extension_name,
            extension_tag=extension_tag,
            extension_type=extension_type)

        self.assertIsInstance(extension_information, ExtensionInformation)

        expected = ExtensionName(extension_name)
        observed = extension_information.extension_name

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        expected = ExtensionTag(extension_tag)
        observed = extension_information.extension_tag

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        expected = ExtensionType(extension_type)
        observed = extension_information.extension_type

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
    def test_repr_with_data(self):
        """
        Test that the representation of an ExtensionInformation object with
        data is formatted properly and can be used by eval to create a new
        ExtensionInformation object identical to the original.
        """
        extension_information = ExtensionInformation(
            extension_name=ExtensionName('ACME LOCATION'),
            extension_tag=ExtensionTag(5548545),
            extension_type=ExtensionType(7))

        expected = "ExtensionInformation("
        expected += "extension_name=ExtensionName(value='ACME LOCATION'), "
        expected += "extension_tag=ExtensionTag(value=5548545), "
        expected += "extension_type=ExtensionType(value=7))"
        observed = repr(extension_information)

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        expected = extension_information
        observed = eval(repr(extension_information))

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
Esempio n. 10
0
    def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the QueryResponsePayload object and decode it
        into its constituent parts.

        Args:
            istream (Stream): A data stream containing encoded object data,
                supporting a read method; usually a BytearrayStream object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 1.0.
        """
        super(QueryResponsePayload, self).read(istream,
                                               kmip_version=kmip_version)
        tstream = BytearrayStream(istream.read(self.length))

        while (self.is_tag_next(enums.Tags.OPERATION, tstream)):
            operation = Operation()
            operation.read(tstream, kmip_version=kmip_version)
            self.operations.append(operation)

        while (self.is_tag_next(enums.Tags.OBJECT_TYPE, tstream)):
            object_type = ObjectType()
            object_type.read(tstream, kmip_version=kmip_version)
            self.object_types.append(object_type)

        if self.is_tag_next(enums.Tags.VENDOR_IDENTIFICATION, tstream):
            self.vendor_identification = VendorIdentification()
            self.vendor_identification.read(tstream, kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.SERVER_INFORMATION, tstream):
            self.server_information = ServerInformation()
            self.server_information.read(tstream, kmip_version=kmip_version)

        while (self.is_tag_next(enums.Tags.APPLICATION_NAMESPACE, tstream)):
            application_namespace = ApplicationNamespace()
            application_namespace.read(tstream, kmip_version=kmip_version)
            self.application_namespaces.append(application_namespace)

        while (self.is_tag_next(enums.Tags.EXTENSION_INFORMATION, tstream)):
            extension_information = ExtensionInformation()
            extension_information.read(tstream, kmip_version=kmip_version)
            self.extension_information.append(extension_information)

        self.is_oversized(tstream)
        self.validate()
Esempio n. 11
0
    def read(self, istream):
        """
        Read the data encoding the QueryResponsePayload object and decode it
        into its constituent parts.

        Args:
            istream (Stream): A data stream containing encoded object data,
                supporting a read method; usually a BytearrayStream object.
        """
        super(QueryResponsePayload, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        while(self.is_tag_next(Tags.OPERATION, tstream)):
            operation = Operation()
            operation.read(tstream)
            self.operations.append(operation)

        while(self.is_tag_next(Tags.OBJECT_TYPE, tstream)):
            object_type = ObjectType()
            object_type.read(tstream)
            self.object_types.append(object_type)

        if self.is_tag_next(Tags.VENDOR_IDENTIFICATION, tstream):
            self.vendor_identification = VendorIdentification()
            self.vendor_identification.read(tstream)

        if self.is_tag_next(Tags.SERVER_INFORMATION, tstream):
            self.server_information = ServerInformation()
            self.server_information.read(tstream)

        while(self.is_tag_next(Tags.APPLICATION_NAMESPACE, tstream)):
            application_namespace = ApplicationNamespace()
            application_namespace.read(tstream)
            self.application_namespaces.append(application_namespace)

        while(self.is_tag_next(Tags.EXTENSION_INFORMATION, tstream)):
            extension_information = ExtensionInformation()
            extension_information.read(tstream)
            self.extension_information.append(extension_information)

        self.is_oversized(tstream)
        self.validate()
Esempio n. 12
0
    def _test_write(self, stream_expected, extension_name, extension_tag,
                    extension_type):
        stream_observed = BytearrayStream()
        extension_information = ExtensionInformation(
            extension_name=extension_name,
            extension_tag=extension_tag,
            extension_type=extension_type)
        extension_information.write(stream_observed)

        length_expected = len(stream_expected)
        length_observed = len(stream_observed)

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

        msg = "encoding mismatch"
        msg += ";\nexpected:\n{0}\nobserved:\n{1}".format(
            stream_expected, stream_observed)
        self.assertEqual(stream_expected, stream_observed, msg)
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the inequality operator returns True when comparing an
        ExtensionInformation object with a non-ExtensionInformation object.
        """
        a = ExtensionInformation(extension_name=self.extension_name_c,
                                 extension_tag=self.extension_tag_c,
                                 extension_type=self.extension_type_c)
        b = "invalid"

        self.assertTrue(a != b)
        self.assertTrue(b != a)
    def _test_write(self, stream_expected, extension_name, extension_tag,
                    extension_type):
        stream_observed = BytearrayStream()
        extension_information = ExtensionInformation(
            extension_name=extension_name,
            extension_tag=extension_tag,
            extension_type=extension_type)
        extension_information.write(stream_observed)

        length_expected = len(stream_expected)
        length_observed = len(stream_observed)

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

        msg = "encoding mismatch"
        msg += ";\nexpected:\n{0}\nobserved:\n{1}".format(
            stream_expected, stream_observed)
        self.assertEqual(stream_expected, stream_observed, msg)
    def test_str_with_no_data(self):
        """
        Test that the string representation of an ExtensionInformation object
        is formatted properly when there is no internal data.
        """
        extension_information = ExtensionInformation()

        expected = "ExtensionInformation("
        expected += "extension_name=ExtensionName(value=''), "
        expected += "extension_tag=None, "
        expected += "extension_type=None)"
        observed = str(extension_information)

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
    def test_str_with_data(self):
        """
        Test that the string representation of an ExtensionInformation object
        is formatted properly when there is internal data.
        """
        extension_information = ExtensionInformation(
            extension_name=ExtensionName('ACME LOCATION'),
            extension_tag=ExtensionTag(5548545),
            extension_type=ExtensionType(7))

        expected = "ExtensionInformation("
        expected += "extension_name=ExtensionName(value='ACME LOCATION'), "
        expected += "extension_tag=ExtensionTag(value=5548545), "
        expected += "extension_type=ExtensionType(value=7))"
        observed = str(extension_information)

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
    def test_repr_with_no_data(self):
        """
        Test that the representation of an ExtensionInformation object with no
        data is formatted properly and can be used by eval to create a new
        ExtensionInformation object identical to the original.
        """
        extension_information = ExtensionInformation()

        expected = "ExtensionInformation("
        expected += "extension_name=ExtensionName(value=''), "
        expected += "extension_tag=None, "
        expected += "extension_type=None)"
        observed = repr(extension_information)

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        expected = extension_information
        observed = eval(repr(extension_information))

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
 def test_init_with_args(self):
     ExtensionInformation(extension_name=ExtensionName(),
                          extension_tag=ExtensionTag(),
                          extension_type=ExtensionType())
 def test_init_with_none(self):
     ExtensionInformation()
Esempio n. 20
0
    def setUp(self):
        super(TestQueryResponsePayload, self).setUp()

        self.operations = list()
        self.object_types = list()
        self.application_namespaces = list()
        self.extension_information = list()

        self.vendor_identification = VendorIdentification(
            "IBM test server, not-TKLM 2.0.1.1 KMIP 2.0.0.1")
        self.server_information = ServerInformation()

        self.operations.append(Operation(OperationEnum.CREATE))
        self.operations.append(Operation(OperationEnum.CREATE_KEY_PAIR))
        self.operations.append(Operation(OperationEnum.REGISTER))
        self.operations.append(Operation(OperationEnum.REKEY))
        self.operations.append(Operation(OperationEnum.CERTIFY))
        self.operations.append(Operation(OperationEnum.RECERTIFY))
        self.operations.append(Operation(OperationEnum.LOCATE))
        self.operations.append(Operation(OperationEnum.CHECK))
        self.operations.append(Operation(OperationEnum.GET))
        self.operations.append(Operation(OperationEnum.GET_ATTRIBUTES))
        self.operations.append(Operation(OperationEnum.GET_ATTRIBUTE_LIST))
        self.operations.append(Operation(OperationEnum.ADD_ATTRIBUTE))
        self.operations.append(Operation(OperationEnum.MODIFY_ATTRIBUTE))
        self.operations.append(Operation(OperationEnum.DELETE_ATTRIBUTE))
        self.operations.append(Operation(OperationEnum.OBTAIN_LEASE))
        self.operations.append(Operation(OperationEnum.GET_USAGE_ALLOCATION))
        self.operations.append(Operation(OperationEnum.ACTIVATE))
        self.operations.append(Operation(OperationEnum.REVOKE))
        self.operations.append(Operation(OperationEnum.DESTROY))
        self.operations.append(Operation(OperationEnum.ARCHIVE))
        self.operations.append(Operation(OperationEnum.RECOVER))
        self.operations.append(Operation(OperationEnum.QUERY))
        self.operations.append(Operation(OperationEnum.CANCEL))
        self.operations.append(Operation(OperationEnum.POLL))
        self.operations.append(Operation(OperationEnum.REKEY_KEY_PAIR))
        self.operations.append(Operation(OperationEnum.DISCOVER_VERSIONS))

        self.object_types.append(ObjectType(ObjectTypeEnum.CERTIFICATE))
        self.object_types.append(ObjectType(ObjectTypeEnum.SYMMETRIC_KEY))
        self.object_types.append(ObjectType(ObjectTypeEnum.PUBLIC_KEY))
        self.object_types.append(ObjectType(ObjectTypeEnum.PRIVATE_KEY))
        self.object_types.append(ObjectType(ObjectTypeEnum.TEMPLATE))
        self.object_types.append(ObjectType(ObjectTypeEnum.SECRET_DATA))

        self.extension_information.append(
            ExtensionInformation(
                extension_name=ExtensionName("ACME LOCATION")))
        self.extension_information.append(
            ExtensionInformation(
                extension_name=ExtensionName("ACME ZIP CODE")))

        self.encoding_a = utils.BytearrayStream(
            (b'\x42\x00\x7C\x01\x00\x00\x00\x00'))

        self.encoding_b = utils.BytearrayStream((
            b'\x42\x00\x7C\x01\x00\x00\x02\x40\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x02\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x03\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x04\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x07\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x08\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x09\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x0A\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x0B\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x0C\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x0D\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x0E\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x0F\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x10\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x11\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x12\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x13\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x14\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x15\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x16\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x18\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x19\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x1A\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x1D\x00\x00\x00\x00\x42\x00\x5C\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x1E\x00\x00\x00\x00\x42\x00\x57\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x01\x00\x00\x00\x00\x42\x00\x57\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x02\x00\x00\x00\x00\x42\x00\x57\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x03\x00\x00\x00\x00\x42\x00\x57\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x04\x00\x00\x00\x00\x42\x00\x57\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x06\x00\x00\x00\x00\x42\x00\x57\x05\x00\x00\x00\x04'
            b'\x00\x00\x00\x07\x00\x00\x00\x00\x42\x00\x9D\x07\x00\x00\x00\x2E'
            b'\x49\x42\x4D\x20\x74\x65\x73\x74\x20\x73\x65\x72\x76\x65\x72\x2C'
            b'\x20\x6E\x6F\x74\x2D\x54\x4B\x4C\x4D\x20\x32\x2E\x30\x2E\x31\x2E'
            b'\x31\x20\x4B\x4D\x49\x50\x20\x32\x2E\x30\x2E\x30\x2E\x31\x00\x00'
            b'\x42\x00\x88\x01\x00\x00\x00\x00'))

        self.encoding_c = utils.BytearrayStream((
            b'\x42\x00\x7C\x01\x00\x00\x00\x40\x42\x00\xA4\x01\x00\x00\x00\x18'
            b'\x42\x00\xA5\x07\x00\x00\x00\x0D\x41\x43\x4D\x45\x20\x4C\x4F\x43'
            b'\x41\x54\x49\x4F\x4E\x00\x00\x00\x42\x00\xA4\x01\x00\x00\x00\x18'
            b'\x42\x00\xA5\x07\x00\x00\x00\x0D\x41\x43\x4D\x45\x20\x5A\x49\x50'
            b'\x20\x43\x4F\x44\x45\x00\x00\x00'))