def test_equal_on_equal(self):
        """
        Test that the equality operator returns True when comparing two
        GetAttributeList response payloads with the same data.
        """
        a = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     self.attribute_names)
        b = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     self.attribute_names)

        self.assertTrue(a == b)
        self.assertTrue(b == a)
    def test_equal_on_not_equal_unique_identifier(self):
        """
        Test that the equality operator returns False when comparing two
        GetAttributeList response payloads with different IDs.
        """
        a = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     self.attribute_names)
        b = payloads.GetAttributeListResponsePayload('invalid',
                                                     self.attribute_names)

        self.assertFalse(a == b)
        self.assertFalse(b == a)
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing
        two GetAttributeList response payloads with the same internal data.
        """
        a = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     self.attribute_names)
        b = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     self.attribute_names)

        self.assertFalse(a != b)
        self.assertFalse(b != a)
    def test_not_equal_on_not_equal_attribute_names(self):
        """
        Test that the inequality operator returns True when comparing two
        GetAttributeList response payloads with different attribute names.
        """
        a = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     self.attribute_names)
        b = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     None)

        self.assertTrue(a != b)
        self.assertTrue(b != a)
    def test_equal_with_mixed_attribute_names(self):
        """
        Test that the equality operator returns True when comparing two
        GetAttributeList response payload with the same attribute_name sets
        but with different attribute name orderings.
        """
        a = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     self.attribute_names)
        self.attribute_names.reverse()
        b = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     self.attribute_names)

        self.assertTrue(a == b)
        self.assertTrue(b == a)
    def test_attribute_names_with_duplicates(self):
        """
        Test that duplicate attribute names are silently removed when setting
        the attribute_names attribute of a GetAttributeList response payload.
        """
        payload = payloads.GetAttributeListResponsePayload()

        self.assertEqual(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)

        payload.attribute_names = [
            'test-attribute-name-1', 'test-attribute-name-1',
            'test-attribute-name-2'
        ]

        self.assertEqual(2, len(payload.attribute_names))
        self.assertEqual(2, len(payload._attribute_names))
        self.assertIn('test-attribute-name-1', payload.attribute_names)
        self.assertIn('test-attribute-name-2', payload.attribute_names)
        self.assertIn(
            primitives.TextString(value='test-attribute-name-1',
                                  tag=enums.Tags.ATTRIBUTE_NAME),
            payload._attribute_names)
        self.assertIn(
            primitives.TextString(value='test-attribute-name-2',
                                  tag=enums.Tags.ATTRIBUTE_NAME),
            payload._attribute_names)
    def test_attribute_names(self):
        """
        Test that the attribute_names attribute of a GetAttributeList response
        payload can be properly set and retrieved.
        """
        payload = payloads.GetAttributeListResponsePayload()

        self.assertEqual(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)

        payload.attribute_names = [
            'test-attribute-name-1', 'test-attribute-name-2'
        ]

        self.assertEqual(2, len(payload.attribute_names))
        self.assertEqual(2, len(payload._attribute_names))
        self.assertIn('test-attribute-name-1', payload.attribute_names)
        self.assertIn('test-attribute-name-2', payload.attribute_names)
        self.assertIn(
            primitives.TextString(value='test-attribute-name-1',
                                  tag=enums.Tags.ATTRIBUTE_NAME),
            payload._attribute_names)
        self.assertIn(
            primitives.TextString(value='test-attribute-name-2',
                                  tag=enums.Tags.ATTRIBUTE_NAME),
            payload._attribute_names)
 def test_init_with_args(self):
     """
     Test that a GetAttributeList response payload can be constructed with a
     valid value.
     """
     payloads.GetAttributeListResponsePayload(
         'test-unique-identifier',
         ['test-attribute-name-1', 'test-attribute-name-2'])
 def test_str_with_no_content(self):
     """
     Test that str can be applied to a GetAttributeList response payload
     with no ID or attribute names.
     """
     payload = payloads.GetAttributeListResponsePayload(None, None)
     expected = str({'unique_identifier': None, 'attribute_names': list()})
     observed = str(payload)
     self.assertEqual(expected, observed)
 def test_attribute_names_with_invalid_value(self):
     """
     Test that a TypeError is raised when an invalid list is used to set
     the attribute_names attribute of a GetAttributeList response payload.
     """
     payload = payloads.GetAttributeListResponsePayload()
     args = (payload, 'attribute_names', 0)
     self.assertRaisesRegexp(TypeError,
                             "attribute_names must be a list of strings",
                             setattr, *args)
Exemple #11
0
 def test_unique_identifier_with_invalid_value(self):
     """
     Test that a TypeError is raised when an invalid ID is used to set
     the unique_identifier attribute of a GetAttributeList response
     payload.
     """
     payload = payloads.GetAttributeListResponsePayload()
     args = (payload, 'unique_identifier', 0)
     self.assertRaisesRegex(TypeError, "unique identifier must be a string",
                            setattr, *args)
 def test_attribute_names_with_invalid_attribute_name(self):
     """
     Test that a TypeError is raised when an invalid attribute name is
     included in the list used to set the attribute_names attribute of a
     GetAttributeList response payload.
     """
     payload = payloads.GetAttributeListResponsePayload()
     args = (payload, 'attribute_names', ['test-attribute-name-1', 0])
     self.assertRaisesRegexp(
         TypeError, "attribute_names must be a list of strings; "
         "item 2 has type {0}".format(type(0)), setattr, *args)
    def test_write_with_no_content(self):
        """
        Test that a GetAttributeList response payload with no ID or attribute
        names can be written to a data stream.
        """
        payload = payloads.GetAttributeListResponsePayload()
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.empty_encoding), len(stream))
        self.assertEqual(str(self.empty_encoding), str(stream))
Exemple #14
0
 def test_write_with_no_attribute_names(self):
     """
     Test that an InvalidField error is raised when a GetAttributeList
     response payload is written to a data stream with no attribute names.
     """
     payload = payloads.GetAttributeListResponsePayload(
         self.unique_identifier, None)
     args = (utils.BytearrayStream(), )
     self.assertRaisesRegex(
         exceptions.InvalidField,
         "The GetAttributeList response payload is missing the attribute "
         "names field.", payload.write, *args)
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the equality operator returns True when comparing a
        GetAttributeList response payload to a non-GetAttributeList response
        payload.
        """
        a = payloads.GetAttributeListResponsePayload(self.unique_identifier,
                                                     self.attribute_names)
        b = "invalid"

        self.assertTrue(a != b)
        self.assertTrue(b != a)
 def test_str(self):
     """
     Test that str can be applied to a GetAttributeList response payload.
     """
     payload = payloads.GetAttributeListResponsePayload(
         self.unique_identifier, self.attribute_names)
     expected = str({
         'unique_identifier': self.unique_identifier,
         'attribute_names': self.attribute_names
     })
     observed = str(payload)
     self.assertEqual(expected, observed)
    def test_write_with_no_attribute_names(self):
        """
        Test that a GetAttributeList response payload with no attribute names
        can be written to a data stream.
        """
        payload = payloads.GetAttributeListResponsePayload(
            self.unique_identifier, None)
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.encoding_sans_attribute_names), len(stream))
        self.assertEqual(str(self.encoding_sans_attribute_names), str(stream))
    def test_write(self):
        """
        Test that a GetAttributeList response payload can be written to a data
        stream.
        """
        payload = payloads.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.full_encoding), len(stream))
        self.assertEqual(str(self.full_encoding), str(stream))
