diff --git a/kmip/core/factories/attribute_values.py b/kmip/core/factories/attribute_values.py index 20d6a5d..ea15437 100644 --- a/kmip/core/factories/attribute_values.py +++ b/kmip/core/factories/attribute_values.py @@ -275,11 +275,11 @@ class AttributeValueFactory(object): def _create_application_specific_information(self, info): if info: - for k,v in info.items(): - return attributes.ApplicationSpecificInformation( - k, - v - ) + print(info.get("application_namespace")) + return attributes.ApplicationSpecificInformation( + application_namespace=info.get("application_namespace"), + application_data=info.get("application_data") + ) else: return attributes.ApplicationSpecificInformation() diff --git a/kmip/pie/client.py b/kmip/pie/client.py index 92ec146..1dbdaea 100644 --- a/kmip/pie/client.py +++ b/kmip/pie/client.py @@ -560,16 +560,11 @@ class ProxyKmipClient(object): if hasattr(managed_object, '_application_specific_informations'): if managed_object._application_specific_informations: - for attr in managed_object._application_specific_informations: - app_dict = {} - app_dict[attr] = managed_object._application_specific_informations[attr] - attribute = self.attribute_factory.create_attribute( - name=enums.AttributeType.APPLICATION_SPECIFIC_INFORMATION, - value=app_dict, - index=1 - ) - object_attributes.append(attribute) - + attribute = self.attribute_factory.create_attribute( + enums.AttributeType.APPLICATION_SPECIFIC_INFORMATION, + managed_object._application_specific_informations + ) + object_attributes.append(attribute) template = cobjects.TemplateAttribute(attributes=object_attributes) object_type = managed_object.object_type # Register the managed object and handle the results diff --git a/kmip/tests/integration/services/test_proxykmipclient.py b/kmip/tests/integration/services/test_proxykmipclient.py index 62d7988..fbc13da 100644 --- a/kmip/tests/integration/services/test_proxykmipclient.py +++ b/kmip/tests/integration/services/test_proxykmipclient.py @@ -198,16 +198,37 @@ class TestProxyKmipClientIntegration(testtools.TestCase): (b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E' b'\x0F'), app_specific_info={ - 'application_namespace': 'Testing', - 'application_data': 'Testing2' - } + 'application_namespace': 'Testing', + 'application_data': 'Testing2' + } ) key_id = self.client.register(key) - result = self.client.get(key_id) - app_specific_info = result.app_specific_info + attribute_list = self.client.get_attribute_list(key_id) + self.assertIn('Application Specific Information', attribute_list) + result_id, attribute_list = self.client.get_attributes( + uid=key_id, + attribute_names=['Application Specific Information'] + ) + self.assertEqual(key_id, result_id) + self.assertEqual(1, len(attribute_list)) + + attribute = attribute_list[0] + self.assertEqual( + 'Application Specific Information', + attribute.attribute_name.value + ) + print(attribute.attribute_value) + self.assertEqual( + 'Testing', + attribute.attribute_value.application_namespace + ) + self.assertEqual( + 'Testing2', + attribute.attribute_value.application_data + ) + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id) self.client.destroy(key_id) - def test_asymmetric_key_pair_create_get_destroy(self): """ @@ -514,6 +535,63 @@ class TestProxyKmipClientIntegration(testtools.TestCase): exceptions.KmipOperationFailure, self.client.get, uid) self.assertRaises( exceptions.KmipOperationFailure, self.client.destroy, uid) + + def test_secret_data_register_get_destroy_app_specific(self): + """ + Test that the ProxyKmipClient can register, retrieve, and destroy a + secret with the app specific info field. + """ + # Secret encoding obtained from Section 3.1.5 of the KMIP 1.1 test + # documentation. + secret = objects.SecretData( + b'\x53\x65\x63\x72\x65\x74\x50\x61\x73\x73\x77\x6F\x72\x64', + enums.SecretDataType.PASSWORD, + app_specific_info={ + 'application_namespace': 'Testing', + 'application_data': 'Testing2' + } + ) + + uid = self.client.register(secret) + self.assertIsInstance(uid, six.string_types) + + try: + result = self.client.get(uid) + self.assertIsInstance(result, objects.SecretData) + self.assertEqual( + result, secret, "expected {0}\nobserved {1}".format( + result, secret)) + attribute_list = self.client.get_attribute_list(uid) + self.assertIn('Application Specific Information', attribute_list) + result_id, attribute_list = self.client.get_attributes( + uid=uid, + attribute_names=['Application Specific Information'] + ) + self.assertEqual(uid, result_id) + self.assertEqual(1, len(attribute_list)) + + attribute = attribute_list[0] + self.assertEqual( + 'Application Specific Information', + attribute.attribute_name.value + ) + print(attribute.attribute_value) + self.assertEqual( + 'Testing', + attribute.attribute_value.application_namespace + ) + self.assertEqual( + 'Testing2', + attribute.attribute_value.application_data + ) + + finally: + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, uid) + self.client.destroy(uid) + self.assertRaises( + exceptions.KmipOperationFailure, self.client.get, uid) + self.assertRaises( + exceptions.KmipOperationFailure, self.client.destroy, uid) def test_opaque_object_register_get_destroy(self): """