コード例 #1
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing two
        Rekey request payloads with the same data.
        """
        a = payloads.RekeyRequestPayload()
        b = payloads.RekeyRequestPayload()

        self.assertFalse(a != b)
        self.assertFalse(b != a)

        a = payloads.RekeyRequestPayload(
            unique_identifier='1346d253-69d6-474c-8cd5-ad475a3e0a81',
            offset=0,
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Activation Date'),
                    attribute_value=primitives.DateTime(
                        value=1136113200, tag=enums.Tags.ACTIVATION_DATE))
            ]))
        b = payloads.RekeyRequestPayload(
            unique_identifier='1346d253-69d6-474c-8cd5-ad475a3e0a81',
            offset=0,
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Activation Date'),
                    attribute_value=primitives.DateTime(
                        value=1136113200, tag=enums.Tags.ACTIVATION_DATE))
            ]))

        self.assertFalse(a != b)
        self.assertFalse(b != a)
コード例 #2
0
ファイル: test_rekey.py プロジェクト: zmole945/PyKMIP
    def test_read(self):
        """
        Test that a Rekey request payload can be read from a data stream.
        """
        payload = payloads.RekeyRequestPayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.offset)
        self.assertEqual(None, payload.template_attribute)

        payload.read(self.full_encoding)

        self.assertEqual(
            '1346d253-69d6-474c-8cd5-ad475a3e0a81',
            payload.unique_identifier
        )
        self.assertEqual(0, payload.offset)
        self.assertEqual(
            objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Activation Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1136113200,
                            tag=enums.Tags.ACTIVATION_DATE
                        )
                    ),
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Process Start Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1136113200,
                            tag=enums.Tags.PROCESS_START_DATE
                        )
                    ),
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Protect Stop Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.PROTECT_STOP_DATE
                        )
                    ),
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Deactivation Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.DEACTIVATION_DATE
                        )
                    )
                ]
            ),
            payload.template_attribute
        )
コード例 #3
0
    def test_get_attributes(self):
        """
        Test that a secret's attributes can be retrieved with proper input.
        """
        result = results.GetAttributesResult(
            contents.ResultStatus(enums.ResultStatus.SUCCESS),
            uuid='aaaaaaaa-1111-2222-3333-ffffffffffff',
            attributes=[
                obj.Attribute(
                    attribute_name=obj.Attribute.AttributeName('Name'),
                    attribute_index=obj.Attribute.AttributeIndex(0),
                    attribute_value=attr.Name(
                        name_value=attr.Name.NameValue('Test Name'),
                        name_type=attr.Name.NameType(
                            enums.NameType.UNINTERPRETED_TEXT_STRING))),
                obj.Attribute(
                    attribute_name=obj.Attribute.AttributeName('Object Type'),
                    attribute_value=attr.ObjectType(
                        enums.ObjectType.SYMMETRIC_KEY))
            ])

        with ProxyKmipClient() as client:
            client.proxy.get_attributes.return_value = result

            result = client.get_attributes(
                'aaaaaaaa-1111-2222-3333-ffffffffffff',
                ['Name', 'Object Type'])
            client.proxy.get_attributes.assert_called_with(
                'aaaaaaaa-1111-2222-3333-ffffffffffff',
                ['Name', 'Object Type'])
            self.assertIsInstance(result[0], six.string_types)
            self.assertIsInstance(result[1], list)
            for r in result[1]:
                self.assertIsInstance(r, obj.Attribute)
コード例 #4
0
    def test_not_equal_on_not_equal_template_attribute(self):
        """
        Test that the inequality operator returns True when comparing two Rekey
        response payloads with different template attributes.
        """
        a = payloads.RekeyResponsePayload(
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(attribute_name=objects.Attribute.
                                  AttributeName('Cryptographic Algorithm'),
                                  attribute_value=primitives.Enumeration(
                                      enums.CryptographicAlgorithm,
                                      value=enums.CryptographicAlgorithm.AES,
                                      tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM))
            ]))
        b = payloads.RekeyResponsePayload(
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Cryptographic Length'),
                    attribute_value=primitives.Integer(
                        value=128, tag=enums.Tags.CRYPTOGRAPHIC_LENGTH))
            ]))

        self.assertTrue(a != b)
        self.assertTrue(b != a)
コード例 #5
0
    def test_comparison(self):
        """
        Test that the equality/inequality operators return True/False when
        comparing two ModifyAttribute response payloads with the same data.
        """
        a = payloads.ModifyAttributeResponsePayload()
        b = payloads.ModifyAttributeResponsePayload()

        self.assertTrue(a == b)
        self.assertTrue(b == a)
        self.assertFalse(a != b)
        self.assertFalse(b != a)

        a = payloads.ModifyAttributeResponsePayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)))
        b = payloads.ModifyAttributeResponsePayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)))

        self.assertTrue(a == b)
        self.assertTrue(b == a)
        self.assertFalse(a != b)
        self.assertFalse(b != a)
コード例 #6
0
    def test_read(self):
        """
        Test that a Rekey response payload can be read from a data stream.
        """
        payload = payloads.RekeyResponsePayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload.template_attribute)

        payload.read(self.full_encoding)

        self.assertEqual('8efbbd67-2847-46b5-b7e7-4ab3b5e175de',
                         payload.unique_identifier)
        self.assertEqual(
            objects.TemplateAttribute(attributes=[
                objects.Attribute(attribute_name=objects.Attribute.
                                  AttributeName('Cryptographic Algorithm'),
                                  attribute_value=primitives.Enumeration(
                                      enums.CryptographicAlgorithm,
                                      value=enums.CryptographicAlgorithm.AES,
                                      tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM)),
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Cryptographic Length'),
                    attribute_value=primitives.Integer(
                        value=128, tag=enums.Tags.CRYPTOGRAPHIC_LENGTH))
            ]), payload.template_attribute)
コード例 #7
0
ファイル: test_rekey.py プロジェクト: zmole945/PyKMIP
    def test_write(self):
        """
        Test that a Rekey response payload can be written to a data stream.
        """
        payload = payloads.RekeyResponsePayload(
            unique_identifier='8efbbd67-2847-46b5-b7e7-4ab3b5e175de',
            template_attribute=objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Cryptographic Algorithm'
                        ),
                        attribute_value=primitives.Enumeration(
                            enums.CryptographicAlgorithm,
                            value=enums.CryptographicAlgorithm.AES,
                            tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM
                        )
                    ),
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Cryptographic Length'
                        ),
                        attribute_value=primitives.Integer(
                            value=128,
                            tag=enums.Tags.CRYPTOGRAPHIC_LENGTH
                        )
                    )
                ]
            )
        )
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.full_encoding), len(stream))
        self.assertEqual(str(self.full_encoding), str(stream))
コード例 #8
0
    def test_write(self):
        """
        Test that a Rekey request payload can be written to a data stream.
        """
        payload = payloads.RekeyRequestPayload(
            unique_identifier='1346d253-69d6-474c-8cd5-ad475a3e0a81',
            offset=0,
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Activation Date'),
                    attribute_value=primitives.DateTime(
                        value=1136113200, tag=enums.Tags.ACTIVATION_DATE)),
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Process Start Date'),
                    attribute_value=primitives.DateTime(
                        value=1136113200, tag=enums.Tags.PROCESS_START_DATE)),
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Protect Stop Date'),
                    attribute_value=primitives.DateTime(
                        value=1577876400, tag=enums.Tags.PROTECT_STOP_DATE)),
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Deactivation Date'),
                    attribute_value=primitives.DateTime(
                        value=1577876400, tag=enums.Tags.DEACTIVATION_DATE))
            ]))
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.full_encoding), len(stream))
        self.assertEqual(str(self.full_encoding), str(stream))
コード例 #9
0
 def test_init_with_args(self):
     """
     Test that a GetAttributes response payload can be constructed with a
     valid value.
     """
     get_attributes.GetAttributesResponsePayload(
         'test-uid',
         [objects.Attribute(), objects.Attribute()])
コード例 #10
0
 def test_init_with_args(self):
     """
     Test that a GetAttributes response payload can be constructed with a
     valid value.
     """
     payloads.GetAttributesResponsePayload(
         'test-unique-identifier',
         [objects.Attribute(), objects.Attribute()])
コード例 #11
0
    def test_attributes(self):
        """
        Test that the attributes attribute of a GetAttributes response
        payload can be properly set and retrieved.
        """
        payload = payloads.GetAttributesResponsePayload()

        self.assertEqual(list(), payload.attributes)
        self.assertEqual(list(), payload._attributes)

        payload.attributes = [objects.Attribute(), objects.Attribute()]

        self.assertEqual(2, len(payload.attributes))
        self.assertEqual(2, len(payload._attributes))
        for attribute in payload._attributes:
            self.assertIsInstance(attribute, objects.Attribute)
コード例 #12
0
ファイル: test_rekey.py プロジェクト: zmole945/PyKMIP
    def test_str(self):
        """
        Test that str can be applied to a Rekey response payload
        """
        payload = payloads.RekeyResponsePayload(
            unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038',
            template_attribute=objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Cryptographic Length'
                        ),
                        attribute_value=primitives.Integer(
                            value=128,
                            tag=enums.Tags.CRYPTOGRAPHIC_LENGTH
                        )
                    )
                ]
            )
        )

        # TODO (peter-hamilton) Update this when TemplateAttributes have str
        expected = str({
            'unique_identifier': '49a1ca88-6bea-4fb2-b450-7e58802c3038',
            'template_attribute': 'Struct()'
        })
        observed = str(payload)

        self.assertEqual(expected, observed)
コード例 #13
0
    def read(self, istream):
        """
        Read the data encoding the GetAttributes response payload 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(GetAttributesResponsePayload, self).read(istream)
        tstream = utils.BytearrayStream(istream.read(self.length))

        if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, tstream):
            unique_identifier = primitives.TextString(
                tag=enums.Tags.UNIQUE_IDENTIFIER)
            unique_identifier.read(tstream)
            self.unique_identifier = unique_identifier.value
        else:
            raise exceptions.InvalidKmipEncoding(
                "expected GetAttributes response unique identifier not found")

        self._attributes = list()
        while self.is_tag_next(enums.Tags.ATTRIBUTE, tstream):
            attribute = objects.Attribute()
            attribute.read(tstream)
            self._attributes.append(attribute)

        self.is_oversized(tstream)
