Ejemplo n.º 1
0
    def test_comparison(self):
        """
        Test that the equality/inequality operators return True/False when
        comparing two SetAttribute request payloads with the same data.
        """
        a = payloads.SetAttributeRequestPayload()
        b = payloads.SetAttributeRequestPayload()

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

        a = payloads.SetAttributeRequestPayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            new_attribute=objects.NewAttribute(
                attribute=primitives.Enumeration(
                    enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.
                    AES, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)))
        b = payloads.SetAttributeRequestPayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            new_attribute=objects.NewAttribute(
                attribute=primitives.Enumeration(
                    enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.
                    AES, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)))

        self.assertTrue(a == b)
        self.assertTrue(b == a)
        self.assertFalse(a != b)
        self.assertFalse(b != a)
Ejemplo n.º 2
0
    def test_comparison_on_different_unique_identifiers(self):
        """
        Test that the equality/inequality operators return False/True when
        comparing two SetAttribute request payloads with different unique
        identifiers.
        """
        a = payloads.SetAttributeRequestPayload(unique_identifier="1")
        b = payloads.SetAttributeRequestPayload(unique_identifier="2")

        self.assertFalse(a == b)
        self.assertFalse(b == a)
        self.assertTrue(a != b)
        self.assertTrue(b != a)
Ejemplo n.º 3
0
    def test_comparison_on_different_new_attributes(self):
        """
        Test that the equality/inequality operators return False/True when
        comparing two SetAttribute request payloads with different new
        attributes.
        """
        a = payloads.SetAttributeRequestPayload(
            new_attribute=objects.NewAttribute(
                attribute=primitives.Enumeration(
                    enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.
                    AES, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)))
        b = payloads.SetAttributeRequestPayload(
            new_attribute=objects.NewAttribute(attribute=primitives.Integer(
                128, enums.Tags.CRYPTOGRAPHIC_LENGTH)))

        self.assertFalse(a == b)
        self.assertFalse(b == a)
        self.assertTrue(a != b)
        self.assertTrue(b != a)
Ejemplo n.º 4
0
    def test_comparison_on_type_mismatch(self):
        """
        Test that the equality/inequality operators return False/True when
        comparining a SetAttribute request payload against a different type.
        """
        a = payloads.SetAttributeRequestPayload()
        b = "invalid"

        self.assertFalse(a == b)
        self.assertFalse(b == a)
        self.assertTrue(a != b)
        self.assertTrue(b != a)
Ejemplo n.º 5
0
 def test_str(self):
     """
     Test that str can be applied to a SetAttribute request payload.
     """
     payload = payloads.SetAttributeRequestPayload(
         unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
         new_attribute=None)
     s = str({
         "unique_identifier": "b4faee10-aa2a-4446-8ad4-0881f3422959",
         "new_attribute": None
     })
     self.assertEqual(s, str(payload))
Ejemplo n.º 6
0
 def test_read_invalid_kmip_version(self):
     """
     Test that a VersionNotSupported error is raised when an unsupported
     version of KMIP is used to decode the SetAttribute request payload.
     """
     payload = payloads.SetAttributeRequestPayload()
     args = (self.empty_encoding, )
     kwargs = {"kmip_version": enums.KMIPVersion.KMIP_1_0}
     self.assertRaisesRegex(
         exceptions.VersionNotSupported,
         "KMIP 1.0 does not support the SetAttribute operation.",
         payload.read, *args, **kwargs)
Ejemplo n.º 7
0
 def test_read_no_new_attribute(self):
     """
     Test that an InvalidKmipEncoding error is raised when an invalid
     encoding containing no encoded new attribute is used to decode
     a SetAttribute request payload.
     """
     payload = payloads.SetAttributeRequestPayload()
     args = (self.empty_encoding, )
     self.assertRaisesRegex(
         exceptions.InvalidKmipEncoding,
         "The SetAttribute request payload encoding is missing the "
         "new attribute field.", payload.read, *args)
Ejemplo n.º 8
0
    def test_write_invalid_kmip_version(self):
        """
        Test that a VersionNotSupported error is raised when an unsupported
        version of KMIP is used to encode the SetAttribute request payload.
        """
        payload = payloads.SetAttributeRequestPayload()

        args = (utils.BytearrayStream(), )
        kwargs = {"kmip_version": enums.KMIPVersion.KMIP_1_0}
        self.assertRaisesRegex(
            exceptions.VersionNotSupported,
            "KMIP 1.0 does not support the SetAttribute operation.",
            payload.write, *args, **kwargs)
