Add integration tests for the Modify and DeleteAttribute operations

This change adds integration tests for the client and server for
the Modify and DeleteAttribute operations, proving they work in
tandem. Minor bug fixes in the client are included to enable
correct test execution.

Partially implements #547
This commit is contained in:
Peter Hamilton 2019-12-13 15:47:01 -05:00 committed by Peter Hamilton
parent 2015cf79ca
commit ae05118804
3 changed files with 166 additions and 3 deletions

View File

@ -44,6 +44,7 @@ from kmip.core import exceptions
from kmip.core.factories.credentials import CredentialFactory
from kmip.core import objects
from kmip.core import primitives
from kmip.core.messages.contents import Authentication
from kmip.core.messages.contents import BatchCount
@ -363,7 +364,11 @@ class KMIPProxy(object):
)
batch_item = messages.RequestBatchItem(
operation=operation,
operation=primitives.Enumeration(
enums.Operation,
operation,
tag=enums.Tags.OPERATION
),
request_payload=payload
)
@ -403,7 +408,7 @@ class KMIPProxy(object):
elif batch_item.operation.value == enums.Operation.SET_ATTRIBUTE:
if not isinstance(
batch_item.response_payload,
payloads.SetAttributeRequestPayload
payloads.SetAttributeResponsePayload
):
raise exceptions.InvalidMessage(
"Invalid response payload received for the SetAttribute "
@ -412,7 +417,7 @@ class KMIPProxy(object):
elif batch_item.operation.value == enums.Operation.MODIFY_ATTRIBUTE:
if not isinstance(
batch_item.response_payload,
payloads.ModifyAttributeRequestPayload
payloads.ModifyAttributeResponsePayload
):
raise exceptions.InvalidMessage(
"Invalid response payload received for the "

View File

@ -40,6 +40,7 @@ from kmip.core.factories.attributes import AttributeFactory
from kmip.core.factories.credentials import CredentialFactory
from kmip.core.factories.secrets import SecretFactory
from kmip.core.messages import payloads
from kmip.core.misc import KeyFormatType
from kmip.core.objects import Attribute
@ -1827,3 +1828,93 @@ class TestIntegration(testtools.TestCase):
ResultReason.ITEM_NOT_FOUND,
result.result_reason.value
)
def test_modify_delete_attribute(self):
"""
Test that the KMIPProxy client can be used to set, modify, and delete
attributes for an object stored by the server.
"""
key_name = "Integration Test - Set-Modify-Delete-Attribute Key"
result = self._create_symmetric_key(key_name=key_name)
key_uuid = result.uuid
self.assertEqual(ResultStatus.SUCCESS, result.result_status.value)
self.assertEqual(ObjectType.SYMMETRIC_KEY, result.object_type)
self.assertIsInstance(key_uuid, str)
# Get the "Name" attribute for the key
result = self.client.get_attributes(
uuid=key_uuid,
attribute_names=["Name"]
)
self.assertEqual(ResultStatus.SUCCESS, result.result_status.value)
self.assertEqual(1, len(result.attributes))
self.assertEqual(
"Name",
result.attributes[0].attribute_name.value
)
self.assertEqual(0, result.attributes[0].attribute_index.value)
self.assertEqual(
"Integration Test - Set-Modify-Delete-Attribute Key",
result.attributes[0].attribute_value.name_value.value
)
# Modify the "Name" attribute for the key.
response_payload = self.client.send_request_payload(
enums.Operation.MODIFY_ATTRIBUTE,
payloads.ModifyAttributeRequestPayload(
unique_identifier=key_uuid,
attribute=self.attr_factory.create_attribute(
enums.AttributeType.NAME,
"New Name",
index=0
)
)
)
self.assertEqual(key_uuid, response_payload.unique_identifier)
self.assertEqual(
"Name",
response_payload.attribute.attribute_name.value
)
self.assertEqual(0, response_payload.attribute.attribute_index.value)
self.assertEqual(
"New Name",
response_payload.attribute.attribute_value.name_value.value
)
# Get the "Name" attribute for the key to verify it was modified
result = self.client.get_attributes(
uuid=key_uuid,
attribute_names=["Name"]
)
self.assertEqual(ResultStatus.SUCCESS, result.result_status.value)
self.assertEqual(1, len(result.attributes))
self.assertEqual(
"Name",
result.attributes[0].attribute_name.value
)
self.assertEqual(0, result.attributes[0].attribute_index.value)
self.assertEqual(
"New Name",
result.attributes[0].attribute_value.name_value.value
)
# Delete the "Name" attribute for the key.
response_payload = self.client.send_request_payload(
enums.Operation.DELETE_ATTRIBUTE,
payloads.DeleteAttributeRequestPayload(
unique_identifier=key_uuid,
attribute_name="Name",
attribute_index=0
)
)
self.assertEqual(key_uuid, response_payload.unique_identifier)
self.assertEqual(
"Name",
response_payload.attribute.attribute_name.value
)
self.assertEqual(0, response_payload.attribute.attribute_index.value)
self.assertEqual(
"New Name",
response_payload.attribute.attribute_value.name_value.value
)

View File

@ -1349,3 +1349,70 @@ class TestProxyKmipClientIntegration(testtools.TestCase):
exceptions.KmipOperationFailure, self.client.get, uid)
self.assertRaises(
exceptions.KmipOperationFailure, self.client.destroy, uid)
def test_modify_delete_attribute(self):
"""
Test that the ProxyKmipClient can modify and delete an attribute.
"""
key_id = self.client.create(
enums.CryptographicAlgorithm.IDEA,
128,
name="Symmetric Key"
)
self.assertIsInstance(key_id, str)
# Get the "Name" attribute for the key.
result_id, result_attributes = self.client.get_attributes(
uid=key_id,
attribute_names=["Name"]
)
self.assertEqual(1, len(result_attributes))
self.assertEqual("Name", result_attributes[0].attribute_name.value)
self.assertEqual(
"Symmetric Key",
result_attributes[0].attribute_value.name_value.value
)
# Modify the "Name" attribute for the key.
response_id, response_attr = self.client.modify_attribute(
unique_identifier=key_id,
attribute=self.attribute_factory.create_attribute(
enums.AttributeType.NAME,
"Modified Name",
index=0
)
)
self.assertEqual(key_id, response_id)
self.assertEqual("Name", response_attr.attribute_name.value)
self.assertEqual(0, response_attr.attribute_index.value)
self.assertEqual(
"Modified Name",
response_attr.attribute_value.name_value.value
)
# Get the "Name" attribute for the key to verify it was modified.
result_id, result_attributes = self.client.get_attributes(
uid=key_id,
attribute_names=["Name"]
)
self.assertEqual(1, len(result_attributes))
self.assertEqual("Name", result_attributes[0].attribute_name.value)
self.assertEqual(
"Modified Name",
result_attributes[0].attribute_value.name_value.value
)
# Delete the "Name" attribute for the key.
response_id, response_attr = self.client.delete_attribute(
unique_identifier=key_id,
attribute_name="Name",
attribute_index=0
)
self.assertEqual(key_id, response_id)
self.assertEqual("Name", response_attr.attribute_name.value)
self.assertEqual(0, response_attr.attribute_index.value)
self.assertEqual(
"Modified Name",
response_attr.attribute_value.name_value.value
)