コード例 #14
0
ファイル: test_rekey.py プロジェクト: zmole945/PyKMIP
    def test_str(self):
        """
        Test that str can be applied to a Rekey request payload
        """
        payload = payloads.RekeyRequestPayload(
            unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038',
            offset=0,
            template_attribute=objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Deactivation Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.DEACTIVATION_DATE
                        )
                    )
                ]
            )
        )

        # TODO (peter-hamilton) Update this when TemplateAttributes have str
        expected = str({
            'unique_identifier': '49a1ca88-6bea-4fb2-b450-7e58802c3038',
            'offset': 0,
            'template_attribute': 'Struct()'
        })
        observed = str(payload)

        self.assertEqual(expected, observed)
コード例 #15
0
ファイル: locate.py プロジェクト: MarcosCalvi/PyKMIP
    def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the Locate request payload and decode it into
        its constituent parts.

        Args:
            input_buffer (stream): A data buffer containing encoded object
                data, supporting a read method.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 1.0.

        Raises:
            InvalidKmipEncoding: Raised if the attributes structure is missing
                from the encoded payload for KMIP 2.0+ encodings.
        """
        super(LocateRequestPayload, self).read(input_buffer,
                                               kmip_version=kmip_version)
        local_buffer = utils.BytearrayStream(input_buffer.read(self.length))

        if self.is_tag_next(enums.Tags.MAXIMUM_ITEMS, local_buffer):
            self._maximum_items = primitives.Integer(
                tag=enums.Tags.MAXIMUM_ITEMS)
            self._maximum_items.read(local_buffer, kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.OFFSET_ITEMS, local_buffer):
            self._offset_items = primitives.Integer(
                tag=enums.Tags.OFFSET_ITEMS)
            self._offset_items.read(local_buffer, kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.STORAGE_STATUS_MASK, local_buffer):
            self._storage_status_mask = primitives.Integer(
                tag=enums.Tags.STORAGE_STATUS_MASK)
            self._storage_status_mask.read(local_buffer,
                                           kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.OBJECT_GROUP_MEMBER, local_buffer):
            self._object_group_member = primitives.Enumeration(
                enums.ObjectGroupMember, tag=enums.Tags.OBJECT_GROUP_MEMBER)
            self._object_group_member.read(local_buffer,
                                           kmip_version=kmip_version)

        if kmip_version < enums.KMIPVersion.KMIP_2_0:
            while self.is_tag_next(enums.Tags.ATTRIBUTE, local_buffer):
                attribute = objects.Attribute()
                attribute.read(local_buffer, kmip_version=kmip_version)
                self._attributes.append(attribute)
        else:
            if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer):
                attributes = objects.Attributes()
                attributes.read(local_buffer, kmip_version=kmip_version)
                # TODO (ph) Add a new utility to avoid using TemplateAttributes
                temp_attr = objects.convert_attributes_to_template_attribute(
                    attributes)
                self._attributes = temp_attr.attributes
            else:
                raise exceptions.InvalidKmipEncoding(
                    "The Locate request payload encoding is missing the "
                    "attributes structure.")
コード例 #16
0
    def test_comparison(self):
        """
        Test that the equality/inequality operators return True/False when
        comparing two ModifyAttribute request payloads with the same data.
        """
        a = payloads.ModifyAttributeRequestPayload()
        b = payloads.ModifyAttributeRequestPayload()

        self.assertTrue(a == b)
        self.assertTrue(b == a)
        self.assertFalse(a != b)
        self.assertFalse(b != a)

        a = payloads.ModifyAttributeRequestPayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)),
            current_attribute=objects.CurrentAttribute(
                attribute=primitives.Enumeration(
                    enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.
                    AES, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)),
            new_attribute=objects.NewAttribute(
                attribute=primitives.Enumeration(
                    enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.
                    RSA, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)))
        b = payloads.ModifyAttributeRequestPayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)),
            current_attribute=objects.CurrentAttribute(
                attribute=primitives.Enumeration(
                    enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.
                    AES, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)),
            new_attribute=objects.NewAttribute(
                attribute=primitives.Enumeration(
                    enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.
                    RSA, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)))

        self.assertTrue(a == b)
        self.assertTrue(b == a)
        self.assertFalse(a != b)
        self.assertFalse(b != a)
コード例 #17
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing two
        Rekey response payloads with the same data.
        """
        a = payloads.RekeyResponsePayload()
        b = payloads.RekeyResponsePayload()

        self.assertFalse(a != b)
        self.assertFalse(b != a)

        a = payloads.RekeyResponsePayload(
            unique_identifier='1346d253-69d6-474c-8cd5-ad475a3e0a81',
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(attribute_name=objects.Attribute.
                                  AttributeName('Cryptographic Algorithm'),
                                  attribute_value=primitives.Enumeration(
                                      enums.CryptographicAlgorithm,
                                      value=enums.CryptographicAlgorithm.AES,
                                      tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM)),
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Cryptographic Length'),
                    attribute_value=primitives.Integer(
                        value=128, tag=enums.Tags.CRYPTOGRAPHIC_LENGTH))
            ]))
        b = payloads.RekeyResponsePayload(
            unique_identifier='1346d253-69d6-474c-8cd5-ad475a3e0a81',
            template_attribute=objects.TemplateAttribute(attributes=[
                objects.Attribute(attribute_name=objects.Attribute.
                                  AttributeName('Cryptographic Algorithm'),
                                  attribute_value=primitives.Enumeration(
                                      enums.CryptographicAlgorithm,
                                      value=enums.CryptographicAlgorithm.AES,
                                      tag=enums.Tags.CRYPTOGRAPHIC_ALGORITHM)),
                objects.Attribute(
                    attribute_name=objects.Attribute.AttributeName(
                        'Cryptographic Length'),
                    attribute_value=primitives.Integer(
                        value=128, tag=enums.Tags.CRYPTOGRAPHIC_LENGTH))
            ]))

        self.assertFalse(a != b)
        self.assertFalse(b != a)