Ejemplo n.º 9
0
    def test_write_no_new_attribute(self):
        """
        Test that an InvalidField error is raised when attempting to write
        a SetAttribute request payload to a buffer with no new attribute
        field specified.
        """
        payload = payloads.SetAttributeRequestPayload()

        args = (utils.BytearrayStream(), )
        self.assertRaisesRegex(
            exceptions.InvalidField,
            "The SetAttribute request payload is missing the new attribute "
            "field.", payload.write, *args)
Ejemplo n.º 10
0
    def test_invalid_unique_identifier(self):
        """
        Test that a TypeError is raised when an invalid value is used to set
        the unique identifier of a SetAttribute request payload.
        """
        kwargs = {"unique_identifier": 0}
        self.assertRaisesRegex(TypeError,
                               "The unique identifier must be a string.",
                               payloads.SetAttributeRequestPayload, **kwargs)

        args = (payloads.SetAttributeRequestPayload(), "unique_identifier", 0)
        self.assertRaisesRegex(TypeError,
                               "The unique identifier must be a string.",
                               setattr, *args)
Ejemplo n.º 11
0
    def test_invalid_new_attribute(self):
        """
        Test that a TypeError is raised when an invalid value is used to set
        the new attribute of a SetAttribute request payload.
        """
        kwargs = {"new_attribute": "invalid"}
        self.assertRaisesRegex(
            TypeError, "The new attribute must be a NewAttribute object.",
            payloads.SetAttributeRequestPayload, **kwargs)

        args = (payloads.SetAttributeRequestPayload(), "new_attribute",
                "invalid")
        self.assertRaisesRegex(
            TypeError, "The new attribute must be a NewAttribute object.",
            setattr, *args)
Ejemplo n.º 12
0
    def test_repr(self):
        """
        Test that repr can be applied to a SetAttribute request payload.
        """
        payload = payloads.SetAttributeRequestPayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            new_attribute=None)

        args = [
            "unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959'",
            "new_attribute=None"
        ]
        self.assertEqual(
            "SetAttributeRequestPayload({})".format(", ".join(args)),
            repr(payload))
Ejemplo n.º 13
0
    def test_write_no_unique_identifier(self):
        """
        Test that a SetAttribute request payload can be written to a buffer
        without the unique identifier field.
        """
        payload = payloads.SetAttributeRequestPayload(
            new_attribute=objects.NewAttribute(
                attribute=primitives.Enumeration(
                    enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.
                    AES, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)))

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

        self.assertEqual(len(self.no_unique_identifier_encoding), len(buffer))
        self.assertEqual(str(self.no_unique_identifier_encoding), str(buffer))
Ejemplo n.º 14
0
    def test_write(self):
        """
        Test that a SetAttribute request payload can be written to a buffer.
        """
        payload = payloads.SetAttributeRequestPayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            new_attribute=objects.NewAttribute(
                attribute=primitives.Enumeration(
                    enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.
                    AES, enums.Tags.CRYPTOGRAPHIC_ALGORITHM)))

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

        self.assertEqual(len(self.full_encoding), len(buffer))
        self.assertEqual(str(self.full_encoding), str(buffer))
Ejemplo n.º 15
0
    def test_read_no_unique_identifier(self):
        """
        Test that a SetAttribute request payload can be read from a buffer
        even when the encoding is missing the unique identifier field.
        """
        payload = payloads.SetAttributeRequestPayload()

        self.assertIsNone(payload.unique_identifier)
        self.assertIsNone(payload.new_attribute)

        payload.read(self.no_unique_identifier_encoding)

        self.assertIsNone(payload.unique_identifier)
        self.assertEqual(
            objects.NewAttribute(attribute=primitives.Enumeration(
                enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.AES,
                enums.Tags.CRYPTOGRAPHIC_ALGORITHM)), payload.new_attribute)
Ejemplo n.º 16
0
    def test_read(self):
        """
        Test that a SetAttribute request payload can be read from a buffer.
        """
        payload = payloads.SetAttributeRequestPayload()

        self.assertIsNone(payload.unique_identifier)
        self.assertIsNone(payload.new_attribute)

        payload.read(self.full_encoding)

        self.assertEqual("b4faee10-aa2a-4446-8ad4-0881f3422959",
                         payload.unique_identifier)
        self.assertEqual(
            objects.NewAttribute(attribute=primitives.Enumeration(
                enums.CryptographicAlgorithm, enums.CryptographicAlgorithm.AES,
                enums.Tags.CRYPTOGRAPHIC_ALGORITHM)), payload.new_attribute)
Ejemplo n.º 17
0
 def _create_set_attribute_payload(self):
     return payloads.SetAttributeRequestPayload()