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:
Peter Hamilton 2019-04-22 16:59:26 -04:00 committed by Peter Hamilton
parent b968378eb8
commit 314dd8761e
6 changed files with 4834 additions and 820 deletions

File diff suppressed because it is too large Load Diff

View File

@ -39,8 +39,6 @@ from kmip.core.messages import messages
from kmip.core.messages import payloads from kmip.core.messages import payloads
from kmip.core import misc
from kmip.pie import factory from kmip.pie import factory
from kmip.pie import objects from kmip.pie import objects
from kmip.pie import sqltypes from kmip.pie import sqltypes
@ -1917,7 +1915,7 @@ class KmipEngine(object):
def _process_query(self, payload): def _process_query(self, payload):
self._logger.info("Processing operation: Query") self._logger.info("Processing operation: Query")
queries = [x.value for x in payload.query_functions] queries = payload.query_functions
operations = list() operations = list()
objects = list() objects = list()
@ -1928,38 +1926,38 @@ class KmipEngine(object):
if enums.QueryFunction.QUERY_OPERATIONS in queries: if enums.QueryFunction.QUERY_OPERATIONS in queries:
operations = list([ operations = list([
contents.Operation(enums.Operation.CREATE), enums.Operation.CREATE,
contents.Operation(enums.Operation.CREATE_KEY_PAIR), enums.Operation.CREATE_KEY_PAIR,
contents.Operation(enums.Operation.REGISTER), enums.Operation.REGISTER,
contents.Operation(enums.Operation.DERIVE_KEY), enums.Operation.DERIVE_KEY,
contents.Operation(enums.Operation.LOCATE), enums.Operation.LOCATE,
contents.Operation(enums.Operation.GET), enums.Operation.GET,
contents.Operation(enums.Operation.GET_ATTRIBUTES), enums.Operation.GET_ATTRIBUTES,
contents.Operation(enums.Operation.GET_ATTRIBUTE_LIST), enums.Operation.GET_ATTRIBUTE_LIST,
contents.Operation(enums.Operation.ACTIVATE), enums.Operation.ACTIVATE,
contents.Operation(enums.Operation.REVOKE), enums.Operation.REVOKE,
contents.Operation(enums.Operation.DESTROY), enums.Operation.DESTROY,
contents.Operation(enums.Operation.QUERY) enums.Operation.QUERY
]) ])
if self._protocol_version >= contents.ProtocolVersion(1, 1): if self._protocol_version >= contents.ProtocolVersion(1, 1):
operations.extend([ operations.extend([
contents.Operation(enums.Operation.DISCOVER_VERSIONS) enums.Operation.DISCOVER_VERSIONS
]) ])
if self._protocol_version >= contents.ProtocolVersion(1, 2): if self._protocol_version >= contents.ProtocolVersion(1, 2):
operations.extend([ operations.extend([
contents.Operation(enums.Operation.ENCRYPT), enums.Operation.ENCRYPT,
contents.Operation(enums.Operation.DECRYPT), enums.Operation.DECRYPT,
contents.Operation(enums.Operation.SIGN), enums.Operation.SIGN,
contents.Operation(enums.Operation.SIGNATURE_VERIFY), enums.Operation.SIGNATURE_VERIFY,
contents.Operation(enums.Operation.MAC) enums.Operation.MAC
]) ])
if enums.QueryFunction.QUERY_OBJECTS in queries: if enums.QueryFunction.QUERY_OBJECTS in queries:
objects = list() objects = list()
if enums.QueryFunction.QUERY_SERVER_INFORMATION in queries: if enums.QueryFunction.QUERY_SERVER_INFORMATION in queries:
vendor_identification = misc.VendorIdentification( vendor_identification = "PyKMIP {0} Software Server".format(
"PyKMIP {0} Software Server".format(kmip.__version__) kmip.__version__
) )
server_information = None server_information = None
if enums.QueryFunction.QUERY_APPLICATION_NAMESPACES in queries: if enums.QueryFunction.QUERY_APPLICATION_NAMESPACES in queries:

View File

