diff --git a/kmip/pie/objects.py b/kmip/pie/objects.py index 6ce62b0..023214b 100644 --- a/kmip/pie/objects.py +++ b/kmip/pie/objects.py @@ -1831,10 +1831,12 @@ class ApplicationSpecificInformation(sql.Base): raise TypeError("The application data must be a string.") def __repr__(self): - application_namespace = "application_namespace={}".format( + application_namespace = "application_namespace='{}'".format( self.application_namespace ) - application_data = "application_data={}".format(self.application_data) + application_data = "application_data='{}'".format( + self.application_data + ) return "ApplicationSpecificInformation({})".format( ", ".join( @@ -1877,8 +1879,7 @@ class ObjectGroup(sql.Base): _object_group = sqlalchemy.Column( "object_group", sqlalchemy.String, - nullable=False, - unique=True + nullable=False ) managed_objects = sqlalchemy.orm.relationship( "ManagedObject", @@ -1909,7 +1910,7 @@ class ObjectGroup(sql.Base): raise TypeError("The object group must be a string.") def __repr__(self): - object_group = "object_group={}".format(self.object_group) + object_group = "object_group='{}'".format(self.object_group) return "ObjectGroup({})".format(object_group) diff --git a/kmip/services/server/engine.py b/kmip/services/server/engine.py index 5ddb19b..c2f2a17 100644 --- a/kmip/services/server/engine.py +++ b/kmip/services/server/engine.py @@ -799,6 +799,8 @@ class KmipEngine(object): ) elif attribute_name == "Object Group": for value in attribute_value: + # TODO (peterhamilton) Enforce uniqueness of object groups + # to avoid wasted space. managed_object.object_groups.append( objects.ObjectGroup(object_group=value.value) ) diff --git a/kmip/tests/integration/services/test_integration.py b/kmip/tests/integration/services/test_integration.py index c2866d9..3acd3e9 100644 --- a/kmip/tests/integration/services/test_integration.py +++ b/kmip/tests/integration/services/test_integration.py @@ -85,34 +85,54 @@ class TestIntegration(testtools.TestCase): :return: returns the result of the "create key" operation as provided by the KMIP appliance """ - object_type = ObjectType.SYMMETRIC_KEY - attribute_type = AttributeType.CRYPTOGRAPHIC_ALGORITHM - algorithm = self.attr_factory.create_attribute(attribute_type, - CryptoAlgorithmEnum.AES) - mask_flags = [CryptographicUsageMask.ENCRYPT, - CryptographicUsageMask.DECRYPT] - attribute_type = AttributeType.CRYPTOGRAPHIC_USAGE_MASK - usage_mask = self.attr_factory.create_attribute(attribute_type, - mask_flags) - key_length = 128 - attribute_type = AttributeType.CRYPTOGRAPHIC_LENGTH - key_length_obj = self.attr_factory.create_attribute(attribute_type, - key_length) - name = Attribute.AttributeName('Name') - + cryptographic_algorithm = self.attr_factory.create_attribute( + enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM, + enums.CryptographicAlgorithm.AES + ) + cryptographic_usage_mask = self.attr_factory.create_attribute( + enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK, + [ + enums.CryptographicUsageMask.ENCRYPT, + enums.CryptographicUsageMask.DECRYPT + ] + ) + cryptographic_length = self.attr_factory.create_attribute( + enums.AttributeType.CRYPTOGRAPHIC_LENGTH, + 128 + ) if key_name is None: - key_name = 'Integration Test - Key' + key_name = "Integration Test - Key" + name = self.attr_factory.create_attribute( + enums.AttributeType.NAME, + key_name + ) + object_group = self.attr_factory.create_attribute( + enums.AttributeType.OBJECT_GROUP, + "IntegrationTestKeys" + ) + application_specific_information = self.attr_factory.create_attribute( + enums.AttributeType.APPLICATION_SPECIFIC_INFORMATION, + { + "application_namespace": "ssl", + "application_data": "www.example.com" + } + ) - name_value = Name.NameValue(key_name) - - name_type = Name.NameType(NameType.UNINTERPRETED_TEXT_STRING) - value = Name(name_value=name_value, name_type=name_type) - name = Attribute(attribute_name=name, attribute_value=value) - attributes = [algorithm, usage_mask, key_length_obj, name] + attributes = [ + cryptographic_algorithm, + cryptographic_usage_mask, + cryptographic_length, + name, + object_group, + application_specific_information + ] template_attribute = TemplateAttribute(attributes=attributes) - return self.client.create(object_type, template_attribute, - credential=None) + return self.client.create( + enums.ObjectType.SYMMETRIC_KEY, + template_attribute, + credential=None + ) def _create_key_pair(self, key_name=None): """ @@ -1595,6 +1615,35 @@ class TestIntegration(testtools.TestCase): ) self.assertEqual(0, len(result.uuids)) + # Test locating each key by its application specific information. + result = self.client.locate( + attributes=[ + self.attr_factory.create_attribute( + enums.AttributeType.APPLICATION_SPECIFIC_INFORMATION, + { + "application_namespace": "ssl", + "application_data": "www.example.com" + } + ) + ] + ) + self.assertEqual(2, len(result.uuids)) + self.assertIn(uid_a, result.uuids) + self.assertIn(uid_b, result.uuids) + + # Test locating each key by its object group. + result = self.client.locate( + attributes=[ + self.attr_factory.create_attribute( + enums.AttributeType.OBJECT_GROUP, + "IntegrationTestKeys" + ) + ] + ) + self.assertEqual(2, len(result.uuids)) + self.assertIn(uid_a, result.uuids) + self.assertIn(uid_b, result.uuids) + # Test locating keys using offset and maximum item constraints. result = self.client.locate(offset_items=1) diff --git a/kmip/tests/unit/pie/objects/test_application_specific_information.py b/kmip/tests/unit/pie/objects/test_application_specific_information.py index 749b7a3..10385c1 100644 --- a/kmip/tests/unit/pie/objects/test_application_specific_information.py +++ b/kmip/tests/unit/pie/objects/test_application_specific_information.py @@ -101,8 +101,8 @@ class TestApplicationSpecificInformation(testtools.TestCase): ) args = [ - "application_namespace={}".format("ssl"), - "application_data={}".format("www.example.com") + "application_namespace='{}'".format("ssl"), + "application_data='{}'".format("www.example.com") ] expected = "ApplicationSpecificInformation({})".format(", ".join(args)) diff --git a/kmip/tests/unit/pie/objects/test_object_group.py b/kmip/tests/unit/pie/objects/test_object_group.py index a5efab2..ebf9c6c 100644 --- a/kmip/tests/unit/pie/objects/test_object_group.py +++ b/kmip/tests/unit/pie/objects/test_object_group.py @@ -70,7 +70,9 @@ class TestObjectGroup(testtools.TestCase): """ object_group = objects.ObjectGroup(object_group="Group1") - expected = "ObjectGroup({})".format("object_group={}".format("Group1")) + expected = "ObjectGroup({})".format( + "object_group='{}'".format("Group1") + ) observed = repr(object_group) self.assertEqual(expected, observed)