Skip to content

Commit

Permalink
Add integration tests for the Modify and DeleteAttribute operations
Browse files Browse the repository at this point in the history
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
  • Loading branch information
PeterHamilton committed Dec 13, 2019
1 parent 2015cf7 commit ae05118
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 3 deletions.
11 changes: 8 additions & 3 deletions kmip/services/kmip_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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
Expand Down Expand Up @@ -363,7 +364,11 @@ def send_request_payload(self, operation, payload, credential=None):
)

batch_item = messages.RequestBatchItem(
operation=operation,
operation=primitives.Enumeration(
enums.Operation,
operation,
tag=enums.Tags.OPERATION
),
request_payload=payload
)

Expand Down Expand Up @@ -403,7 +408,7 @@ def send_request_payload(self, operation, payload, credential=None):
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 "
Expand All @@ -412,7 +417,7 @@ def send_request_payload(self, operation, payload, credential=None):
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 "
Expand Down
91 changes: 91 additions & 0 deletions kmip/tests/integration/services/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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
Expand Down Expand Up @@ -1827,3 +1828,93 @@ def test_split_key_register_get_destroy(self):
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
)
67 changes: 67 additions & 0 deletions kmip/tests/integration/services/test_proxykmipclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,3 +1349,70 @@ def test_split_key_register_get_destroy(self):
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
)

0 comments on commit ae05118

Please sign in to comment.