@ -32,7 +32,7 @@ from kmip.core.enums import OpaqueDataType
from kmip.core.enums import SecretDataType from kmip.core.enums import SecretDataType
from kmip.core.enums import ResultStatus from kmip.core.enums import ResultStatus
from kmip.core.enums import ResultReason 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.attributes import AttributeFactory
from kmip.core.factories.credentials import CredentialFactory 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 KeyValue
from kmip.core.objects import TemplateAttribute from kmip.core.objects import TemplateAttribute
from kmip.core.misc import QueryFunction
from kmip.core.secrets import SymmetricKey from kmip.core.secrets import SymmetricKey
from kmip.core.secrets import PrivateKey from kmip.core.secrets import PrivateKey
from kmip.core.secrets import PublicKey from kmip.core.secrets import PublicKey
@ -314,19 +312,16 @@ class TestIntegration(TestCase):
def test_query(self): def test_query(self):
# Build query function list, asking for all server data. # Build query function list, asking for all server data.
query_functions = list() query_functions = list(
query_functions.append( [
QueryFunction(QueryFunctionEnum.QUERY_OPERATIONS)) QueryFunction.QUERY_OPERATIONS,
query_functions.append( QueryFunction.QUERY_OBJECTS,
QueryFunction(QueryFunctionEnum.QUERY_OBJECTS)) QueryFunction.QUERY_SERVER_INFORMATION,
query_functions.append( QueryFunction.QUERY_APPLICATION_NAMESPACES,
QueryFunction(QueryFunctionEnum.QUERY_SERVER_INFORMATION)) QueryFunction.QUERY_EXTENSION_LIST,
query_functions.append( QueryFunction.QUERY_EXTENSION_MAP
QueryFunction(QueryFunctionEnum.QUERY_APPLICATION_NAMESPACES)) ]
query_functions.append( )
QueryFunction(QueryFunctionEnum.QUERY_EXTENSION_LIST))
query_functions.append(
QueryFunction(QueryFunctionEnum.QUERY_EXTENSION_MAP))
result = self.client.query(query_functions=query_functions) result = self.client.query(query_functions=query_functions)

File diff suppressed because it is too large Load Diff

View File