Exemple #19
0
    def test_process_get_attribute_list_batch_item(self):
        uid = '00000000-1111-2222-3333-444444444444'
        names = ['Cryptographic Algorithm', 'Cryptographic Length']
        payload = payloads.GetAttributeListResponsePayload(
            unique_identifier=uid, attribute_names=names)
        batch_item = ResponseBatchItem(
            operation=Operation(OperationEnum.GET_ATTRIBUTE_LIST),
            response_payload=payload)
        result = self.client._process_get_attribute_list_batch_item(batch_item)

        self.assertIsInstance(result, GetAttributeListResult)
        self.assertEqual(uid, result.uid)
        self.assertEqual(names, result.names)
 def test_repr_with_no_content(self):
     """
     Test that repr can be applied to a GetAttributeList response payload
     with no ID or attribute names.
     """
     payload = payloads.GetAttributeListResponsePayload(None, None)
     unique_identifier = "unique_identifier={0}".format(
         payload.unique_identifier)
     attribute_names = "attribute_names={0}".format(payload.attribute_names)
     expected = "GetAttributeListResponsePayload({0}, {1})".format(
         unique_identifier, attribute_names)
     observed = repr(payload)
     self.assertEqual(expected, observed)
Exemple #21
0
    def test_read_kmip_2_0_invalid_attribute_reference(self):
        """
        Test that an InvalidKmipEncoding error is raised during the decoding
        of a GetAttributeList response payload when the wrong type is found
        for the AttributeReference structure.
        """
        payload = payloads.GetAttributeListResponsePayload()

        args = (self.invalid_attribute_reference_encoding, )
        kwargs = {"kmip_version": enums.KMIPVersion.KMIP_2_0}
        self.assertRaisesRegex(
            exceptions.InvalidKmipEncoding,
            "The GetAttributeList response payload encoding contains an "
            "invalid AttributeReference type.", payload.read, *args, **kwargs)
