def test_comparison(self):
        """
        Test that the equality/inequality operators return True/False when
        comparing two ApplicationSpecificInformation objects with the same
        data.
        """
        a = attributes.ApplicationSpecificInformation()
        b = attributes.ApplicationSpecificInformation()

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

        a = attributes.ApplicationSpecificInformation(
            application_namespace="test_namespace",
            application_data="test_data")
        b = attributes.ApplicationSpecificInformation(
            application_namespace="test_namespace",
            application_data="test_data")

        self.assertTrue(a == b)
        self.assertTrue(b == a)
        self.assertFalse(a != b)
        self.assertFalse(b != a)
Exemplo n.º 2
0
 def _create_application_specific_information(self, info):
     if info:
         return attributes.ApplicationSpecificInformation(
             application_namespace=info.get("application_namespace"),
             application_data=info.get("application_data"))
     else:
         return attributes.ApplicationSpecificInformation()
    def test_init(self):
        """
        Test that an ApplicationSpecificInformation object can be constructed.
        """
        app_specific_info = attributes.ApplicationSpecificInformation()

        self.assertIsNone(app_specific_info.application_namespace)
        self.assertIsNone(app_specific_info.application_data)

        app_specific_info = attributes.ApplicationSpecificInformation(
            application_namespace="namespace", application_data="data")

        self.assertEqual("namespace", app_specific_info.application_namespace)
        self.assertEqual("data", app_specific_info.application_data)
    def test_comparison_on_different_application_data(self):
        """
        Test that the equality/inequality operators return False/True when
        comparing two ApplicationSpecificInformation objects with different
        data.
        """
        a = attributes.ApplicationSpecificInformation(
            application_data="test_data_1")
        b = attributes.ApplicationSpecificInformation(
            application_data="test_data_2")

        self.assertFalse(a == b)
        self.assertFalse(b == a)
        self.assertTrue(a != b)
        self.assertTrue(b != a)
    def test_comparison_on_type_mismatch(self):
        """
        Test that the equality/inequality operators return False/True when
        comparing an ApplicationSpecificInformation object to a
        non-ApplicationSpecificInformation object.
        """
        a = attributes.ApplicationSpecificInformation(
            application_namespace="test_namespace",
            application_data="test_data")
        b = "invalid"

        self.assertFalse(a == b)
        self.assertFalse(b == a)
    def test_write(self):
        """
        Test that an ApplicationSpecificInformation object can be written to a
        buffer.
        """
        app_specific_info = attributes.ApplicationSpecificInformation(
            application_namespace="ssl", application_data="www.example.com")

        buff = utils.BytearrayStream()
        app_specific_info.write(buff)

        self.assertEqual(len(self.full_encoding), len(buff))
        self.assertEqual(str(self.full_encoding), str(buff))
    def test_str(self):
        """
        Test that str can be applied to an ApplicationSpecificInformation
        object.
        """
        app_specific_info = attributes.ApplicationSpecificInformation(
            application_namespace="ssl", application_data="www.example.com")

        args = [("application_namespace", "ssl"),
                ("application_data", "www.example.com")]
        value = "{}".format(", ".join(
            ['"{}": "{}"'.format(arg[0], arg[1]) for arg in args]))
        self.assertEqual("{" + value + "}", str(app_specific_info))
    def test_repr(self):
        """
        Test that repr can be applied to an ApplicationSpecificInformation
        object.
        """
        app_specific_info = attributes.ApplicationSpecificInformation(
            application_namespace="ssl", application_data="www.example.com")

        args = [
            "application_namespace='ssl'", "application_data='www.example.com'"
        ]
        self.assertEqual(
            "ApplicationSpecificInformation({})".format(", ".join(args)),
            repr(app_specific_info))
    def test_read(self):
        """
        Test that an ApplicationSpecificInformation object can be read from a
        buffer.
        """
        app_specific_info = attributes.ApplicationSpecificInformation()

        self.assertIsNone(app_specific_info.application_namespace)
        self.assertIsNone(app_specific_info.application_data)

        app_specific_info.read(self.full_encoding)

        self.assertEqual("ssl", app_specific_info.application_namespace)
        self.assertEqual("www.example.com", app_specific_info.application_data)
    def test_write_missing_application_data(self):
        """
        Test that an InvalidField error is raised during the encoding of an
        ApplicationSpecificInformation object when the object is missing the
        application data field.
        """
        app_specific_info = attributes.ApplicationSpecificInformation(
            application_namespace="ssl")

        buff = utils.BytearrayStream()
        args = (buff, )
        self.assertRaisesRegex(
            exceptions.InvalidField,
            "The ApplicationSpecificInformation object is missing the "
            "ApplicationData field.", app_specific_info.write, *args)
    def test_read_missing_application_data(self):
        """
        Test that an InvalidKmipEncoding error is raised during the decoding of
        an ApplicationSpecificInformation object with the application data is
        missing from the encoding.
        """
        app_specific_info = attributes.ApplicationSpecificInformation()

        self.assertIsNone(app_specific_info.application_data)

        args = (self.no_application_data_encoding, )
        self.assertRaisesRegex(
            exceptions.InvalidKmipEncoding,
            "The ApplicationSpecificInformation encoding is missing the "
            "ApplicationData field.", app_specific_info.read, *args)
    def test_invalid_application_namespace(self):
        """
        Test that a TypeError is raised when an invalid value is used to set
        the application namespace of an ApplicationSpecificInformation object.
        """
        kwargs = {"application_namespace": []}
        self.assertRaisesRegex(TypeError,
                               "The application namespace must be a string.",
                               attributes.ApplicationSpecificInformation,
                               **kwargs)

        args = (attributes.ApplicationSpecificInformation(),
                "application_namespace", [])
        self.assertRaisesRegex(TypeError,
                               "The application namespace must be a string.",
                               setattr, *args)
Exemplo n.º 13
0
    def _create_application_specific_information(self, info):
        if info is None:
            return attributes.ApplicationSpecificInformation()
        else:
            application_namespace = info.get('application_namespace')
            application_data = info.get('application_data')

            if not isinstance(application_namespace, str):
                msg = utils.build_er_error(
                    attributes.ApplicationSpecificInformation,
                    'constructor argument type', str,
                    type(application_namespace))
                raise TypeError(msg)

            if not isinstance(application_data, str):
                msg = utils.build_er_error(
                    attributes.ApplicationSpecificInformation,
                    'constructor argument type', str, type(application_data))
                raise TypeError(msg)

            return attributes.ApplicationSpecificInformation.create(
                application_namespace, application_data)
Exemplo n.º 14
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'))
        ]