@ -6421,82 +6421,80 @@ class TestKmipEngine(testtools.TestCase):
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
e._protocol_version = contents.ProtocolVersion(1, 0) e._protocol_version = contents.ProtocolVersion(1, 0)
payload = payloads.QueryRequestPayload([ payload = payloads.QueryRequestPayload(
misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS), query_functions=[
misc.QueryFunction(enums.QueryFunction.QUERY_OBJECTS), enums.QueryFunction.QUERY_OPERATIONS,
misc.QueryFunction( enums.QueryFunction.QUERY_OBJECTS,
enums.QueryFunction.QUERY_SERVER_INFORMATION enums.QueryFunction.QUERY_SERVER_INFORMATION,
), enums.QueryFunction.QUERY_APPLICATION_NAMESPACES,
misc.QueryFunction( enums.QueryFunction.QUERY_EXTENSION_LIST,
enums.QueryFunction.QUERY_APPLICATION_NAMESPACES enums.QueryFunction.QUERY_EXTENSION_MAP
), ]
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_LIST), )
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_MAP)
])
result = e._process_query(payload) result = e._process_query(payload)
e._logger.info.assert_called_once_with("Processing operation: Query") e._logger.info.assert_called_once_with("Processing operation: Query")
self.assertIsInstance(result, payloads.QueryResponsePayload) self.assertIsInstance(result, payloads.QueryResponsePayload)
self.assertIsNotNone(result.operations) self.assertIsInstance(result.operations, list)
self.assertEqual(12, len(result.operations)) self.assertEqual(12, len(result.operations))
self.assertEqual( self.assertEqual(
enums.Operation.CREATE, enums.Operation.CREATE,
result.operations[0].value result.operations[0]
) )
self.assertEqual( self.assertEqual(
enums.Operation.CREATE_KEY_PAIR, enums.Operation.CREATE_KEY_PAIR,
result.operations[1].value result.operations[1]
) )
self.assertEqual( self.assertEqual(
enums.Operation.REGISTER, enums.Operation.REGISTER,
result.operations[2].value result.operations[2]
) )
self.assertEqual( self.assertEqual(
enums.Operation.DERIVE_KEY, enums.Operation.DERIVE_KEY,
result.operations[3].value result.operations[3]
) )
self.assertEqual( self.assertEqual(
enums.Operation.LOCATE, enums.Operation.LOCATE,
result.operations[4].value result.operations[4]
) )
self.assertEqual( self.assertEqual(
enums.Operation.GET, enums.Operation.GET,
result.operations[5].value result.operations[5]
) )
self.assertEqual( self.assertEqual(
enums.Operation.GET_ATTRIBUTES, enums.Operation.GET_ATTRIBUTES,
result.operations[6].value result.operations[6]
) )
self.assertEqual( self.assertEqual(
enums.Operation.GET_ATTRIBUTE_LIST, enums.Operation.GET_ATTRIBUTE_LIST,
result.operations[7].value result.operations[7]
) )
self.assertEqual( self.assertEqual(
enums.Operation.ACTIVATE, enums.Operation.ACTIVATE,
result.operations[8].value result.operations[8]
) )
self.assertEqual( self.assertEqual(
enums.Operation.REVOKE, enums.Operation.REVOKE,
result.operations[9].value result.operations[9]
) )
self.assertEqual( self.assertEqual(
enums.Operation.DESTROY, enums.Operation.DESTROY,
result.operations[10].value result.operations[10]
) )
self.assertEqual( self.assertEqual(
enums.Operation.QUERY, 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.assertIsNotNone(result.vendor_identification)
self.assertEqual( self.assertEqual(
"PyKMIP {0} Software Server".format(kmip.__version__), "PyKMIP {0} Software Server".format(kmip.__version__),
result.vendor_identification.value result.vendor_identification
) )
self.assertIsNone(result.server_information) self.assertIsNone(result.server_information)
self.assertEqual(list(), result.application_namespaces) self.assertIsNone(result.application_namespaces)
self.assertEqual(list(), result.extension_information) self.assertIsNone(result.extension_information)
def test_query_1_1(self): def test_query_1_1(self):
""" """
@ -6507,86 +6505,84 @@ class TestKmipEngine(testtools.TestCase):
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
e._protocol_version = contents.ProtocolVersion(1, 1) e._protocol_version = contents.ProtocolVersion(1, 1)
payload = payloads.QueryRequestPayload([ payload = payloads.QueryRequestPayload(
misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS), query_functions=[
misc.QueryFunction(enums.QueryFunction.QUERY_OBJECTS), enums.QueryFunction.QUERY_OPERATIONS,
misc.QueryFunction( enums.QueryFunction.QUERY_OBJECTS,
enums.QueryFunction.QUERY_SERVER_INFORMATION enums.QueryFunction.QUERY_SERVER_INFORMATION,
), enums.QueryFunction.QUERY_APPLICATION_NAMESPACES,
misc.QueryFunction( enums.QueryFunction.QUERY_EXTENSION_LIST,
enums.QueryFunction.QUERY_APPLICATION_NAMESPACES enums.QueryFunction.QUERY_EXTENSION_MAP
), ]
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_LIST), )
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_MAP)
])
result = e._process_query(payload) result = e._process_query(payload)
e._logger.info.assert_called_once_with("Processing operation: Query") e._logger.info.assert_called_once_with("Processing operation: Query")
self.assertIsInstance(result, payloads.QueryResponsePayload) self.assertIsInstance(result, payloads.QueryResponsePayload)
self.assertIsNotNone(result.operations) self.assertIsInstance(result.operations, list)
self.assertEqual(13, len(result.operations)) self.assertEqual(13, len(result.operations))
self.assertEqual( self.assertEqual(
enums.Operation.CREATE, enums.Operation.CREATE,
result.operations[0].value result.operations[0]
) )
self.assertEqual( self.assertEqual(
enums.Operation.CREATE_KEY_PAIR, enums.Operation.CREATE_KEY_PAIR,
result.operations[1].value result.operations[1]
) )
self.assertEqual( self.assertEqual(
enums.Operation.REGISTER, enums.Operation.REGISTER,
result.operations[2].value result.operations[2]
) )
self.assertEqual( self.assertEqual(
enums.Operation.DERIVE_KEY, enums.Operation.DERIVE_KEY,
result.operations[3].value result.operations[3]
) )
self.assertEqual( self.assertEqual(
enums.Operation.LOCATE, enums.Operation.LOCATE,
result.operations[4].value result.operations[4]
) )
self.assertEqual( self.assertEqual(
enums.Operation.GET, enums.Operation.GET,
result.operations[5].value result.operations[5]
) )
self.assertEqual( self.assertEqual(
enums.Operation.GET_ATTRIBUTES, enums.Operation.GET_ATTRIBUTES,
result.operations[6].value result.operations[6]
) )
self.assertEqual( self.assertEqual(
enums.Operation.GET_ATTRIBUTE_LIST, enums.Operation.GET_ATTRIBUTE_LIST,
result.operations[7].value result.operations[7]
) )
self.assertEqual( self.assertEqual(
enums.Operation.ACTIVATE, enums.Operation.ACTIVATE,
result.operations[8].value result.operations[8]
) )
self.assertEqual( self.assertEqual(
enums.Operation.REVOKE, enums.Operation.REVOKE,
result.operations[9].value result.operations[9]
) )
self.assertEqual( self.assertEqual(
enums.Operation.DESTROY, enums.Operation.DESTROY,
result.operations[10].value result.operations[10]
) )
self.assertEqual( self.assertEqual(
enums.Operation.QUERY, enums.Operation.QUERY,
result.operations[11].value result.operations[11]
) )
self.assertEqual( self.assertEqual(
enums.Operation.DISCOVER_VERSIONS, 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.assertIsNotNone(result.vendor_identification)
self.assertEqual( self.assertEqual(
"PyKMIP {0} Software Server".format(kmip.__version__), "PyKMIP {0} Software Server".format(kmip.__version__),
result.vendor_identification.value result.vendor_identification
) )
self.assertIsNone(result.server_information) self.assertIsNone(result.server_information)
self.assertEqual(list(), result.application_namespaces) self.assertIsNone(result.application_namespaces)
self.assertEqual(list(), result.extension_information) self.assertIsNone(result.extension_information)
def test_query_1_2(self): def test_query_1_2(self):
""" """
@ -6597,106 +6593,104 @@ class TestKmipEngine(testtools.TestCase):
e._logger = mock.MagicMock() e._logger = mock.MagicMock()
e._protocol_version = contents.ProtocolVersion(1, 2) e._protocol_version = contents.ProtocolVersion(1, 2)
payload = payloads.QueryRequestPayload([ payload = payloads.QueryRequestPayload(
misc.QueryFunction(enums.QueryFunction.QUERY_OPERATIONS), query_functions=[
misc.QueryFunction(enums.QueryFunction.QUERY_OBJECTS), enums.QueryFunction.QUERY_OPERATIONS,
misc.QueryFunction( enums.QueryFunction.QUERY_OBJECTS,
enums.QueryFunction.QUERY_SERVER_INFORMATION enums.QueryFunction.QUERY_SERVER_INFORMATION,
), enums.QueryFunction.QUERY_APPLICATION_NAMESPACES,
misc.QueryFunction( enums.QueryFunction.QUERY_EXTENSION_LIST,
enums.QueryFunction.QUERY_APPLICATION_NAMESPACES enums.QueryFunction.QUERY_EXTENSION_MAP
), ]
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_LIST), )
misc.QueryFunction(enums.QueryFunction.QUERY_EXTENSION_MAP)
])
result = e._process_query(payload) result = e._process_query(payload)
e._logger.info.assert_called_once_with("Processing operation: Query") e._logger.info.assert_called_once_with("Processing operation: Query")
self.assertIsInstance(result, payloads.QueryResponsePayload) self.assertIsInstance(result, payloads.QueryResponsePayload)
self.assertIsNotNone(result.operations) self.assertIsInstance(result.operations, list)
self.assertEqual(18, len(result.operations)) self.assertEqual(18, len(result.operations))
self.assertEqual( self.assertEqual(
enums.Operation.CREATE, enums.Operation.CREATE,
result.operations[0].value result.operations[0]
) )
self.assertEqual( self.assertEqual(
enums.Operation.CREATE_KEY_PAIR, enums.Operation.CREATE_KEY_PAIR,
result.operations[1].value result.operations[1]
) )
self.assertEqual( self.assertEqual(
enums.Operation.REGISTER, enums.Operation.REGISTER,
result.operations[2].value result.operations[2]
) )
self.assertEqual( self.assertEqual(
enums.Operation.DERIVE_KEY, enums.Operation.DERIVE_KEY,
result.operations[3].value result.operations[3]
) )
self.assertEqual( self.assertEqual(
enums.Operation.LOCATE, enums.Operation.LOCATE,
result.operations[4].value result.operations[4]
) )
self.assertEqual( self.assertEqual(
enums.Operation.GET, enums.Operation.GET,
result.operations[5].value result.operations[5]
) )
self.assertEqual( self.assertEqual(
enums.Operation.GET_ATTRIBUTES, enums.Operation.GET_ATTRIBUTES,
result.operations[6].value result.operations[6]
) )
self.assertEqual( self.assertEqual(
enums.Operation.GET_ATTRIBUTE_LIST, enums.Operation.GET_ATTRIBUTE_LIST,
result.operations[7].value result.operations[7]
) )
self.assertEqual( self.assertEqual(
enums.Operation.ACTIVATE, enums.Operation.ACTIVATE,
result.operations[8].value result.operations[8]
) )
self.assertEqual( self.assertEqual(
enums.Operation.REVOKE, enums.Operation.REVOKE,
result.operations[9].value result.operations[9]
) )
self.assertEqual( self.assertEqual(
enums.Operation.DESTROY, enums.Operation.DESTROY,
result.operations[10].value result.operations[10]
) )
self.assertEqual( self.assertEqual(
enums.Operation.QUERY, enums.Operation.QUERY,
result.operations[11].value result.operations[11]
) )
self.assertEqual( self.assertEqual(
enums.Operation.DISCOVER_VERSIONS, enums.Operation.DISCOVER_VERSIONS,
result.operations[12].value result.operations[12]
) )
self.assertEqual( self.assertEqual(
enums.Operation.ENCRYPT, enums.Operation.ENCRYPT,
result.operations[13].value result.operations[13]
) )
self.assertEqual( self.assertEqual(
enums.Operation.DECRYPT, enums.Operation.DECRYPT,
result.operations[14].value result.operations[14]
) )
self.assertEqual( self.assertEqual(
enums.Operation.SIGN, enums.Operation.SIGN,
result.operations[15].value result.operations[15]
) )
self.assertEqual( self.assertEqual(
enums.Operation.SIGNATURE_VERIFY, enums.Operation.SIGNATURE_VERIFY,
result.operations[16].value result.operations[16]
) )
self.assertEqual( self.assertEqual(
enums.Operation.MAC, 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.assertIsNotNone(result.vendor_identification)
self.assertEqual( self.assertEqual(
"PyKMIP {0} Software Server".format(kmip.__version__), "PyKMIP {0} Software Server".format(kmip.__version__),
result.vendor_identification.value result.vendor_identification
) )
self.assertIsNone(result.server_information) self.assertIsNone(result.server_information)
self.assertEqual(list(), result.application_namespaces) self.assertIsNone(result.application_namespaces)
self.assertEqual(list(), result.extension_information) self.assertIsNone(result.extension_information)
def test_discover_versions(self): def test_discover_versions(self):
""" """

View File

@ -45,9 +45,7 @@ from kmip.core.messages.contents import ProtocolVersion
from kmip.core.messages import payloads from kmip.core.messages import payloads
from kmip.core.misc import Offset from kmip.core.misc import Offset
from kmip.core.misc import QueryFunction
from kmip.core.misc import ServerInformation from kmip.core.misc import ServerInformation
from kmip.core.misc import VendorIdentification
from kmip.core import objects from kmip.core import objects
from kmip.core.objects import TemplateAttribute from kmip.core.objects import TemplateAttribute
@ -375,9 +373,6 @@ class TestKMIPClient(TestCase):
payload = batch_item.request_payload payload = batch_item.request_payload
if query_functions is None:
query_functions = list()
msg = base.format(payloads.QueryRequestPayload, payload) msg = base.format(payloads.QueryRequestPayload, payload)
self.assertIsInstance(payload, payloads.QueryRequestPayload, msg) self.assertIsInstance(payload, payloads.QueryRequestPayload, msg)
@ -386,7 +381,8 @@ class TestKMIPClient(TestCase):
def test_build_query_batch_item_with_input(self): def test_build_query_batch_item_with_input(self):
self._test_build_query_batch_item( self._test_build_query_batch_item(
[QueryFunction(QueryFunctionEnum.QUERY_OBJECTS)]) [QueryFunctionEnum.QUERY_OBJECTS]
)
def test_build_query_batch_item_without_input(self): def test_build_query_batch_item_without_input(self):
self._test_build_query_batch_item(None) self._test_build_query_batch_item(None)
@ -630,7 +626,7 @@ class TestKMIPClient(TestCase):
self._test_process_query_batch_item( self._test_process_query_batch_item(
list(), list(),
list(), list(),
VendorIdentification(), "",
ServerInformation(), ServerInformation(),
list(), list(),
list()) list())