コード例 #18
0
    def test_comparison_on_different_attributes(self):
        """
        Test that the equality/inequality operators return False/True when
        comparing two ModifyAttribute request payloads with different
        attributes.
        """
        a = payloads.ModifyAttributeRequestPayload(attribute=objects.Attribute(
            attribute_name=objects.Attribute.AttributeName("x-attribute1"),
            attribute_value=primitives.TextString(
                value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)))
        b = payloads.ModifyAttributeRequestPayload(attribute=objects.Attribute(
            attribute_name=objects.Attribute.AttributeName("x-attribute2"),
            attribute_value=primitives.TextString(
                value="ModifiedValue2", tag=enums.Tags.ATTRIBUTE_VALUE)))

        self.assertFalse(a == b)
        self.assertFalse(b == a)
        self.assertTrue(a != b)
        self.assertTrue(b != a)
コード例 #19
0
    def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the ModifyAttribute request payload and decode
        it into its constituent part.

        Args:
            input_buffer (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.

        Raises:
            InvalidKmipEncoding: Raised if fields are missing from the
                encoding.
        """
        super(ModifyAttributeRequestPayload,
              self).read(input_buffer, kmip_version=kmip_version)
        local_buffer = utils.BytearrayStream(input_buffer.read(self.length))

        if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
            self._unique_identifier = primitives.TextString(
                tag=enums.Tags.UNIQUE_IDENTIFIER)
            self._unique_identifier.read(local_buffer,
                                         kmip_version=kmip_version)
        else:
            self._unique_identifier = None

        if kmip_version < enums.KMIPVersion.KMIP_2_0:
            if self.is_tag_next(enums.Tags.ATTRIBUTE, local_buffer):
                self._attribute = objects.Attribute()
                self._attribute.read(local_buffer, kmip_version=kmip_version)
            else:
                raise exceptions.InvalidKmipEncoding(
                    "The ModifyAttribute request payload encoding is missing "
                    "the attribute field.")
        else:
            if self.is_tag_next(enums.Tags.CURRENT_ATTRIBUTE, local_buffer):
                self._current_attribute = objects.CurrentAttribute()
                self._current_attribute.read(local_buffer,
                                             kmip_version=kmip_version)
            else:
                self._current_attribute = None

            if self.is_tag_next(enums.Tags.NEW_ATTRIBUTE, local_buffer):
                self._new_attribute = objects.NewAttribute()
                self._new_attribute.read(local_buffer,
                                         kmip_version=kmip_version)
            else:
                raise exceptions.InvalidKmipEncoding(
                    "The ModifyAttribute request payload encoding is missing "
                    "the new attribute field.")

        self.is_oversized(local_buffer)
コード例 #20
0
 def test_attributes_with_invalid_attribute(self):
     """
     Test that a TypeError is raised when an invalid attribute is included
     in the list used to set the attributes attribute of a GetAttributes
     response payload.
     """
     payload = payloads.GetAttributesResponsePayload()
     args = (payload, 'attributes', [objects.Attribute(), 0])
     self.assertRaisesRegex(
         TypeError, "attributes must be a list of attribute objects; "
         "item 2 has type {0}".format(type(0)), setattr, *args)
コード例 #21
0
ファイル: get_attributes.py プロジェクト: xxgoracle/PyKMIP
    def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the GetAttributes response payload and decode
        it into its constituent parts.

        Args:
            input_buffer (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(GetAttributesResponsePayload, self).read(
            input_buffer,
            kmip_version=kmip_version
        )
        local_buffer = utils.BytearrayStream(input_buffer.read(self.length))

        if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
            unique_identifier = primitives.TextString(
                tag=enums.Tags.UNIQUE_IDENTIFIER
            )
            unique_identifier.read(local_buffer, kmip_version=kmip_version)
            self.unique_identifier = unique_identifier.value
        else:
            raise exceptions.InvalidKmipEncoding(
                "The GetAttributes response payload encoding is missing the "
                "unique identifier."
            )

        if kmip_version < enums.KMIPVersion.KMIP_2_0:
            self._attributes = list()
            while self.is_tag_next(enums.Tags.ATTRIBUTE, local_buffer):
                attribute = objects.Attribute()
                attribute.read(local_buffer, kmip_version=kmip_version)
                self._attributes.append(attribute)
        else:
            if self.is_tag_next(enums.Tags.ATTRIBUTES, local_buffer):
                attributes = objects.Attributes()
                attributes.read(local_buffer, kmip_version=kmip_version)
                # TODO (ph) Add a new utility to avoid using TemplateAttributes
                temp_attr = objects.convert_attributes_to_template_attribute(
                    attributes
                )
                self._attributes = temp_attr.attributes
            else:
                raise exceptions.InvalidKmipEncoding(
                    "The GetAttributes response payload encoding is missing "
                    "the attributes structure."
                )

        self.is_oversized(local_buffer)
コード例 #22
0
ファイル: test_rekey.py プロジェクト: zmole945/PyKMIP
    def test_not_equal_on_not_equal_template_attribute(self):
        """
        Test that the inequality operator returns True when comparing two Rekey
        request payloads with different template attributes.
        """
        a = payloads.RekeyRequestPayload(
            template_attribute=objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Protect Stop Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.PROTECT_STOP_DATE
                        )
                    )
                ]
            )
        )
        b = payloads.RekeyRequestPayload(
            template_attribute=objects.TemplateAttribute(
                attributes=[
                    objects.Attribute(
                        attribute_name=objects.Attribute.AttributeName(
                            'Deactivation Date'
                        ),
                        attribute_value=primitives.DateTime(
                            value=1577876400,
                            tag=enums.Tags.DEACTIVATION_DATE
                        )
                    )
                ]
            )
        )

        self.assertTrue(a != b)
        self.assertTrue(b != a)
コード例 #23
0
ファイル: test_attribute.py プロジェクト: xxgoracle/PyKMIP
    def test_repr(self):
        """
        Test that repr can be applied to an Attribute object.
        """
        attribute = objects.Attribute(
            attribute_name=objects.Attribute.AttributeName('test-name'),
            attribute_index=objects.Attribute.AttributeIndex(0),
            attribute_value=attributes.CustomAttribute('test-value'))

        self.assertEqual(
            "Attribute("
            "attribute_name=AttributeName(value='test-name'), "
            "attribute_index=AttributeIndex(value=0), "
            "attribute_value=CustomAttribute(value='test-value'))",
            repr(attribute))
コード例 #24
0
ファイル: test_attribute.py プロジェクト: xxgoracle/PyKMIP
    def test_str(self):
        """
        Test that str can be applied to an Attribute object.
        """
        attribute = objects.Attribute(
            attribute_name=objects.Attribute.AttributeName('test-name'),
            attribute_index=objects.Attribute.AttributeIndex(0),
            attribute_value=attributes.CustomAttribute('test-value'))

        self.assertEqual(
            str({
                'attribute_name': 'test-name',
                'attribute_index': '0',
                'attribute_value': 'test-value'
            }), str(attribute))
コード例 #25
0
    def test_write(self):
        """
        Test that a ModifyAttribute request payload can be written to a buffer.
        """
        payload = payloads.ModifyAttributeRequestPayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)))

        buffer = utils.BytearrayStream()
        payload.write(buffer)

        self.assertEqual(len(self.full_encoding), len(buffer))
        self.assertEqual(str(self.full_encoding), str(buffer))
コード例 #26
0
    def test_read(self):
        """
        Test that a ModifyAttribute response payload can be read from a buffer.
        """
        payload = payloads.ModifyAttributeResponsePayload()

        self.assertIsNone(payload.unique_identifier)
        self.assertIsNone(payload.attribute)

        payload.read(self.full_encoding)

        self.assertEqual("b4faee10-aa2a-4446-8ad4-0881f3422959",
                         payload.unique_identifier)
        self.assertEqual(
            objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)),
            payload.attribute)
コード例 #27
0
ファイル: test_attribute.py プロジェクト: xxgoracle/PyKMIP
 def test_init(self):
     """
     Test that an Attribute object can be created.
     """
     objects.Attribute()
コード例 #28
0
    def setUp(self):
        super(TestGetAttributesResponsePayload, self).setUp()

        # Encodings taken from Sections 3.1.2 of the KMIP 1.1 testing
        # documentation.
        self.full_encoding = utils.BytearrayStream(
            b'\x42\x00\x7C\x01\x00\x00\x01\x30\x42\x00\x94\x07\x00\x00\x00\x24'
            b'\x31\x37\x30\x33\x32\x35\x30\x62\x2D\x34\x64\x34\x30\x2D\x34\x64'
            b'\x65\x32\x2D\x39\x33\x61\x30\x2D\x63\x34\x39\x34\x61\x31\x64\x34'
            b'\x61\x65\x34\x30\x00\x00\x00\x00\x42\x00\x08\x01\x00\x00\x00\x28'
            b'\x42\x00\x0A\x07\x00\x00\x00\x0C\x4F\x62\x6A\x65\x63\x74\x20\x47'
            b'\x72\x6F\x75\x70\x00\x00\x00\x00\x42\x00\x0B\x07\x00\x00\x00\x06'
            b'\x47\x72\x6F\x75\x70\x31\x00\x00\x42\x00\x08\x01\x00\x00\x00\x58'
            b'\x42\x00\x0A\x07\x00\x00\x00\x20\x41\x70\x70\x6C\x69\x63\x61\x74'
            b'\x69\x6F\x6E\x20\x53\x70\x65\x63\x69\x66\x69\x63\x20\x49\x6E\x66'
            b'\x6F\x72\x6D\x61\x74\x69\x6F\x6E\x42\x00\x0B\x01\x00\x00\x00\x28'
            b'\x42\x00\x03\x07\x00\x00\x00\x03\x73\x73\x6C\x00\x00\x00\x00\x00'
            b'\x42\x00\x02\x07\x00\x00\x00\x0F\x77\x77\x77\x2E\x65\x78\x61\x6D'
            b'\x70\x6C\x65\x2E\x63\x6F\x6D\x00\x42\x00\x08\x01\x00\x00\x00\x30'
            b'\x42\x00\x0A\x07\x00\x00\x00\x13\x43\x6F\x6E\x74\x61\x63\x74\x20'
            b'\x49\x6E\x66\x6F\x72\x6D\x61\x74\x69\x6F\x6E\x00\x00\x00\x00\x00'
            b'\x42\x00\x0B\x07\x00\x00\x00\x03\x4A\x6F\x65\x00\x00\x00\x00\x00'
            b'\x42\x00\x08\x01\x00\x00\x00\x30\x42\x00\x0A\x07\x00\x00\x00\x09'
            b'\x78\x2D\x50\x75\x72\x70\x6F\x73\x65\x00\x00\x00\x00\x00\x00\x00'
            b'\x42\x00\x0B\x07\x00\x00\x00\x0D\x64\x65\x6D\x6F\x6E\x73\x74\x72'
            b'\x61\x74\x69\x6F\x6E\x00\x00\x00')
        self.encoding_sans_unique_identifier = utils.BytearrayStream(
            b'\x42\x00\x7C\x01\x00\x00\x01\x00\x42\x00\x08\x01\x00\x00\x00\x28'
            b'\x42\x00\x0A\x07\x00\x00\x00\x0C\x4F\x62\x6A\x65\x63\x74\x20\x47'
            b'\x72\x6F\x75\x70\x00\x00\x00\x00\x42\x00\x0B\x07\x00\x00\x00\x06'
            b'\x47\x72\x6F\x75\x70\x31\x00\x00\x42\x00\x08\x01\x00\x00\x00\x58'
            b'\x42\x00\x0A\x07\x00\x00\x00\x20\x41\x70\x70\x6C\x69\x63\x61\x74'
            b'\x69\x6F\x6E\x20\x53\x70\x65\x63\x69\x66\x69\x63\x20\x49\x6E\x66'
            b'\x6F\x72\x6D\x61\x74\x69\x6F\x6E\x42\x00\x0B\x01\x00\x00\x00\x28'
            b'\x42\x00\x03\x07\x00\x00\x00\x03\x73\x73\x6C\x00\x00\x00\x00\x00'
            b'\x42\x00\x02\x07\x00\x00\x00\x0F\x77\x77\x77\x2E\x65\x78\x61\x6D'
            b'\x70\x6C\x65\x2E\x63\x6F\x6D\x00\x42\x00\x08\x01\x00\x00\x00\x30'
            b'\x42\x00\x0A\x07\x00\x00\x00\x13\x43\x6F\x6E\x74\x61\x63\x74\x20'
            b'\x49\x6E\x66\x6F\x72\x6D\x61\x74\x69\x6F\x6E\x00\x00\x00\x00\x00'
            b'\x42\x00\x0B\x07\x00\x00\x00\x03\x4A\x6F\x65\x00\x00\x00\x00\x00'
            b'\x42\x00\x08\x01\x00\x00\x00\x30\x42\x00\x0A\x07\x00\x00\x00\x09'
            b'\x78\x2D\x50\x75\x72\x70\x6F\x73\x65\x00\x00\x00\x00\x00\x00\x00'
            b'\x42\x00\x0B\x07\x00\x00\x00\x0D\x64\x65\x6D\x6F\x6E\x73\x74\x72'
            b'\x61\x74\x69\x6F\x6E\x00\x00\x00')
        self.encoding_sans_attributes = utils.BytearrayStream(
            b'\x42\x00\x7C\x01\x00\x00\x00\x30\x42\x00\x94\x07\x00\x00\x00\x24'
            b'\x31\x37\x30\x33\x32\x35\x30\x62\x2D\x34\x64\x34\x30\x2D\x34\x64'
            b'\x65\x32\x2D\x39\x33\x61\x30\x2D\x63\x34\x39\x34\x61\x31\x64\x34'
            b'\x61\x65\x34\x30\x00\x00\x00\x00')

        self.unique_identifier = '1703250b-4d40-4de2-93a0-c494a1d4ae40'
        self.attributes = [
            objects.Attribute(
                attribute_name=objects.Attribute.AttributeName('Object Group'),
                attribute_value=attributes.ObjectGroup('Group1')),
            objects.Attribute(
                attribute_name=objects.Attribute.AttributeName(
                    'Application Specific Information'),
                attribute_value=attributes.ApplicationSpecificInformation(
                    attributes.ApplicationNamespace('ssl'),
                    attributes.ApplicationData('www.example.com'))),
            objects.Attribute(
                attribute_name=objects.Attribute.AttributeName(
                    'Contact Information'),
                attribute_value=attributes.ContactInformation('Joe')),
            objects.Attribute(
                attribute_name=objects.Attribute.AttributeName('x-Purpose'),
                attribute_value=primitives.TextString('demonstration'))
        ]