Skip to content

Commit ae05118

Browse files
committed
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
1 parent 2015cf7 commit ae05118

File tree

3 files changed

+166
-3
lines changed

3 files changed

+166
-3
lines changed

kmip/services/kmip_client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from kmip.core.factories.credentials import CredentialFactory
4545

4646
from kmip.core import objects
47+
from kmip.core import primitives
4748

4849
from kmip.core.messages.contents import Authentication
4950
from kmip.core.messages.contents import BatchCount
@@ -363,7 +364,11 @@ def send_request_payload(self, operation, payload, credential=None):
363364
)
364365

365366
batch_item = messages.RequestBatchItem(
366-
operation=operation,
367+
operation=primitives.Enumeration(
368+
enums.Operation,
369+
operation,
370+
tag=enums.Tags.OPERATION
371+
),
367372
request_payload=payload
368373
)
369374

@@ -403,7 +408,7 @@ def send_request_payload(self, operation, payload, credential=None):
403408
elif batch_item.operation.value == enums.Operation.SET_ATTRIBUTE:
404409
if not isinstance(
405410
batch_item.response_payload,
406-
payloads.SetAttributeRequestPayload
411+
payloads.SetAttributeResponsePayload
407412
):
408413
raise exceptions.InvalidMessage(
409414
"Invalid response payload received for the SetAttribute "
@@ -412,7 +417,7 @@ def send_request_payload(self, operation, payload, credential=None):
412417
elif batch_item.operation.value == enums.Operation.MODIFY_ATTRIBUTE:
413418
if not isinstance(
414419
batch_item.response_payload,
415-
payloads.ModifyAttributeRequestPayload
420+
payloads.ModifyAttributeResponsePayload
416421
):
417422
raise exceptions.InvalidMessage(
418423
"Invalid response payload received for the "

kmip/tests/integration/services/test_integration.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from kmip.core.factories.credentials import CredentialFactory
4141
from kmip.core.factories.secrets import SecretFactory
4242

43+
from kmip.core.messages import payloads
4344
from kmip.core.misc import KeyFormatType
4445

4546
from kmip.core.objects import Attribute
@@ -1827,3 +1828,93 @@ def test_split_key_register_get_destroy(self):
18271828
ResultReason.ITEM_NOT_FOUND,
18281829
result.result_reason.value
18291830
)
1831+
1832+
def test_modify_delete_attribute(self):
1833+
"""
1834+
Test that the KMIPProxy client can be used to set, modify, and delete
1835+
attributes for an object stored by the server.
1836+
"""
1837+
key_name = "Integration Test - Set-Modify-Delete-Attribute Key"
1838+
result = self._create_symmetric_key(key_name=key_name)
1839+
key_uuid = result.uuid
1840+
1841+
self.assertEqual(ResultStatus.SUCCESS, result.result_status.value)
1842+
self.assertEqual(ObjectType.SYMMETRIC_KEY, result.object_type)
1843+
self.assertIsInstance(key_uuid, str)
1844+
1845+
# Get the "Name" attribute for the key
1846+
result = self.client.get_attributes(
1847+
uuid=key_uuid,
1848+
attribute_names=["Name"]
1849+
)
1850+
self.assertEqual(ResultStatus.SUCCESS, result.result_status.value)
1851+
self.assertEqual(1, len(result.attributes))
1852+
self.assertEqual(
1853+
"Name",
1854+
result.attributes[0].attribute_name.value
1855+
)
1856+
self.assertEqual(0, result.attributes[0].attribute_index.value)
1857+
self.assertEqual(
1858+
"Integration Test - Set-Modify-Delete-Attribute Key",
1859+
result.attributes[0].attribute_value.name_value.value
1860+
)
1861+
1862+
# Modify the "Name" attribute for the key.
1863+
response_payload = self.client.send_request_payload(
1864+
enums.Operation.MODIFY_ATTRIBUTE,
1865+
payloads.ModifyAttributeRequestPayload(
1866+
unique_identifier=key_uuid,
1867+
attribute=self.attr_factory.create_attribute(
1868+
enums.AttributeType.NAME,
1869+
"New Name",
1870+
index=0
1871+
)
1872+
)
1873+
)
1874+
self.assertEqual(key_uuid, response_payload.unique_identifier)
1875+
self.assertEqual(
1876+
"Name",
1877+
response_payload.attribute.attribute_name.value
1878+
)
1879+
self.assertEqual(0, response_payload.attribute.attribute_index.value)
1880+
self.assertEqual(
1881+
"New Name",
1882+
response_payload.attribute.attribute_value.name_value.value
1883+
)
1884+
1885+
# Get the "Name" attribute for the key to verify it was modified
1886+
result = self.client.get_attributes(
1887+
uuid=key_uuid,
1888+
attribute_names=["Name"]
1889+
)
1890+
self.assertEqual(ResultStatus.SUCCESS, result.result_status.value)
1891+
self.assertEqual(1, len(result.attributes))
1892+
self.assertEqual(
1893+
"Name",
1894+
result.attributes[0].attribute_name.value
1895+
)
1896+
self.assertEqual(0, result.attributes[0].attribute_index.value)
1897+
self.assertEqual(
1898+
"New Name",
1899+
result.attributes[0].attribute_value.name_value.value
1900+
)
1901+
1902+
# Delete the "Name" attribute for the key.
1903+
response_payload = self.client.send_request_payload(
1904+
enums.Operation.DELETE_ATTRIBUTE,
1905+
payloads.DeleteAttributeRequestPayload(
1906+
unique_identifier=key_uuid,
1907+
attribute_name="Name",
1908+
attribute_index=0
1909+
)
1910+
)
1911+
self.assertEqual(key_uuid, response_payload.unique_identifier)
1912+
self.assertEqual(
1913+
"Name",
1914+
response_payload.attribute.attribute_name.value
1915+
)
1916+
self.assertEqual(0, response_payload.attribute.attribute_index.value)
1917+
self.assertEqual(
1918+
"New Name",
1919+
response_payload.attribute.attribute_value.name_value.value
1920+
)

kmip/tests/integration/services/test_proxykmipclient.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,3 +1349,70 @@ def test_split_key_register_get_destroy(self):
13491349
exceptions.KmipOperationFailure, self.client.get, uid)
13501350
self.assertRaises(
13511351
exceptions.KmipOperationFailure, self.client.destroy, uid)
1352+
1353+
def test_modify_delete_attribute(self):
1354+
"""
1355+
Test that the ProxyKmipClient can modify and delete an attribute.
1356+
"""
1357+
key_id = self.client.create(
1358+
enums.CryptographicAlgorithm.IDEA,
1359+
128,
1360+
name="Symmetric Key"
1361+
)
1362+
1363+
self.assertIsInstance(key_id, str)
1364+
1365+
# Get the "Name" attribute for the key.
1366+
result_id, result_attributes = self.client.get_attributes(
1367+
uid=key_id,
1368+
attribute_names=["Name"]
1369+
)
1370+
self.assertEqual(1, len(result_attributes))
1371+
self.assertEqual("Name", result_attributes[0].attribute_name.value)
1372+
self.assertEqual(
1373+
"Symmetric Key",
1374+
result_attributes[0].attribute_value.name_value.value
1375+
)
1376+
1377+
# Modify the "Name" attribute for the key.
1378+
response_id, response_attr = self.client.modify_attribute(
1379+
unique_identifier=key_id,
1380+
attribute=self.attribute_factory.create_attribute(
1381+
enums.AttributeType.NAME,
1382+
"Modified Name",
1383+
index=0
1384+
)
1385+
)
1386+
self.assertEqual(key_id, response_id)
1387+
self.assertEqual("Name", response_attr.attribute_name.value)
1388+
self.assertEqual(0, response_attr.attribute_index.value)
1389+
self.assertEqual(
1390+
"Modified Name",
1391+
response_attr.attribute_value.name_value.value
1392+
)
1393+
1394+
# Get the "Name" attribute for the key to verify it was modified.
1395+
result_id, result_attributes = self.client.get_attributes(
1396+
uid=key_id,
1397+
attribute_names=["Name"]
1398+
)
1399+
self.assertEqual(1, len(result_attributes))
1400+
self.assertEqual("Name", result_attributes[0].attribute_name.value)
1401+
self.assertEqual(
1402+
"Modified Name",
1403+
result_attributes[0].attribute_value.name_value.value
1404+
)
1405+
1406+
# Delete the "Name" attribute for the key.
1407+
response_id, response_attr = self.client.delete_attribute(
1408+
unique_identifier=key_id,
1409+
attribute_name="Name",
1410+
attribute_index=0
1411+
)
1412+
self.assertEqual(key_id, response_id)
1413+
self.assertEqual("Name", response_attr.attribute_name.value)
1414+
self.assertEqual(0, response_attr.attribute_index.value)
1415+
self.assertEqual(
1416+
"Modified Name",
1417+
response_attr.attribute_value.name_value.value
1418+
)

0 commit comments

Comments
 (0)