Exemple #22
0
    def test_read_with_no_attribute_names(self):
        """
        Test that an InvalidKmipEncoding error is raised when a
        GetAttributeList response payload is read from a data stream with no
        attribute names.
        """
        payload = payloads.GetAttributeListResponsePayload()

        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload._attribute_names)

        args = (self.encoding_sans_attribute_names, )
        self.assertRaisesRegex(
            exceptions.InvalidKmipEncoding,
            "The GetAttributeList response payload encoding is missing the "
            "attribute names.", payload.read, *args)
    def test_read_with_no_content(self):
        """
        Test that a GetAttributeList response payload with no ID or attribute
        names can be read from a data stream.
        """
        payload = payloads.GetAttributeListResponsePayload()

        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload._attribute_names)

        payload.read(self.empty_encoding)

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)
    def test_unique_identifier(self):
        """
        Test that the unique_identifier attribute of a GetAttributeList
        response payload can be properly set and retrieved.
        """
        payload = payloads.GetAttributeListResponsePayload()

        self.assertIsNone(payload.unique_identifier)
        self.assertIsNone(payload._unique_identifier)

        payload.unique_identifier = 'test-unique-identifier'

        self.assertEqual('test-unique-identifier', payload.unique_identifier)
        self.assertEqual(
            primitives.TextString(value='test-unique-identifier',
                                  tag=enums.Tags.UNIQUE_IDENTIFIER),
            payload._unique_identifier)
Exemple #25
0
    def test_write_kmip_2_0_enums(self):
        """
        Test that a GetAttributeList response payload can be written to a data
        stream encoded in the KMIP 2.0 format using AttributeReference
        enumerations.
        """
        payload = payloads.GetAttributeListResponsePayload(
            "1703250b-4d40-4de2-93a0-c494a1d4ae40", [
                "Object Group", "Application Specific Information",
                "Contact Information"
            ])
        stream = utils.BytearrayStream()
        payload.write(stream, kmip_version=enums.KMIPVersion.KMIP_2_0)

        self.assertEqual(len(self.full_encoding_with_reference_enums),
                         len(stream))
        self.assertEqual(str(self.full_encoding_with_reference_enums),
                         str(stream))
    def test_read_with_no_attribute_names(self):
        """
        Test that a GetAttributeList response payload with no attribute names
        can be read from a data stream.
        """
        payload = payloads.GetAttributeListResponsePayload()

        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload._attribute_names)

        payload.read(self.encoding_sans_attribute_names)

        self.assertEqual(self.unique_identifier, payload.unique_identifier)
        self.assertEqual(
            primitives.TextString(value=self.unique_identifier,
                                  tag=enums.Tags.UNIQUE_IDENTIFIER),
            payload._unique_identifier)
        self.assertEqual(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)
    def test_read_with_no_unique_identifier(self):
        """
        Test that a GetAttributeList response payload with no ID can be read
        from a data stream.
        """
        payload = payloads.GetAttributeListResponsePayload()

        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload._attribute_names)

        payload.read(self.encoding_sans_unique_identifier)

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(set(self.attribute_names),
                         set(payload.attribute_names))
        for attribute_name in self.attribute_names:
            self.assertIn(
                primitives.TextString(value=attribute_name,
                                      tag=enums.Tags.ATTRIBUTE_NAME),
                payload._attribute_names)
Exemple #28
0
    def test_read_kmip_2_0_structs(self):
        """
        Test that a GetAttributeList response payload can be read from a data
        stream encoded with the KMIP 2.0 format using AttributeReference
        structures.
        """
        payload = payloads.GetAttributeListResponsePayload()

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(list(), payload.attribute_names)

        payload.read(self.full_encoding_with_reference_structs,
                     kmip_version=enums.KMIPVersion.KMIP_2_0)

        self.assertEqual("1703250b-4d40-4de2-93a0-c494a1d4ae40",
                         payload.unique_identifier)
        self.assertEqual(3, len(payload.attribute_names))
        self.assertEqual([
            "Object Group", "Application Specific Information",
            "Contact Information"
        ], payload.attribute_names)
    def test_read(self):
        """
        Test that a GetAttributeList response payload can be read from a data
        stream.
        """
        payload = payloads.GetAttributeListResponsePayload()

        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload._attribute_names)

        payload.read(self.full_encoding)

        self.assertEqual(self.unique_identifier, payload.unique_identifier)
        self.assertEqual(
            primitives.TextString(value=self.unique_identifier,
                                  tag=enums.Tags.UNIQUE_IDENTIFIER),
            payload._unique_identifier)
        self.assertEqual(set(self.attribute_names),
                         set(payload.attribute_names))
        for attribute_name in self.attribute_names:
            self.assertIn(
                primitives.TextString(value=attribute_name,
                                      tag=enums.Tags.ATTRIBUTE_NAME),
                payload._attribute_names)
 def test_init(self):
     """
     Test that a GetAttributeList response payload can be constructed with
     no arguments.
     """
     payloads.GetAttributeListResponsePayload()