Add integration tests for Locate using new attributes

This change adds integration tests that verify that objects can
be found by Locate when filtering off of the new ObjectGroup and
ApplicationSpecificInformation attributes. Some minor tweaks to
the database attribute models are included to simplify usage.
This commit is contained in:
Peter Hamilton 2019-10-11 15:12:38 -04:00 committed by Peter Hamilton
parent 009e8cecc9
commit cd1079afd5
5 changed files with 86 additions and 32 deletions

View File

@ -1831,10 +1831,12 @@ class ApplicationSpecificInformation(sql.Base):
raise TypeError("The application data must be a string.") raise TypeError("The application data must be a string.")
def __repr__(self): def __repr__(self):
application_namespace = "application_namespace={}".format( application_namespace = "application_namespace='{}'".format(
self.application_namespace self.application_namespace
) )
application_data = "application_data={}".format(self.application_data) application_data = "application_data='{}'".format(
self.application_data
)
return "ApplicationSpecificInformation({})".format( return "ApplicationSpecificInformation({})".format(
", ".join( ", ".join(
@ -1877,8 +1879,7 @@ class ObjectGroup(sql.Base):
_object_group = sqlalchemy.Column( _object_group = sqlalchemy.Column(
"object_group", "object_group",
sqlalchemy.String, sqlalchemy.String,
nullable=False, nullable=False
unique=True
) )
managed_objects = sqlalchemy.orm.relationship( managed_objects = sqlalchemy.orm.relationship(
"ManagedObject", "ManagedObject",
@ -1909,7 +1910,7 @@ class ObjectGroup(sql.Base):
raise TypeError("The object group must be a string.") raise TypeError("The object group must be a string.")
def __repr__(self): def __repr__(self):
object_group = "object_group={}".format(self.object_group) object_group = "object_group='{}'".format(self.object_group)
return "ObjectGroup({})".format(object_group) return "ObjectGroup({})".format(object_group)

View File

@ -799,6 +799,8 @@ class KmipEngine(object):
) )
elif attribute_name == "Object Group": elif attribute_name == "Object Group":
for value in attribute_value: for value in attribute_value:
# TODO (peterhamilton) Enforce uniqueness of object groups
# to avoid wasted space.
managed_object.object_groups.append( managed_object.object_groups.append(
objects.ObjectGroup(object_group=value.value) objects.ObjectGroup(object_group=value.value)
) )

View File

@ -85,34 +85,54 @@ class TestIntegration(testtools.TestCase):
:return: returns the result of the "create key" operation as :return: returns the result of the "create key" operation as
provided by the KMIP appliance provided by the KMIP appliance
""" """
object_type = ObjectType.SYMMETRIC_KEY cryptographic_algorithm = self.attr_factory.create_attribute(
attribute_type = AttributeType.CRYPTOGRAPHIC_ALGORITHM enums.AttributeType.CRYPTOGRAPHIC_ALGORITHM,
algorithm = self.attr_factory.create_attribute(attribute_type, enums.CryptographicAlgorithm.AES
CryptoAlgorithmEnum.AES) )
mask_flags = [CryptographicUsageMask.ENCRYPT, cryptographic_usage_mask = self.attr_factory.create_attribute(
CryptographicUsageMask.DECRYPT] enums.AttributeType.CRYPTOGRAPHIC_USAGE_MASK,
attribute_type = AttributeType.CRYPTOGRAPHIC_USAGE_MASK [
usage_mask = self.attr_factory.create_attribute(attribute_type, enums.CryptographicUsageMask.ENCRYPT,
mask_flags) enums.CryptographicUsageMask.DECRYPT
key_length = 128 ]
attribute_type = AttributeType.CRYPTOGRAPHIC_LENGTH )
key_length_obj = self.attr_factory.create_attribute(attribute_type, cryptographic_length = self.attr_factory.create_attribute(
key_length) enums.AttributeType.CRYPTOGRAPHIC_LENGTH,
name = Attribute.AttributeName('Name') 128
)
if key_name is None: 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) attributes = [
cryptographic_algorithm,
name_type = Name.NameType(NameType.UNINTERPRETED_TEXT_STRING) cryptographic_usage_mask,
value = Name(name_value=name_value, name_type=name_type) cryptographic_length,
name = Attribute(attribute_name=name, attribute_value=value) name,
attributes = [algorithm, usage_mask, key_length_obj, name] object_group,
application_specific_information
]
template_attribute = TemplateAttribute(attributes=attributes) template_attribute = TemplateAttribute(attributes=attributes)
return self.client.create(object_type, template_attribute, return self.client.create(
credential=None) enums.ObjectType.SYMMETRIC_KEY,
template_attribute,
credential=None
)
def _create_key_pair(self, key_name=None): def _create_key_pair(self, key_name=None):
""" """
@ -1595,6 +1615,35 @@ class TestIntegration(testtools.TestCase):
) )
self.assertEqual(0, len(result.uuids)) 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. # Test locating keys using offset and maximum item constraints.
result = self.client.locate(offset_items=1) result = self.client.locate(offset_items=1)

View File

@ -101,8 +101,8 @@ class TestApplicationSpecificInformation(testtools.TestCase):
) )
args = [ args = [
"application_namespace={}".format("ssl"), "application_namespace='{}'".format("ssl"),
"application_data={}".format("www.example.com") "application_data='{}'".format("www.example.com")
] ]
expected = "ApplicationSpecificInformation({})".format(", ".join(args)) expected = "ApplicationSpecificInformation({})".format(", ".join(args))

View File

@ -70,7 +70,9 @@ class TestObjectGroup(testtools.TestCase):
""" """
object_group = objects.ObjectGroup(object_group="Group1") 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) observed = repr(object_group)
self.assertEqual(expected, observed) self.assertEqual(expected, observed)