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.")
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)

View File

@ -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)
)

View File

@ -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)

View File

@ -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))

View File

@ -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)