mirror of https://github.com/OpenKMIP/PyKMIP.git
Update the Query payloads
This change upgrades the Query payloads, fixing error messages, comments, local variables, and internal payload structure to bring Query support up to KMIP 1.4 standards, in addition to compliance with the current payload format. The corresponding unit test suite has been completely rewritten to reflect these changes. This change prepares the Query payloads for future updates to support KMIP 2.0.
This commit is contained in:
parent
b968378eb8
commit
314dd8761e
File diff suppressed because it is too large
Load Diff
|
@ -39,8 +39,6 @@ from kmip.core.messages import messages
|
|||
|
||||
from kmip.core.messages import payloads
|
||||
|
||||
from kmip.core import misc
|
||||
|
||||
from kmip.pie import factory
|
||||
from kmip.pie import objects
|
||||
from kmip.pie import sqltypes
|
||||
|
@ -1917,7 +1915,7 @@ class KmipEngine(object):
|
|||
def _process_query(self, payload):
|
||||
self._logger.info("Processing operation: Query")
|
||||
|
||||
queries = [x.value for x in payload.query_functions]
|
||||
queries = payload.query_functions
|
||||
|
||||
operations = list()
|
||||
objects = list()
|
||||
|
@ -1928,38 +1926,38 @@ class KmipEngine(object):
|
|||
|
||||
if enums.QueryFunction.QUERY_OPERATIONS in queries:
|
||||
operations = list([
|
||||
contents.Operation(enums.Operation.CREATE),
|
||||
contents.Operation(enums.Operation.CREATE_KEY_PAIR),
|
||||
contents.Operation(enums.Operation.REGISTER),
|
||||
contents.Operation(enums.Operation.DERIVE_KEY),
|
||||
contents.Operation(enums.Operation.LOCATE),
|
||||
contents.Operation(enums.Operation.GET),
|
||||
contents.Operation(enums.Operation.GET_ATTRIBUTES),
|
||||
contents.Operation(enums.Operation.GET_ATTRIBUTE_LIST),
|
||||
contents.Operation(enums.Operation.ACTIVATE),
|
||||
contents.Operation(enums.Operation.REVOKE),
|
||||
contents.Operation(enums.Operation.DESTROY),
|
||||
contents.Operation(enums.Operation.QUERY)
|
||||
enums.Operation.CREATE,
|
||||
enums.Operation.CREATE_KEY_PAIR,
|
||||
enums.Operation.REGISTER,
|
||||
enums.Operation.DERIVE_KEY,
|
||||
enums.Operation.LOCATE,
|
||||
enums.Operation.GET,
|
||||
enums.Operation.GET_ATTRIBUTES,
|
||||
enums.Operation.GET_ATTRIBUTE_LIST,
|
||||
enums.Operation.ACTIVATE,
|
||||
enums.Operation.REVOKE,
|
||||
enums.Operation.DESTROY,
|
||||
enums.Operation.QUERY
|
||||
])
|
||||
|
||||
if self._protocol_version >= contents.ProtocolVersion(1, 1):
|
||||
operations.extend([
|
||||
contents.Operation(enums.Operation.DISCOVER_VERSIONS)
|
||||
enums.Operation.DISCOVER_VERSIONS
|
||||
])
|
||||
if self._protocol_version >= contents.ProtocolVersion(1, 2):
|
||||
operations.extend([
|
||||
contents.Operation(enums.Operation.ENCRYPT),
|
||||
contents.Operation(enums.Operation.DECRYPT),
|
||||
contents.Operation(enums.Operation.SIGN),
|
||||
contents.Operation(enums.Operation.SIGNATURE_VERIFY),
|
||||
contents.Operation(enums.Operation.MAC)
|
||||
enums.Operation.ENCRYPT,
|
||||
enums.Operation.DECRYPT,
|
||||
enums.Operation.SIGN,
|
||||
enums.Operation.SIGNATURE_VERIFY,
|
||||
enums.Operation.MAC
|
||||
])
|
||||
|
||||
if enums.QueryFunction.QUERY_OBJECTS in queries:
|
||||
objects = list()
|
||||
if enums.QueryFunction.QUERY_SERVER_INFORMATION in queries:
|
||||
vendor_identification = misc.VendorIdentification(
|
||||
"PyKMIP {0} Software Server".format(kmip.__version__)
|
||||
vendor_identification = "PyKMIP {0} Software Server".format(
|
||||
kmip.__version__
|
||||
)
|
||||
server_information = None
|
||||
if enums.QueryFunction.QUERY_APPLICATION_NAMESPACES in queries:
|
||||
|
|
|
@ -32,7 +32,7 @@ from kmip.core.enums import OpaqueDataType
|
|||
from kmip.core.enums import SecretDataType
|
||||
from kmip.core.enums import ResultStatus
|
||||
from kmip.core.enums import ResultReason
|
||||
from kmip.core.enums import QueryFunction as QueryFunctionEnum
|
||||
from kmip.core.enums import QueryFunction
|
||||
|
||||
from kmip.core.factories.attributes import AttributeFactory
|
||||
from kmip.core.factories.credentials import CredentialFactory
|
||||
|
@ -46,8 +46,6 @@ from kmip.core.objects import KeyMaterial
|
|||
from kmip.core.objects import KeyValue
|
||||
from kmip.core.objects import TemplateAttribute
|
||||
|
||||
from kmip.core.misc import QueryFunction
|
||||
|
||||
from kmip.core.secrets import SymmetricKey
|
||||
from kmip.core.secrets import PrivateKey
|
||||
from kmip.core.secrets import PublicKey
|
||||
|
@ -314,19 +312,16 @@ class TestIntegration(TestCase):
|
|||
|
||||
def test_query(self):
|
||||
# Build query function list, asking for all server data.
|
||||
query_functions = list()
|
||||
query_functions.append(
|
||||
QueryFunction(QueryFunctionEnum.QUERY_OPERATIONS))
|
||||
query_functions.append(
|
||||
QueryFunction(QueryFunctionEnum.QUERY_OBJECTS))
|
||||
query_functions.append(
|
||||
QueryFunction(QueryFunctionEnum.QUERY_SERVER_INFORMATION))
|
||||
query_functions.append(
|
||||
QueryFunction(QueryFunctionEnum.QUERY_APPLICATION_NAMESPACES))
|
||||
query_functions.append(
|
||||
QueryFunction(QueryFunctionEnum.QUERY_EXTENSION_LIST))
|
||||
query_functions.append(
|
||||
QueryFunction(QueryFunctionEnum.QUERY_EXTENSION_MAP))
|
||||
query_functions = list(
|
||||
[
|
||||
QueryFunction.QUERY_OPERATIONS,
|
||||
QueryFunction.QUERY_OBJECTS,
|
||||
QueryFunction.QUERY_SERVER_INFORMATION,
|
||||
QueryFunction.QUERY_APPLICATION_NAMESPACES,
|
||||
QueryFunction.QUERY_EXTENSION_LIST,
|
||||
QueryFunction.QUERY_EXTENSION_MAP
|
||||
]
|
||||
)
|
||||
|
||||
result = self.client.query(query_functions=query_functions)
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6421,82 +6421,80 @@ class TestKmipEngine(testtools.TestCase):
|
|||
e._logger = mock.MagicMock()
|
||||
e._protocol_version = contents.ProtocolVersion(1, 0)
|
||||
|
||||
payload = payloads.QueryRequestPayload([
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS),
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_OBJECTS),
|
||||
misc.QueryFunction(
|
||||
enums.QueryFunction.QUERY_SERVER_INFORMATION
|
||||
),
|
||||
misc.QueryFunction(
|
||||
enums.QueryFunction.QUERY_APPLICATION_NAMESPACES
|
||||
),
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_LIST),
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_MAP)
|
||||
])
|
||||
payload = payloads.QueryRequestPayload(
|
||||
query_functions=[
|
||||
enums.QueryFunction.QUERY_OPERATIONS,
|
||||
enums.QueryFunction.QUERY_OBJECTS,
|
||||
enums.QueryFunction.QUERY_SERVER_INFORMATION,
|
||||
enums.QueryFunction.QUERY_APPLICATION_NAMESPACES,
|
||||
enums.QueryFunction.QUERY_EXTENSION_LIST,
|
||||
enums.QueryFunction.QUERY_EXTENSION_MAP
|
||||
]
|
||||
)
|
||||
|
||||
result = e._process_query(payload)
|
||||
|
||||
e._logger.info.assert_called_once_with("Processing operation: Query")
|
||||
self.assertIsInstance(result, payloads.QueryResponsePayload)
|
||||
self.assertIsNotNone(result.operations)
|
||||
self.assertIsInstance(result.operations, list)
|
||||
self.assertEqual(12, len(result.operations))
|
||||
self.assertEqual(
|
||||
enums.Operation.CREATE,
|
||||
result.operations[0].value
|
||||
result.operations[0]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.CREATE_KEY_PAIR,
|
||||
result.operations[1].value
|
||||
result.operations[1]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.REGISTER,
|
||||
result.operations[2].value
|
||||
result.operations[2]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.DERIVE_KEY,
|
||||
result.operations[3].value
|
||||
result.operations[3]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.LOCATE,
|
||||
result.operations[4].value
|
||||
result.operations[4]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.GET,
|
||||
result.operations[5].value
|
||||
result.operations[5]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.GET_ATTRIBUTES,
|
||||
result.operations[6].value
|
||||
result.operations[6]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.GET_ATTRIBUTE_LIST,
|
||||
result.operations[7].value
|
||||
result.operations[7]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.ACTIVATE,
|
||||
result.operations[8].value
|
||||
result.operations[8]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.REVOKE,
|
||||
result.operations[9].value
|
||||
result.operations[9]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.DESTROY,
|
||||
result.operations[10].value
|
||||
result.operations[10]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.QUERY,
|
||||
result.operations[11].value
|
||||
result.operations[11]
|
||||
)
|
||||
self.assertEqual(list(), result.object_types)
|
||||
self.assertIsNone(result.object_types)
|
||||
self.assertIsNotNone(result.vendor_identification)
|
||||
self.assertEqual(
|
||||
"PyKMIP {0} Software Server".format(kmip.__version__),
|
||||
result.vendor_identification.value
|
||||
result.vendor_identification
|
||||
)
|
||||
self.assertIsNone(result.server_information)
|
||||
self.assertEqual(list(), result.application_namespaces)
|
||||
self.assertEqual(list(), result.extension_information)
|
||||
self.assertIsNone(result.application_namespaces)
|
||||
self.assertIsNone(result.extension_information)
|
||||
|
||||
def test_query_1_1(self):
|
||||
"""
|
||||
|
@ -6507,86 +6505,84 @@ class TestKmipEngine(testtools.TestCase):
|
|||
e._logger = mock.MagicMock()
|
||||
e._protocol_version = contents.ProtocolVersion(1, 1)
|
||||
|
||||
payload = payloads.QueryRequestPayload([
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS),
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_OBJECTS),
|
||||
misc.QueryFunction(
|
||||
enums.QueryFunction.QUERY_SERVER_INFORMATION
|
||||
),
|
||||
misc.QueryFunction(
|
||||
enums.QueryFunction.QUERY_APPLICATION_NAMESPACES
|
||||
),
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_LIST),
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_MAP)
|
||||
])
|
||||
payload = payloads.QueryRequestPayload(
|
||||
query_functions=[
|
||||
enums.QueryFunction.QUERY_OPERATIONS,
|
||||
enums.QueryFunction.QUERY_OBJECTS,
|
||||
enums.QueryFunction.QUERY_SERVER_INFORMATION,
|
||||
enums.QueryFunction.QUERY_APPLICATION_NAMESPACES,
|
||||
enums.QueryFunction.QUERY_EXTENSION_LIST,
|
||||
enums.QueryFunction.QUERY_EXTENSION_MAP
|
||||
]
|
||||
)
|
||||
|
||||
result = e._process_query(payload)
|
||||
|
||||
e._logger.info.assert_called_once_with("Processing operation: Query")
|
||||
self.assertIsInstance(result, payloads.QueryResponsePayload)
|
||||
self.assertIsNotNone(result.operations)
|
||||
self.assertIsInstance(result.operations, list)
|
||||
self.assertEqual(13, len(result.operations))
|
||||
self.assertEqual(
|
||||
enums.Operation.CREATE,
|
||||
result.operations[0].value
|
||||
result.operations[0]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.CREATE_KEY_PAIR,
|
||||
result.operations[1].value
|
||||
result.operations[1]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.REGISTER,
|
||||
result.operations[2].value
|
||||
result.operations[2]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.DERIVE_KEY,
|
||||
result.operations[3].value
|
||||
result.operations[3]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.LOCATE,
|
||||
result.operations[4].value
|
||||
result.operations[4]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.GET,
|
||||
result.operations[5].value
|
||||
result.operations[5]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.GET_ATTRIBUTES,
|
||||
result.operations[6].value
|
||||
result.operations[6]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.GET_ATTRIBUTE_LIST,
|
||||
result.operations[7].value
|
||||
result.operations[7]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.ACTIVATE,
|
||||
result.operations[8].value
|
||||
result.operations[8]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.REVOKE,
|
||||
result.operations[9].value
|
||||
result.operations[9]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.DESTROY,
|
||||
result.operations[10].value
|
||||
result.operations[10]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.QUERY,
|
||||
result.operations[11].value
|
||||
result.operations[11]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.DISCOVER_VERSIONS,
|
||||
result.operations[12].value
|
||||
result.operations[12]
|
||||
)
|
||||
self.assertEqual(list(), result.object_types)
|
||||
self.assertIsNone(result.object_types)
|
||||
self.assertIsNotNone(result.vendor_identification)
|
||||
self.assertEqual(
|
||||
"PyKMIP {0} Software Server".format(kmip.__version__),
|
||||
result.vendor_identification.value
|
||||
result.vendor_identification
|
||||
)
|
||||
self.assertIsNone(result.server_information)
|
||||
self.assertEqual(list(), result.application_namespaces)
|
||||
self.assertEqual(list(), result.extension_information)
|
||||
self.assertIsNone(result.application_namespaces)
|
||||
self.assertIsNone(result.extension_information)
|
||||
|
||||
def test_query_1_2(self):
|
||||
"""
|
||||
|
@ -6597,106 +6593,104 @@ class TestKmipEngine(testtools.TestCase):
|
|||
e._logger = mock.MagicMock()
|
||||
e._protocol_version = contents.ProtocolVersion(1, 2)
|
||||
|
||||
payload = payloads.QueryRequestPayload([
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS),
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_OBJECTS),
|
||||
misc.QueryFunction(
|
||||
enums.QueryFunction.QUERY_SERVER_INFORMATION
|
||||
),
|
||||
misc.QueryFunction(
|
||||
enums.QueryFunction.QUERY_APPLICATION_NAMESPACES
|
||||
),
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_LIST),
|
||||
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_MAP)
|
||||
])
|
||||
payload = payloads.QueryRequestPayload(
|
||||
query_functions=[
|
||||
enums.QueryFunction.QUERY_OPERATIONS,
|
||||
enums.QueryFunction.QUERY_OBJECTS,
|
||||
enums.QueryFunction.QUERY_SERVER_INFORMATION,
|
||||
enums.QueryFunction.QUERY_APPLICATION_NAMESPACES,
|
||||
enums.QueryFunction.QUERY_EXTENSION_LIST,
|
||||
enums.QueryFunction.QUERY_EXTENSION_MAP
|
||||
]
|
||||
)
|
||||
|
||||
result = e._process_query(payload)
|
||||
|
||||
e._logger.info.assert_called_once_with("Processing operation: Query")
|
||||
self.assertIsInstance(result, payloads.QueryResponsePayload)
|
||||
self.assertIsNotNone(result.operations)
|
||||
self.assertIsInstance(result.operations, list)
|
||||
self.assertEqual(18, len(result.operations))
|
||||
self.assertEqual(
|
||||
enums.Operation.CREATE,
|
||||
result.operations[0].value
|
||||
result.operations[0]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.CREATE_KEY_PAIR,
|
||||
result.operations[1].value
|
||||
result.operations[1]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.REGISTER,
|
||||
result.operations[2].value
|
||||
result.operations[2]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.DERIVE_KEY,
|
||||
result.operations[3].value
|
||||
result.operations[3]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.LOCATE,
|
||||
result.operations[4].value
|
||||
result.operations[4]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.GET,
|
||||
result.operations[5].value
|
||||
result.operations[5]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.GET_ATTRIBUTES,
|
||||
result.operations[6].value
|
||||
result.operations[6]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.GET_ATTRIBUTE_LIST,
|
||||
result.operations[7].value
|
||||
result.operations[7]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.ACTIVATE,
|
||||
result.operations[8].value
|
||||
result.operations[8]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.REVOKE,
|
||||
result.operations[9].value
|
||||
result.operations[9]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.DESTROY,
|
||||
result.operations[10].value
|
||||
result.operations[10]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.QUERY,
|
||||
result.operations[11].value
|
||||
result.operations[11]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.DISCOVER_VERSIONS,
|
||||
result.operations[12].value
|
||||
result.operations[12]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.ENCRYPT,
|
||||
result.operations[13].value
|
||||
result.operations[13]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.DECRYPT,
|
||||
result.operations[14].value
|
||||
result.operations[14]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.SIGN,
|
||||
result.operations[15].value
|
||||
result.operations[15]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.SIGNATURE_VERIFY,
|
||||
result.operations[16].value
|
||||
result.operations[16]
|
||||
)
|
||||
self.assertEqual(
|
||||
enums.Operation.MAC,
|
||||
result.operations[17].value
|
||||
result.operations[17]
|
||||
)
|
||||
self.assertEqual(list(), result.object_types)
|
||||
self.assertIsNone(result.object_types)
|
||||
self.assertIsNotNone(result.vendor_identification)
|
||||
self.assertEqual(
|
||||
"PyKMIP {0} Software Server".format(kmip.__version__),
|
||||
result.vendor_identification.value
|
||||
result.vendor_identification
|
||||
)
|
||||
self.assertIsNone(result.server_information)
|
||||
self.assertEqual(list(), result.application_namespaces)
|
||||
self.assertEqual(list(), result.extension_information)
|
||||
self.assertIsNone(result.application_namespaces)
|
||||
self.assertIsNone(result.extension_information)
|
||||
|
||||
def test_discover_versions(self):
|
||||
"""
|
||||
|
|
|
@ -45,9 +45,7 @@ from kmip.core.messages.contents import ProtocolVersion
|
|||
from kmip.core.messages import payloads
|
||||
|
||||
from kmip.core.misc import Offset
|
||||
from kmip.core.misc import QueryFunction
|
||||
from kmip.core.misc import ServerInformation
|
||||
from kmip.core.misc import VendorIdentification
|
||||
|
||||
from kmip.core import objects
|
||||
from kmip.core.objects import TemplateAttribute
|
||||
|
@ -375,9 +373,6 @@ class TestKMIPClient(TestCase):
|
|||
|
||||
payload = batch_item.request_payload
|
||||
|
||||
if query_functions is None:
|
||||
query_functions = list()
|
||||
|
||||
msg = base.format(payloads.QueryRequestPayload, payload)
|
||||
self.assertIsInstance(payload, payloads.QueryRequestPayload, msg)
|
||||
|
||||
|
@ -386,7 +381,8 @@ class TestKMIPClient(TestCase):
|
|||
|
||||
def test_build_query_batch_item_with_input(self):
|
||||
self._test_build_query_batch_item(
|
||||
[QueryFunction(QueryFunctionEnum.QUERY_OBJECTS)])
|
||||
[QueryFunctionEnum.QUERY_OBJECTS]
|
||||
)
|
||||
|
||||
def test_build_query_batch_item_without_input(self):
|
||||
self._test_build_query_batch_item(None)
|
||||
|
@ -630,7 +626,7 @@ class TestKMIPClient(TestCase):
|
|||
self._test_process_query_batch_item(
|
||||
list(),
|
||||
list(),
|
||||
VendorIdentification(),
|
||||
"",
|
||||
ServerInformation(),
|
||||
list(),
|
||||
list())
|
||||
|
|
Loading…
Reference in New Issue