diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9bb8b0d9..6c67931d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -39,7 +39,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -50,7 +50,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # â„šī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -64,4 +64,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml new file mode 100755 index 00000000..678e1952 --- /dev/null +++ b/.github/workflows/tox.yml @@ -0,0 +1,41 @@ +name: "tox.yml" + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ${{ matrix.os }} + env: + TOXENV: ${{ matrix.test }} + RUN_INTEGRATION_TESTS: ${{ matrix.test_number}} + steps: + - uses: actions/checkout@v3 + - run: pip install "tox" + - run: pip install bandit + - run: pip install codecov + - run: pip install slugs + - run: sudo chmod -R 777 /usr/local/lib/ + - run: python3 setup.py install + - run: ./.travis/run.sh + - run: codecov + strategy: + matrix: + test: ["pep8", "bandit", "docs"] + os: [ubuntu-22.04,ubuntu-20.04] + include: + - test: "py38" + test_number: "0" + os: ubuntu-20.04 + - test: "py38" + test_number: "1" + os: ubuntu-20.04 + - test: "py310" + test_number: "0" + os: ubuntu-22.04 + - test: "py310" + test_number: "1" + os: ubuntu-22.04 \ No newline at end of file diff --git a/.travis/run.sh b/.travis/run.sh index 7baf0fbc..e4065bd3 100755 --- a/.travis/run.sh +++ b/.travis/run.sh @@ -3,6 +3,9 @@ set -e set -x +pkill -f run_server.py || true +sleep 1 + if [[ "${RUN_INTEGRATION_TESTS}" == "1" ]]; then sudo mkdir -p /etc/pykmip/certs sudo mkdir -p /etc/pykmip/policies @@ -12,9 +15,10 @@ if [[ "${RUN_INTEGRATION_TESTS}" == "1" ]]; then sudo cp ./.travis/pykmip.conf /etc/pykmip/pykmip.conf sudo cp ./.travis/server.conf /etc/pykmip/server.conf sudo cp ./.travis/policy.json /etc/pykmip/policies/policy.json - sudo mkdir /var/log/pykmip + sudo mkdir -p /var/log/pykmip sudo chmod 777 /var/log/pykmip - python ./bin/run_server.py & + sudo chmod -R 777 /etc/pykmip/ + python3 ./bin/run_server.py & tox -e integration -- --config client elif [[ "${RUN_INTEGRATION_TESTS}" == "2" ]]; then # Set up the SLUGS instance @@ -23,9 +27,9 @@ elif [[ "${RUN_INTEGRATION_TESTS}" == "2" ]]; then # Set up the PyKMIP server cp -r ./.travis/functional/pykmip /tmp/ - python ./bin/create_certificates.py + python3 ./bin/create_certificates.py mv *.pem /tmp/pykmip/certs/ - sudo mkdir /var/log/pykmip + sudo mkdir -p /var/log/pykmip sudo chmod 777 /var/log/pykmip pykmip-server -f /tmp/pykmip/server.conf -l /tmp/pykmip/server.log & diff --git a/.travis/server.conf b/.travis/server.conf index 61f18a39..a162ca2b 100644 --- a/.travis/server.conf +++ b/.travis/server.conf @@ -4,6 +4,6 @@ port=5696 certificate_path=/etc/pykmip/certs/cert.pem key_path=/etc/pykmip/certs/key.pem ca_path=/etc/pykmip/certs/cert.pem -auth_suite=Basic +auth_suite=TLS1.2 enable_tls_client_auth=False policy_path=/etc/pykmip/policies/ diff --git a/bin/create_certificates.py b/bin/create_certificates.py index 0bd15698..bc7e5b33 100755 --- a/bin/create_certificates.py +++ b/bin/create_certificates.py @@ -47,7 +47,8 @@ def create_certificate(subject_name, signing_certificate, signing_key, days_valid=365, - client_auth=False): + client_auth=False, + hostname=None): subject = x509.Name([ x509.NameAttribute(x509.NameOID.ORGANIZATION_NAME, u"Test, Inc."), x509.NameAttribute(x509.NameOID.COMMON_NAME, subject_name) @@ -72,6 +73,12 @@ def create_certificate(subject_name, critical=True ) + if hostname: + builder = builder.add_extension( + x509.SubjectAlternativeName([x509.DNSName(hostname)]), + critical=False, + ) + certificate = builder.sign( signing_key, hashes.SHA256(), @@ -92,7 +99,8 @@ def main(): u"Server Certificate", server_key, root_certificate, - root_key + root_key, + hostname=u"localhost" ) john_doe_client_key = create_rsa_private_key() diff --git a/docs/source/conf.py b/docs/source/conf.py index 37e90381..3e713e21 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -64,7 +64,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = 'en' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. diff --git a/kmip/core/enums.py b/kmip/core/enums.py index 4195d2be..5118d3ad 100644 --- a/kmip/core/enums.py +++ b/kmip/core/enums.py @@ -127,6 +127,9 @@ class AttributeType(enum.Enum): KEY_VALUE_LOCATION = 'Key Value Location' ORIGINAL_CREATION_DATE = 'Original Creation Date' SENSITIVE = "Sensitive" + ALWAYS_SENSITIVE = 'Always Sensitive' + EXTRACTABLE = 'Extractable' + NEVER_EXTRACTABLE = 'Never Extractable' class AuthenticationSuite(enum.Enum): diff --git a/kmip/core/factories/attribute_values.py b/kmip/core/factories/attribute_values.py index 4a1c4a59..1bc1e208 100644 --- a/kmip/core/factories/attribute_values.py +++ b/kmip/core/factories/attribute_values.py @@ -106,8 +106,16 @@ def create_attribute_value(self, name, value): return primitives.DateTime(value, enums.Tags.LAST_CHANGE_DATE) elif name is enums.AttributeType.SENSITIVE: return primitives.Boolean(value, enums.Tags.SENSITIVE) + elif name is enums.AttributeType.ALWAYS_SENSITIVE: + return primitives.Boolean(value, enums.Tags.ALWAYS_SENSITIVE) + elif name is enums.AttributeType.EXTRACTABLE: + return primitives.Boolean(value, enums.Tags.EXTRACTABLE) + elif name is enums.AttributeType.NEVER_EXTRACTABLE: + return primitives.Boolean(value, enums.Tags.NEVER_EXTRACTABLE) elif name is enums.AttributeType.CUSTOM_ATTRIBUTE: return attributes.CustomAttribute(value) + elif name is enums.AttributeType.ORIGINAL_CREATION_DATE: + return primitives.DateTime(value, enums.Tags.ORIGINAL_CREATION_DATE) else: if not isinstance(name, str): raise ValueError('Unrecognized attribute type: ' diff --git a/kmip/core/messages/contents.py b/kmip/core/messages/contents.py index 2912dbe6..470c4318 100644 --- a/kmip/core/messages/contents.py +++ b/kmip/core/messages/contents.py @@ -506,6 +506,13 @@ def __init__(self): super(MessageExtension, self).__init__(enums.Tags.MESSAGE_EXTENSION) +# 6.19 +class ServerCorrelationValue(TextString): + def __init__(self, value=None): + super(ServerCorrelationValue, self).__init__( + value, enums.Tags.SERVER_CORRELATION_VALUE) + + # 9.1.3.2.2 class KeyCompressionType(Enumeration): diff --git a/kmip/core/messages/messages.py b/kmip/core/messages/messages.py index e2e37cf6..c1b4c6bc 100644 --- a/kmip/core/messages/messages.py +++ b/kmip/core/messages/messages.py @@ -150,12 +150,14 @@ def __init__(self, protocol_version=None, time_stamp=None, batch_count=None, - server_hashed_password=None): + server_hashed_password=None, + server_correlation_value=None): super(ResponseHeader, self).__init__(tag=Tags.RESPONSE_HEADER) self.protocol_version = protocol_version self.time_stamp = time_stamp self.batch_count = batch_count self.server_hashed_password = server_hashed_password + self.server_correlation_value = server_correlation_value self.validate() @@ -204,6 +206,10 @@ def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): server_hashed_password.read(tstream, kmip_version=kmip_version) self._server_hashed_password = server_hashed_password + if self.is_tag_next(enums.Tags.SERVER_CORRELATION_VALUE, tstream): + self.server_correlation_value = contents.ServerCorrelationValue() + self.server_correlation_value.read(tstream, kmip_version=kmip_version) + self.batch_count = contents.BatchCount() self.batch_count.read(tstream, kmip_version=kmip_version) diff --git a/kmip/core/messages/payloads/discover_versions.py b/kmip/core/messages/payloads/discover_versions.py index 8df74a53..92166d5e 100644 --- a/kmip/core/messages/payloads/discover_versions.py +++ b/kmip/core/messages/payloads/discover_versions.py @@ -40,7 +40,7 @@ def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): ) tstream = BytearrayStream(istream.read(self.length)) - while(self.is_tag_next(enums.Tags.PROTOCOL_VERSION, tstream)): + while (self.is_tag_next(enums.Tags.PROTOCOL_VERSION, tstream)): protocol_version = ProtocolVersion() protocol_version.read(tstream, kmip_version=kmip_version) self.protocol_versions.append(protocol_version) @@ -99,7 +99,7 @@ def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): ) tstream = BytearrayStream(istream.read(self.length)) - while(self.is_tag_next(enums.Tags.PROTOCOL_VERSION, tstream)): + while (self.is_tag_next(enums.Tags.PROTOCOL_VERSION, tstream)): protocol_version = ProtocolVersion() protocol_version.read(tstream, kmip_version=kmip_version) self.protocol_versions.append(protocol_version) diff --git a/kmip/core/messages/payloads/query.py b/kmip/core/messages/payloads/query.py index 6c3d7bd2..8c65d2e2 100644 --- a/kmip/core/messages/payloads/query.py +++ b/kmip/core/messages/payloads/query.py @@ -105,7 +105,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) query_functions = [] - while(self.is_tag_next(enums.Tags.QUERY_FUNCTION, local_buffer)): + while (self.is_tag_next(enums.Tags.QUERY_FUNCTION, local_buffer)): query_function = primitives.Enumeration( enums.QueryFunction, tag=enums.Tags.QUERY_FUNCTION @@ -709,7 +709,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): local_buffer = utils.BytearrayStream(input_buffer.read(self.length)) operations = [] - while(self.is_tag_next(enums.Tags.OPERATION, local_buffer)): + while (self.is_tag_next(enums.Tags.OPERATION, local_buffer)): operation = primitives.Enumeration( enums.Operation, tag=enums.Tags.OPERATION @@ -719,7 +719,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): self._operations = operations object_types = [] - while(self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer)): + while (self.is_tag_next(enums.Tags.OBJECT_TYPE, local_buffer)): object_type = primitives.Enumeration( enums.ObjectType, tag=enums.Tags.OBJECT_TYPE @@ -747,7 +747,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): self._server_information = server_information application_namespaces = [] - while(self.is_tag_next( + while (self.is_tag_next( enums.Tags.APPLICATION_NAMESPACE, local_buffer ) @@ -761,7 +761,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): if kmip_version >= enums.KMIPVersion.KMIP_1_1: extensions_information = [] - while(self.is_tag_next( + while (self.is_tag_next( enums.Tags.EXTENSION_INFORMATION, local_buffer ) @@ -776,7 +776,11 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): if kmip_version >= enums.KMIPVersion.KMIP_1_2: attestation_types = [] - while(self.is_tag_next(enums.Tags.ATTESTATION_TYPE, local_buffer)): + while (self.is_tag_next( + enums.Tags.ATTESTATION_TYPE, + local_buffer + ) + ): attestation_type = primitives.Enumeration( enums.AttestationType, tag=enums.Tags.ATTESTATION_TYPE @@ -787,14 +791,14 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): if kmip_version >= enums.KMIPVersion.KMIP_1_3: rngs_parameters = [] - while(self.is_tag_next(enums.Tags.RNG_PARAMETERS, local_buffer)): + while (self.is_tag_next(enums.Tags.RNG_PARAMETERS, local_buffer)): rng_parameters = objects.RNGParameters() rng_parameters.read(local_buffer, kmip_version=kmip_version) rngs_parameters.append(rng_parameters) self._rng_parameters = rngs_parameters profiles_information = [] - while(self.is_tag_next( + while (self.is_tag_next( enums.Tags.PROFILE_INFORMATION, local_buffer ) @@ -808,7 +812,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): self._profile_information = profiles_information validations_information = [] - while(self.is_tag_next( + while (self.is_tag_next( enums.Tags.VALIDATION_INFORMATION, local_buffer ) @@ -822,7 +826,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): self._validation_information = validations_information capabilities_information = [] - while(self.is_tag_next( + while (self.is_tag_next( enums.Tags.CAPABILITY_INFORMATION, local_buffer ) @@ -836,7 +840,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): self._capability_information = capabilities_information client_registration_methods = [] - while(self.is_tag_next( + while (self.is_tag_next( enums.Tags.CLIENT_REGISTRATION_METHOD, local_buffer ) @@ -862,7 +866,7 @@ def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): self._defaults_information = defaults_information protection_storage_masks = [] - while(self.is_tag_next( + while (self.is_tag_next( enums.Tags.PROTECTION_STORAGE_MASK, local_buffer ) diff --git a/kmip/demos/pie/register_certificate.py b/kmip/demos/pie/register_certificate.py index ffaa38ad..5f2aca73 100644 --- a/kmip/demos/pie/register_certificate.py +++ b/kmip/demos/pie/register_certificate.py @@ -26,7 +26,7 @@ if __name__ == '__main__': logger = utils.build_console_logger(logging.INFO) - parser = utils.build_cli_parser() + parser = utils.build_cli_parser(enums.Operation.REGISTER) opts, args = parser.parse_args(sys.argv[1:]) config = opts.config diff --git a/kmip/demos/pie/register_opaque_object.py b/kmip/demos/pie/register_opaque_object.py index e0523c89..48cf48cd 100644 --- a/kmip/demos/pie/register_opaque_object.py +++ b/kmip/demos/pie/register_opaque_object.py @@ -26,7 +26,7 @@ if __name__ == '__main__': logger = utils.build_console_logger(logging.INFO) - parser = utils.build_cli_parser() + parser = utils.build_cli_parser(enums.Operation.REGISTER) opts, args = parser.parse_args(sys.argv[1:]) config = opts.config diff --git a/kmip/demos/pie/register_private_key.py b/kmip/demos/pie/register_private_key.py index ee27ffb0..e6f62b03 100644 --- a/kmip/demos/pie/register_private_key.py +++ b/kmip/demos/pie/register_private_key.py @@ -26,7 +26,7 @@ if __name__ == '__main__': logger = utils.build_console_logger(logging.INFO) - parser = utils.build_cli_parser() + parser = utils.build_cli_parser(enums.Operation.REGISTER) opts, args = parser.parse_args(sys.argv[1:]) config = opts.config diff --git a/kmip/demos/pie/register_public_key.py b/kmip/demos/pie/register_public_key.py index bc867dd9..17469a75 100644 --- a/kmip/demos/pie/register_public_key.py +++ b/kmip/demos/pie/register_public_key.py @@ -26,7 +26,7 @@ if __name__ == '__main__': logger = utils.build_console_logger(logging.INFO) - parser = utils.build_cli_parser() + parser = utils.build_cli_parser(enums.Operation.REGISTER) opts, args = parser.parse_args(sys.argv[1:]) config = opts.config diff --git a/kmip/demos/pie/register_secret_data.py b/kmip/demos/pie/register_secret_data.py index 2ac7072f..86d5f780 100644 --- a/kmip/demos/pie/register_secret_data.py +++ b/kmip/demos/pie/register_secret_data.py @@ -27,7 +27,7 @@ if __name__ == '__main__': logger = utils.build_console_logger(logging.INFO) - parser = utils.build_cli_parser() + parser = utils.build_cli_parser(enums.Operation.REGISTER) opts, args = parser.parse_args(sys.argv[1:]) config = opts.config @@ -37,7 +37,7 @@ usage_mask = [enums.CryptographicUsageMask.VERIFY] name = 'Demo Secret Data' - secret = objects.SecretData(value, data_type, usage_mask, name) + secret = objects.SecretData(value, data_type, None, usage_mask, name) secret.operation_policy_name = opts.operation_policy_name # Build the client and connect to the server diff --git a/kmip/demos/pie/register_symmetric_key.py b/kmip/demos/pie/register_symmetric_key.py index 38a0689b..5234e6d3 100644 --- a/kmip/demos/pie/register_symmetric_key.py +++ b/kmip/demos/pie/register_symmetric_key.py @@ -26,7 +26,7 @@ if __name__ == '__main__': logger = utils.build_console_logger(logging.INFO) - parser = utils.build_cli_parser() + parser = utils.build_cli_parser(enums.Operation.REGISTER) opts, args = parser.parse_args(sys.argv[1:]) config = opts.config diff --git a/kmip/pie/client.py b/kmip/pie/client.py index 0205ea8e..d27ad4b1 100644 --- a/kmip/pie/client.py +++ b/kmip/pie/client.py @@ -559,12 +559,15 @@ def register(self, managed_object): if hasattr(managed_object, '_application_specific_informations'): if managed_object._application_specific_informations: - for attr in managed_object._application_specific_informations: - object_attributes.append(attr) - + for info in managed_object._application_specific_informations: + attribute = self.attribute_factory.create_attribute( + enums.AttributeType.APPLICATION_SPECIFIC_INFORMATION, + info, + index=0 + ) + object_attributes.append(attribute) template = cobjects.TemplateAttribute(attributes=object_attributes) object_type = managed_object.object_type - # Register the managed object and handle the results secret = self.object_factory.convert(managed_object) result = self.proxy.register(object_type, template, secret) diff --git a/kmip/pie/objects.py b/kmip/pie/objects.py index e0ab00df..a0b2172e 100644 --- a/kmip/pie/objects.py +++ b/kmip/pie/objects.py @@ -658,7 +658,8 @@ class SymmetricKey(Key): } def __init__(self, algorithm, length, value, masks=None, - name='Symmetric Key', key_wrapping_data=None): + name='Symmetric Key', key_wrapping_data=None, + app_specific_info=None): """ Create a SymmetricKey. @@ -674,6 +675,9 @@ def __init__(self, algorithm, length, value, masks=None, key_wrapping_data(dict): A dictionary containing key wrapping data settings, describing how the key value has been wrapped. Optional, defaults to None. + app_specific_info(list): A list of dictionaries containing + application_namespace and application_data. Optional, defaults + to None. """ super(SymmetricKey, self).__init__( key_wrapping_data=key_wrapping_data @@ -690,6 +694,9 @@ def __init__(self, algorithm, length, value, masks=None, if masks: self.cryptographic_usage_masks.extend(masks) + if app_specific_info: + self._application_specific_informations = app_specific_info + # All remaining attributes are not considered part of the public API # and are subject to change. @@ -747,14 +754,18 @@ def __repr__(self): algorithm = "algorithm={0}".format(self.cryptographic_algorithm) length = "length={0}".format(self.cryptographic_length) value = "value={0}".format(binascii.hexlify(self.value)) + masks = "masks={0}".format(self.cryptographic_usage_masks) + names = "names={0}".format(self.names) key_wrapping_data = "key_wrapping_data={0}".format( self.key_wrapping_data ) - return "SymmetricKey({0}, {1}, {2}, {3})".format( + return "SymmetricKey({0}, {1}, {2}, {3}, {4}, {5})".format( algorithm, length, value, + masks, + names, key_wrapping_data ) @@ -821,7 +832,8 @@ class PublicKey(Key): def __init__(self, algorithm, length, value, format_type=enums.KeyFormatType.X_509, masks=None, - name='Public Key', key_wrapping_data=None): + name='Public Key', key_wrapping_data=None, + app_specific_info=None): """ Create a PublicKey. @@ -839,6 +851,9 @@ def __init__(self, algorithm, length, value, key_wrapping_data(dict): A dictionary containing key wrapping data settings, describing how the key value has been wrapped. Optional, defaults to None. + app_specific_info(list): A list of dictionaries containing + application_namespace and application_data. Optional, defaults + to None. """ super(PublicKey, self).__init__( key_wrapping_data=key_wrapping_data @@ -859,6 +874,9 @@ def __init__(self, algorithm, length, value, if masks: self.cryptographic_usage_masks = masks + if app_specific_info: + self._application_specific_informations = app_specific_info + # All remaining attributes are not considered part of the public API # and are subject to change. @@ -986,7 +1004,8 @@ class PrivateKey(Key): } def __init__(self, algorithm, length, value, format_type, masks=None, - name='Private Key', key_wrapping_data=None): + name='Private Key', key_wrapping_data=None, + app_specific_info=None): """ Create a PrivateKey. @@ -1003,6 +1022,9 @@ def __init__(self, algorithm, length, value, format_type, masks=None, key_wrapping_data(dict): A dictionary containing key wrapping data settings, describing how the key value has been wrapped. Optional, defaults to None. + app_specific_info(list): A list of dictionaries containing + application_namespace and application_data. Optional, defaults + to None. """ super(PrivateKey, self).__init__( key_wrapping_data=key_wrapping_data @@ -1023,6 +1045,9 @@ def __init__(self, algorithm, length, value, format_type, masks=None, if masks: self.cryptographic_usage_masks = masks + if app_specific_info: + self._application_specific_informations = app_specific_info + # All remaining attributes are not considered part of the public API # and are subject to change. @@ -1580,7 +1605,8 @@ class SecretData(CryptographicObject): 'sqlite_autoincrement': True } - def __init__(self, value, data_type, app_specific_info=None, masks=None, name='Secret Data'): + def __init__(self, value, data_type, masks=None, name='Secret Data', + app_specific_info=None): """ Create a SecretData object. @@ -1591,6 +1617,9 @@ def __init__(self, value, data_type, app_specific_info=None, masks=None, name='S masks(list): A list of CryptographicUsageMask enumerations defining how the key will be used. name(string): The string name of the key. + app_specific_info(list): A list of dictionaries containing + application_namespace and application_data. Optional, defaults + to None. """ super(SecretData, self).__init__() @@ -1599,7 +1628,7 @@ def __init__(self, value, data_type, app_specific_info=None, masks=None, name='S self.value = value self.data_type = data_type self.names = [name] - + if app_specific_info: self._application_specific_informations = app_specific_info diff --git a/kmip/services/server/auth/slugs.py b/kmip/services/server/auth/slugs.py index 0bf15e22..5046313a 100644 --- a/kmip/services/server/auth/slugs.py +++ b/kmip/services/server/auth/slugs.py @@ -88,7 +88,7 @@ def authenticate(self, ) try: - response = requests.get(self.users_url.format(user_id)) + response = requests.get(self.users_url.format(user_id), timeout=10) except Exception: raise exceptions.ConfigurationError( "A connection could not be established using the SLUGS URL." @@ -98,7 +98,7 @@ def authenticate(self, "Unrecognized user ID: {}".format(user_id) ) - response = requests.get(self.groups_url.format(user_id)) + response = requests.get(self.groups_url.format(user_id), timeout=10) if response.status_code == 404: raise exceptions.PermissionDenied( "Group information could not be retrieved for user ID: " diff --git a/kmip/services/server/crypto/engine.py b/kmip/services/server/crypto/engine.py index 838e1b92..3c6534a6 100644 --- a/kmip/services/server/crypto/engine.py +++ b/kmip/services/server/crypto/engine.py @@ -269,12 +269,11 @@ def mac(self, algorithm, key, data): ) cipher_algorithm = self._symmetric_key_algorithms.get(algorithm) try: - # ARC4 and IDEA algorithms will raise exception as CMAC - # requires block ciphers + # ARC4 and other non-block cipher algorithm will raise TypeError c = cmac.CMAC(cipher_algorithm(key), backend=default_backend()) c.update(data) mac_data = c.finalize() - except Exception as e: + except Exception: raise exceptions.CryptographicFailure( "An error occurred while computing a CMAC. " "See the server log for more information." @@ -929,18 +928,18 @@ def _decrypt_asymmetric( "decryption.".format(padding_method) ) - backend = default_backend() - try: - private_key = backend.load_der_private_key( + private_key = serialization.load_der_private_key( decryption_key, - None + password=None, + backend=default_backend() ) except Exception: try: - private_key = backend.load_pem_private_key( + private_key = serialization.load_pem_private_key( decryption_key, - None + password=None, + backend=default_backend() ) except Exception: raise exceptions.CryptographicFailure( diff --git a/kmip/services/server/engine.py b/kmip/services/server/engine.py index 4c5ff508..43fdbe93 100644 --- a/kmip/services/server/engine.py +++ b/kmip/services/server/engine.py @@ -355,80 +355,81 @@ def build_error_response(self, version, reason, message): def _process_batch(self, request_batch, batch_handling, batch_order): response_batch = list() - self._data_session = self._data_store_session_factory() + with self._data_store_session_factory() as session: + self._data_session = session - for batch_item in request_batch: - error_occurred = False + for batch_item in request_batch: + error_occurred = False - response_payload = None - result_status = None - result_reason = None - result_message = None + response_payload = None + result_status = None + result_reason = None + result_message = None - operation = batch_item.operation - request_payload = batch_item.request_payload + operation = batch_item.operation + request_payload = batch_item.request_payload - # Process batch item ID. - if len(request_batch) > 1: - if not batch_item.unique_batch_item_id: - raise exceptions.InvalidMessage( - "Batch item ID is undefined." - ) + # Process batch item ID. + if len(request_batch) > 1: + if not batch_item.unique_batch_item_id: + raise exceptions.InvalidMessage( + "Batch item ID is undefined." + ) - # Process batch message extension. - # TODO (peterhamilton) Add support for message extension handling. - # 1. Extract the vendor identification and criticality indicator. - # 2. If the indicator is True, raise an error. - # 3. If the indicator is False, ignore the extension. - - # Process batch payload. - try: - response_payload = self._process_operation( - operation.value, - request_payload - ) + # Process batch message extension. + # TODO (peterhamilton) Add support for message extension handling. + # 1. Extract the vendor identification and criticality indicator. + # 2. If the indicator is True, raise an error. + # 3. If the indicator is False, ignore the extension. - result_status = enums.ResultStatus.SUCCESS - except exceptions.KmipError as e: - error_occurred = True - result_status = e.status - result_reason = e.reason - result_message = str(e) - except Exception as e: - self._logger.warning( - "Error occurred while processing operation." - ) - self._logger.exception(e) - - error_occurred = True - result_status = enums.ResultStatus.OPERATION_FAILED - result_reason = enums.ResultReason.GENERAL_FAILURE - result_message = ( - "Operation failed. See the server logs for more " - "information." - ) + # Process batch payload. + try: + response_payload = self._process_operation( + operation.value, + request_payload + ) - # Compose operation result. - result_status = contents.ResultStatus(result_status) - if result_reason: - result_reason = contents.ResultReason(result_reason) - if result_message: - result_message = contents.ResultMessage(result_message) + result_status = enums.ResultStatus.SUCCESS + except exceptions.KmipError as e: + error_occurred = True + result_status = e.status + result_reason = e.reason + result_message = str(e) + except Exception as e: + self._logger.warning( + "Error occurred while processing operation." + ) + self._logger.exception(e) - batch_item = messages.ResponseBatchItem( - operation=batch_item.operation, - unique_batch_item_id=batch_item.unique_batch_item_id, - result_status=result_status, - result_reason=result_reason, - result_message=result_message, - response_payload=response_payload - ) - response_batch.append(batch_item) + error_occurred = True + result_status = enums.ResultStatus.OPERATION_FAILED + result_reason = enums.ResultReason.GENERAL_FAILURE + result_message = ( + "Operation failed. See the server logs for more " + "information." + ) + + # Compose operation result. + result_status = contents.ResultStatus(result_status) + if result_reason: + result_reason = contents.ResultReason(result_reason) + if result_message: + result_message = contents.ResultMessage(result_message) + + batch_item = messages.ResponseBatchItem( + operation=batch_item.operation, + unique_batch_item_id=batch_item.unique_batch_item_id, + result_status=result_status, + result_reason=result_reason, + result_message=result_message, + response_payload=response_payload + ) + response_batch.append(batch_item) - # Handle batch error if necessary. - if error_occurred: - if batch_handling == enums.BatchErrorContinuationOption.STOP: - break + # Handle batch error if necessary. + if error_occurred: + if batch_handling == enums.BatchErrorContinuationOption.STOP: + break return response_batch @@ -439,7 +440,7 @@ def _get_object_type(self, unique_identifier): ).filter( objects.ManagedObject.unique_identifier == unique_identifier ).one()[0] - except exc.NoResultFound as e: + except exc.NoResultFound: self._logger.warning( "Could not identify object type for object: {0}".format( unique_identifier diff --git a/kmip/services/server/session.py b/kmip/services/server/session.py index 32f369eb..c6a5f70c 100644 --- a/kmip/services/server/session.py +++ b/kmip/services/server/session.py @@ -107,7 +107,7 @@ def run(self): while True: try: self._handle_message_loop() - except exceptions.ConnectionClosed as e: + except exceptions.ConnectionClosed: break except Exception as e: self._logger.info("Failure handling message loop") @@ -127,7 +127,8 @@ def _handle_message_loop(self): ) try: - if hasattr(self._connection, 'shared_ciphers'): + if (hasattr(self._connection, 'shared_ciphers') + and self._connection.shared_ciphers() is not None): shared_ciphers = self._connection.shared_ciphers() self._logger.debug( "Possible session ciphers: {0}".format(len(shared_ciphers)) diff --git a/kmip/tests/integration/services/test_proxykmipclient.py b/kmip/tests/integration/services/test_proxykmipclient.py index aeecc03e..9af12636 100644 --- a/kmip/tests/integration/services/test_proxykmipclient.py +++ b/kmip/tests/integration/services/test_proxykmipclient.py @@ -39,6 +39,7 @@ def tearDown(self): uuids = self.client.locate() for uuid in uuids: + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, uuid) self.client.destroy(uid=uuid) def test_symmetric_key_create_get_destroy(self): @@ -57,6 +58,7 @@ def test_symmetric_key_create_get_destroy(self): enums.CryptographicAlgorithm.AES) self.assertEqual(key.cryptographic_length, 256) finally: + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, uid) self.client.destroy(uid) self.assertRaises( exceptions.KmipOperationFailure, self.client.get, uid) @@ -100,10 +102,9 @@ def test_create_get_wrapped_destroy(self): self.assertNotEqual(unwrapped_key.value, wrapped_key.value) - self.client.revoke( - enums.RevocationReasonCode.CESSATION_OF_OPERATION, - wrapping_id - ) + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id) + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, + wrapping_id) self.client.destroy(key_id) self.client.destroy(wrapping_id) @@ -131,6 +132,7 @@ def test_symmetric_key_register_get_destroy(self): self.assertEqual( result, key, "expected {0}\nobserved {1}".format(result, key)) finally: + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, uid) self.client.destroy(uid) self.assertRaises( exceptions.KmipOperationFailure, self.client.get, uid) @@ -181,6 +183,69 @@ def test_register_wrapped_get_destroy(self): enums.EncodingOption.NO_ENCODING, key_wrapping_data.get('encoding_option') ) + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id) + self.client.destroy(key_id) + + def test_register_app_specific_get(self): + """ + Test that a key with app specifc info can be registered with the + server and that its metadata is retrieved with the get operation. + """ + key = objects.SymmetricKey( + enums.CryptographicAlgorithm.AES, + 128, + (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': 'Testing3', + 'application_data': 'Testing4' + } + ] + ) + key_id = self.client.register(key) + 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) + + attribute = attribute_list[0] + self.assertEqual( + 'Application Specific Information', + attribute.attribute_name.value + ) + self.assertEqual( + 'Testing', + attribute.attribute_value.application_namespace + ) + self.assertEqual( + 'Testing2', + attribute.attribute_value.application_data + ) + + attribute2 = attribute_list[1] + self.assertEqual( + 'Application Specific Information', + attribute2.attribute_name.value + ) + self.assertEqual( + 'Testing3', + attribute2.attribute_value.application_namespace + ) + self.assertEqual( + 'Testing4', + attribute2.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): """ @@ -211,6 +276,8 @@ def test_asymmetric_key_pair_create_get_destroy(self): enums.CryptographicAlgorithm.RSA) self.assertEqual(private_key.cryptographic_length, 2048) finally: + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, + public_uid) self.client.destroy(public_uid) self.assertRaises( exceptions.KmipOperationFailure, self.client.get, public_uid) @@ -218,6 +285,8 @@ def test_asymmetric_key_pair_create_get_destroy(self): exceptions.KmipOperationFailure, self.client.destroy, public_uid) + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, + private_uid) self.client.destroy(private_uid) self.assertRaises( exceptions.KmipOperationFailure, self.client.get, private_uid) @@ -264,6 +333,7 @@ def test_public_key_register_get_destroy(self): self.assertEqual( result, key, "expected {0}\nobserved {1}".format(result, key)) finally: + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, uid) self.client.destroy(uid) self.assertRaises( exceptions.KmipOperationFailure, self.client.get, uid) @@ -371,6 +441,7 @@ def test_private_key_register_get_destroy(self): self.assertEqual( result, key, "expected {0}\nobserved {1}".format(result, key)) finally: + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, uid) self.client.destroy(uid) self.assertRaises( exceptions.KmipOperationFailure, self.client.get, uid) @@ -449,6 +520,7 @@ def test_x509_certificate_register_get_destroy(self): result, cert, "expected {0}\nobserved {1}".format( result, cert)) finally: + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, uid) self.client.destroy(uid) self.assertRaises( exceptions.KmipOperationFailure, self.client.get, uid) @@ -476,6 +548,82 @@ def test_secret_data_register_get_destroy(self): result, secret, "expected {0}\nobserved {1}".format( result, secret)) 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_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' + }, + { + 'application_namespace': 'Testing3', + 'application_data': 'Testing4' + } + ] + ) + + 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) + + attribute = attribute_list[0] + self.assertEqual( + 'Application Specific Information', + attribute.attribute_name.value + ) + self.assertEqual( + 'Testing', + attribute.attribute_value.application_namespace + ) + self.assertEqual( + 'Testing2', + attribute.attribute_value.application_data + ) + + attribute2 = attribute_list[1] + self.assertEqual( + 'Application Specific Information', + attribute2.attribute_name.value + ) + self.assertEqual( + 'Testing3', + attribute2.attribute_value.application_namespace + ) + self.assertEqual( + 'Testing4', + attribute2.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) @@ -570,6 +718,8 @@ def test_derive_key_using_pbkdf2(self): attribute.attribute_name.value ) self.assertEqual(160, attribute.attribute_value.value) + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id) + self.client.destroy(key_id) def test_derive_key_using_encryption(self): """ @@ -798,10 +948,7 @@ def test_encrypt_decrypt(self): self.assertEqual(plain_text, result) # Clean up. - self.client.revoke( - enums.RevocationReasonCode.CESSATION_OF_OPERATION, - key_id - ) + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, key_id) self.client.destroy(key_id) def test_create_key_pair_sign_signature_verify(self): @@ -858,11 +1005,11 @@ def test_create_key_pair_sign_signature_verify(self): # Clean up. self.client.revoke( - enums.RevocationReasonCode.CESSATION_OF_OPERATION, + enums.RevocationReasonCode.KEY_COMPROMISE, public_key_id ) self.client.revoke( - enums.RevocationReasonCode.CESSATION_OF_OPERATION, + enums.RevocationReasonCode.KEY_COMPROMISE, private_key_id ) self.client.destroy(public_key_id) @@ -1293,6 +1440,8 @@ def test_create_getattributes_locate_destroy(self): self.assertEqual(0, len(result)) # Clean up the keys + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, a_id) + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, b_id) self.client.destroy(a_id) self.client.destroy(b_id) @@ -1344,6 +1493,7 @@ def test_split_key_register_get_destroy(self): self.assertEqual(enums.SplitKeyMethod.XOR, result.split_key_method) self.assertIsNone(result.prime_field_size) finally: + self.client.revoke(enums.RevocationReasonCode.KEY_COMPROMISE, uid) self.client.destroy(uid) self.assertRaises( exceptions.KmipOperationFailure, self.client.get, uid) diff --git a/kmip/tests/unit/core/messages/test_messages.py b/kmip/tests/unit/core/messages/test_messages.py index 1576e62a..0e3feda1 100644 --- a/kmip/tests/unit/core/messages/test_messages.py +++ b/kmip/tests/unit/core/messages/test_messages.py @@ -431,9 +431,9 @@ def test_create_request_read(self): msg = "Bad batch items type: expected {0}, received {1}" self.assertIsInstance(batch_items, list, msg.format(list, type(batch_items))) - self.assertEquals(1, len(batch_items), - self.msg.format('batch items', 'length', - 1, len(batch_items))) + self.assertEqual(1, len(batch_items), + self.msg.format('batch items', 'length', + 1, len(batch_items))) batch_item = batch_items[0] msg = "Bad batch item type: expected {0}, received {1}" @@ -479,9 +479,9 @@ def test_create_request_read(self): self.assertIsInstance(attributes, list, self.msg.format('attributes', 'type', list, type(attributes))) - self.assertEquals(3, len(attributes), - self.msg.format('attributes', 'length', - 3, len(attributes))) + self.assertEqual(3, len(attributes), + self.msg.format('attributes', 'length', + 3, len(attributes))) attribute_a = attributes[0] self.assertIsInstance(attribute_a, objects.Attribute, @@ -494,10 +494,10 @@ def test_create_request_read(self): self.msg.format('attribute name', 'type', objects.Attribute.AttributeName, type(attribute_name))) - self.assertEquals('Cryptographic Algorithm', attribute_name.value, - self.msg.format('attribute name', 'value', - 'Cryptographic Algorithm', - attribute_name.value)) + self.assertEqual('Cryptographic Algorithm', attribute_name.value, + self.msg.format('attribute name', 'value', + 'Cryptographic Algorithm', + attribute_name.value)) attribute_value = attribute_a.attribute_value exp_type = attr.CryptographicAlgorithm @@ -505,11 +505,11 @@ def test_create_request_read(self): self.assertIsInstance(attribute_value, exp_type, self.msg.format('attribute value', 'type', exp_type, rcv_type)) - self.assertEquals(attribute_value.value, - enums.CryptographicAlgorithm.AES, - self.msg.format('cryptographic algorithm', 'value', - enums.CryptographicAlgorithm.AES, - attribute_value.value)) + self.assertEqual(attribute_value.value, + enums.CryptographicAlgorithm.AES, + self.msg.format('cryptographic algorithm', 'value', + enums.CryptographicAlgorithm.AES, + attribute_value.value)) attribute_b = attributes[1] self.assertIsInstance(attribute_b, objects.Attribute, @@ -522,10 +522,10 @@ def test_create_request_read(self): self.msg.format('attribute name', 'type', objects.Attribute.AttributeName, type(attribute_name))) - self.assertEquals('Cryptographic Length', attribute_name.value, - self.msg.format('attribute name', 'value', - 'Cryptographic Length', - attribute_name.value)) + self.assertEqual('Cryptographic Length', attribute_name.value, + self.msg.format('attribute name', 'value', + 'Cryptographic Length', + attribute_name.value)) attribute_value = attribute_b.attribute_value exp_type = attr.CryptographicLength @@ -533,9 +533,9 @@ def test_create_request_read(self): self.assertIsInstance(attribute_value, exp_type, self.msg.format('attribute value', 'type', exp_type, rcv_type)) - self.assertEquals(attribute_value.value, 128, - self.msg.format('cryptographic length', 'value', - 128, attribute_value.value)) + self.assertEqual(attribute_value.value, 128, + self.msg.format('cryptographic length', 'value', + 128, attribute_value.value)) attribute_c = attributes[2] self.assertIsInstance(attribute_c, objects.Attribute, @@ -548,10 +548,10 @@ def test_create_request_read(self): self.msg.format('attribute name', 'type', objects.Attribute.AttributeName, type(attribute_name))) - self.assertEquals('Cryptographic Usage Mask', attribute_name.value, - self.msg.format('attribute name', 'value', - 'Cryptographic Usage Mask', - attribute_name.value)) + self.assertEqual('Cryptographic Usage Mask', attribute_name.value, + self.msg.format('attribute name', 'value', + 'Cryptographic Usage Mask', + attribute_name.value)) attribute_value = attribute_c.attribute_value exp_type = attr.CryptographicUsageMask @@ -562,9 +562,9 @@ def test_create_request_read(self): flag_encrypt = CryptographicUsageMask.ENCRYPT flag_decrypt = CryptographicUsageMask.DECRYPT exp_value = flag_encrypt.value | flag_decrypt.value - self.assertEquals(attribute_value.value, exp_value, - self.msg.format('cryptographic usage mask', 'value', - exp_value, attribute_value.value)) + self.assertEqual(attribute_value.value, exp_value, + self.msg.format('cryptographic usage mask', 'value', + exp_value, attribute_value.value)) def test_create_request_write(self): prot_ver = contents.ProtocolVersion(1, 1) @@ -662,9 +662,9 @@ def test_get_request_read(self): msg = "Bad batch items type: expected {0}, received {1}" self.assertIsInstance(batch_items, list, msg.format(list, type(batch_items))) - self.assertEquals(1, len(batch_items), - self.msg.format('batch items', 'length', - 1, len(batch_items))) + self.assertEqual(1, len(batch_items), + self.msg.format('batch items', 'length', + 1, len(batch_items))) batch_item = batch_items[0] msg = "Bad batch item type: expected {0}, received {1}" @@ -780,9 +780,9 @@ def test_destroy_request_read(self): msg = "Bad batch items type: expected {0}, received {1}" self.assertIsInstance(batch_items, list, msg.format(list, type(batch_items))) - self.assertEquals(1, len(batch_items), - self.msg.format('batch items', 'length', - 1, len(batch_items))) + self.assertEqual(1, len(batch_items), + self.msg.format('batch items', 'length', + 1, len(batch_items))) batch_item = batch_items[0] msg = "Bad batch item type: expected {0}, received {1}" @@ -899,9 +899,9 @@ def test_register_request_read(self): msg = "Bad batch items type: expected {0}, received {1}" self.assertIsInstance(batch_items, list, msg.format(list, type(batch_items))) - self.assertEquals(1, len(batch_items), - self.msg.format('batch items', 'length', - 1, len(batch_items))) + self.assertEqual(1, len(batch_items), + self.msg.format('batch items', 'length', + 1, len(batch_items))) for batch_item in batch_items: msg = "Bad batch item type: expected {0}, received {1}" @@ -1113,9 +1113,9 @@ def test_locate_request_read(self): batch_items = request_message.batch_items msg = "Bad batch items type: expected {0}, received {1}" - self.assertEquals(1, len(batch_items), - self.msg.format('batch items', 'length', - 1, len(batch_items))) + self.assertEqual(1, len(batch_items), + self.msg.format('batch items', 'length', + 1, len(batch_items))) batch_item = batch_items[0] msg = "Bad batch item type: expected {0}, received {1}" @@ -1164,10 +1164,9 @@ def test_locate_request_read(self): self.msg.format('attribute name', 'type', objects.Attribute.AttributeName, type(attribute_name))) - self.assertEquals('Object Type', attribute_name.value, - self.msg.format('attribute name', 'value', - 'Object Type', - attribute_name.value)) + self.assertEqual('Object Type', attribute_name.value, + self.msg.format('attribute name', 'value', + 'Object Type', attribute_name.value)) attribute_value = attribute_a.attribute_value exp_type = attr.Enumeration @@ -1175,7 +1174,7 @@ def test_locate_request_read(self): self.assertIsInstance(attribute_value, exp_type, self.msg.format('attribute value', 'type', exp_type, rcv_type)) - self.assertEquals( + self.assertEqual( attribute_value.value, enums.ObjectType.SYMMETRIC_KEY, self.msg.format( @@ -1193,10 +1192,10 @@ def test_locate_request_read(self): self.msg.format('attribute name', 'type', objects.Attribute.AttributeName, type(attribute_name))) - self.assertEquals('Name', attribute_name.value, - self.msg.format('attribute name', 'value', - 'Name', - attribute_name.value)) + self.assertEqual('Name', attribute_name.value, + self.msg.format('attribute name', 'value', + 'Name', + attribute_name.value)) attribute_value = attribute_b.attribute_value exp_type = Name @@ -1204,10 +1203,10 @@ def test_locate_request_read(self): self.assertIsInstance(attribute_value, exp_type, self.msg.format('attribute value', 'type', exp_type, rcv_type)) - self.assertEquals('Key1', attribute_value.name_value.value, - self.msg.format('name value', 'value', - 'Key1', - attribute_value.name_value.value)) + self.assertEqual('Key1', attribute_value.name_value.value, + self.msg.format('name value', 'value', + 'Key1', + attribute_value.name_value.value)) def test_mac_request_read(self): self.stream = BytearrayStream(self.mac) @@ -1260,9 +1259,9 @@ def test_mac_request_read(self): msg = "Bad batch items type: expected {0}, received {1}" self.assertIsInstance(batch_items, list, msg.format(list, type(batch_items))) - self.assertEquals(1, len(batch_items), - self.msg.format('batch items', 'length', - 1, len(batch_items))) + self.assertEqual(1, len(batch_items), + self.msg.format('batch items', 'length', + 1, len(batch_items))) batch_item = batch_items[0] msg = "Bad batch item type: expected {0}, received {1}" @@ -1310,10 +1309,10 @@ def test_mac_request_read(self): msg.format(enums.CryptographicAlgorithm, type(cryptographic_algorithm))) msg = "Bad cryptographic algorithm value: expected {0}, received {1}" - self.assertEquals(cryptographic_algorithm, - enums.CryptographicAlgorithm.HMAC_SHA512, - msg.format(cryptographic_algorithm, - enums.CryptographicAlgorithm.HMAC_SHA512)) + self.assertEqual(cryptographic_algorithm, + enums.CryptographicAlgorithm.HMAC_SHA512, + msg.format(cryptographic_algorithm, + enums.CryptographicAlgorithm.HMAC_SHA512)) data = request_payload.data msg = "Bad data type: expected {0}, received {1}" @@ -1922,9 +1921,9 @@ def test_destroy_response_read(self): msg = "Bad batch items type: expected {0}, received {1}" self.assertIsInstance(batch_items, list, msg.format(list, type(batch_items))) - self.assertEquals(1, len(batch_items), - self.msg.format('batch items', 'length', - 1, len(batch_items))) + self.assertEqual(1, len(batch_items), + self.msg.format('batch items', 'length', + 1, len(batch_items))) for batch_item in batch_items: msg = "Bad batch item type: expected {0}, received {1}" @@ -2065,9 +2064,9 @@ def test_register_response_read(self): msg = "Bad batch items type: expected {0}, received {1}" self.assertIsInstance(batch_items, list, msg.format(list, type(batch_items))) - self.assertEquals(1, len(batch_items), - self.msg.format('batch items', 'length', - 1, len(batch_items))) + self.assertEqual(1, len(batch_items), + self.msg.format('batch items', 'length', + 1, len(batch_items))) for batch_item in batch_items: msg = "Bad batch item type: expected {0}, received {1}" diff --git a/kmip/tests/unit/core/test_enums.py b/kmip/tests/unit/core/test_enums.py index c0c91977..9a419309 100644 --- a/kmip/tests/unit/core/test_enums.py +++ b/kmip/tests/unit/core/test_enums.py @@ -34,7 +34,7 @@ def test_greater_than_or_equal(self): enums.KMIPVersion.KMIP_1_0 >= enums.KMIPVersion.KMIP_2_0 ) - self.assertEquals( + self.assertEqual( NotImplemented, enums.KMIPVersion.KMIP_2_0.__ge__(enums.WrappingMethod.ENCRYPT) ) @@ -47,7 +47,7 @@ def test_greater_than(self): enums.KMIPVersion.KMIP_1_1 > enums.KMIPVersion.KMIP_1_3 ) - self.assertEquals( + self.assertEqual( NotImplemented, enums.KMIPVersion.KMIP_2_0.__gt__(enums.WrappingMethod.ENCRYPT) ) @@ -60,7 +60,7 @@ def test_less_than_or_equal(self): enums.KMIPVersion.KMIP_1_4 <= enums.KMIPVersion.KMIP_1_3 ) - self.assertEquals( + self.assertEqual( NotImplemented, enums.KMIPVersion.KMIP_2_0.__le__(enums.WrappingMethod.ENCRYPT) ) @@ -73,7 +73,7 @@ def test_less_than(self): enums.KMIPVersion.KMIP_2_0 < enums.KMIPVersion.KMIP_1_3 ) - self.assertEquals( + self.assertEqual( NotImplemented, enums.KMIPVersion.KMIP_2_0.__lt__(enums.WrappingMethod.ENCRYPT) ) @@ -174,7 +174,7 @@ def test_convert_attribute_name_to_tag(self): args = ("invalid", ) self.assertRaisesRegex( ValueError, - "Unrecognized attribute name: 'invalid'".format(args[0]), + "Unrecognized attribute name: 'invalid'", enums.convert_attribute_name_to_tag, *args ) diff --git a/kmip/tests/unit/pie/objects/test_opaque_object.py b/kmip/tests/unit/pie/objects/test_opaque_object.py index f41f1b0e..6a7542ce 100644 --- a/kmip/tests/unit/pie/objects/test_opaque_object.py +++ b/kmip/tests/unit/pie/objects/test_opaque_object.py @@ -253,11 +253,11 @@ def test_add_multiple_names(self): self.bytes_a, enums.OpaqueDataType.NONE, name=expected_names[0]) obj.names.append(expected_names[1]) obj.names.append(expected_names[2]) - self.assertEquals(3, obj.name_index) + self.assertEqual(3, obj.name_index) expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_mo_names, obj._names) + self.assertEqual(expected_mo_names, obj._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -269,7 +269,7 @@ def test_add_multiple_names(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_name(self): """ @@ -284,7 +284,7 @@ def test_remove_name(self): obj.names.append(names[1]) obj.names.append(names[2]) obj.names.pop(remove_index) - self.assertEquals(3, obj.name_index) + self.assertEqual(3, obj.name_index) expected_names = list() expected_mo_names = list() @@ -292,8 +292,8 @@ def test_remove_name(self): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_names, obj.names) - self.assertEquals(expected_mo_names, obj._names) + self.assertEqual(expected_names, obj.names) + self.assertEqual(expected_mo_names, obj._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -305,8 +305,8 @@ def test_remove_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_and_add_name(self): """ @@ -323,7 +323,7 @@ def test_remove_and_add_name(self): obj.names.pop() obj.names.pop() obj.names.append('dog') - self.assertEquals(4, obj.name_index) + self.assertEqual(4, obj.name_index) expected_names = ['bowser', 'dog'] expected_mo_names = list() @@ -331,8 +331,8 @@ def test_remove_and_add_name(self): 0)) expected_mo_names.append(sqltypes.ManagedObjectName(expected_names[1], 3)) - self.assertEquals(expected_names, obj.names) - self.assertEquals(expected_mo_names, obj._names) + self.assertEqual(expected_names, obj.names) + self.assertEqual(expected_mo_names, obj._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -344,8 +344,8 @@ def test_remove_and_add_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_add_name(self): """ @@ -385,8 +385,8 @@ def test_update_with_add_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_name(self): """ @@ -426,8 +426,8 @@ def test_update_with_remove_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_and_add_name(self): """ @@ -470,5 +470,5 @@ def test_update_with_remove_and_add_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) diff --git a/kmip/tests/unit/pie/objects/test_private_key.py b/kmip/tests/unit/pie/objects/test_private_key.py index 0ad425f4..d03fbdb2 100644 --- a/kmip/tests/unit/pie/objects/test_private_key.py +++ b/kmip/tests/unit/pie/objects/test_private_key.py @@ -597,11 +597,11 @@ def test_add_multiple_names(self): enums.KeyFormatType.PKCS_1, name=expected_names[0]) key.names.append(expected_names[1]) key.names.append(expected_names[2]) - self.assertEquals(3, key.name_index) + self.assertEqual(3, key.name_index) expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_mo_names, key._names) + self.assertEqual(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -613,7 +613,7 @@ def test_add_multiple_names(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_name(self): """ @@ -629,7 +629,7 @@ def test_remove_name(self): key.names.append(names[1]) key.names.append(names[2]) key.names.pop(remove_index) - self.assertEquals(3, key.name_index) + self.assertEqual(3, key.name_index) expected_names = list() expected_mo_names = list() @@ -637,8 +637,8 @@ def test_remove_name(self): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_names, key.names) - self.assertEquals(expected_mo_names, key._names) + self.assertEqual(expected_names, key.names) + self.assertEqual(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -650,8 +650,8 @@ def test_remove_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_and_add_name(self): """ @@ -669,7 +669,7 @@ def test_remove_and_add_name(self): key.names.pop() key.names.pop() key.names.append('dog') - self.assertEquals(4, key.name_index) + self.assertEqual(4, key.name_index) expected_names = ['bowser', 'dog'] expected_mo_names = list() @@ -677,8 +677,8 @@ def test_remove_and_add_name(self): 0)) expected_mo_names.append(sqltypes.ManagedObjectName(expected_names[1], 3)) - self.assertEquals(expected_names, key.names) - self.assertEquals(expected_mo_names, key._names) + self.assertEqual(expected_names, key.names) + self.assertEqual(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -690,8 +690,8 @@ def test_remove_and_add_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_add_name(self): """ @@ -732,8 +732,8 @@ def test_update_with_add_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_name(self): """ @@ -774,8 +774,8 @@ def test_update_with_remove_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_and_add_name(self): """ @@ -819,5 +819,5 @@ def test_update_with_remove_and_add_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) diff --git a/kmip/tests/unit/pie/objects/test_public_key.py b/kmip/tests/unit/pie/objects/test_public_key.py index cf71833b..be63da38 100644 --- a/kmip/tests/unit/pie/objects/test_public_key.py +++ b/kmip/tests/unit/pie/objects/test_public_key.py @@ -495,11 +495,11 @@ def test_add_multiple_names(self): enums.KeyFormatType.PKCS_1, name=expected_names[0]) key.names.append(expected_names[1]) key.names.append(expected_names[2]) - self.assertEquals(3, key.name_index) + self.assertEqual(3, key.name_index) expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_mo_names, key._names) + self.assertEqual(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -511,7 +511,7 @@ def test_add_multiple_names(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_name(self): """ @@ -527,7 +527,7 @@ def test_remove_name(self): key.names.append(names[1]) key.names.append(names[2]) key.names.pop(remove_index) - self.assertEquals(3, key.name_index) + self.assertEqual(3, key.name_index) expected_names = list() expected_mo_names = list() @@ -535,8 +535,8 @@ def test_remove_name(self): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_names, key.names) - self.assertEquals(expected_mo_names, key._names) + self.assertEqual(expected_names, key.names) + self.assertEqual(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -548,8 +548,8 @@ def test_remove_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_and_add_name(self): """ @@ -567,7 +567,7 @@ def test_remove_and_add_name(self): key.names.pop() key.names.pop() key.names.append('dog') - self.assertEquals(4, key.name_index) + self.assertEqual(4, key.name_index) expected_names = ['bowser', 'dog'] expected_mo_names = list() @@ -575,8 +575,8 @@ def test_remove_and_add_name(self): 0)) expected_mo_names.append(sqltypes.ManagedObjectName(expected_names[1], 3)) - self.assertEquals(expected_names, key.names) - self.assertEquals(expected_mo_names, key._names) + self.assertEqual(expected_names, key.names) + self.assertEqual(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -588,8 +588,8 @@ def test_remove_and_add_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_add_name(self): """ @@ -630,8 +630,8 @@ def test_update_with_add_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_name(self): """ @@ -672,8 +672,8 @@ def test_update_with_remove_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_and_add_name(self): """ @@ -717,5 +717,5 @@ def test_update_with_remove_and_add_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) diff --git a/kmip/tests/unit/pie/objects/test_secret_data.py b/kmip/tests/unit/pie/objects/test_secret_data.py index 1cfe075d..c11317b3 100644 --- a/kmip/tests/unit/pie/objects/test_secret_data.py +++ b/kmip/tests/unit/pie/objects/test_secret_data.py @@ -272,11 +272,11 @@ def test_add_multiple_names(self): name=expected_names[0]) obj.names.append(expected_names[1]) obj.names.append(expected_names[2]) - self.assertEquals(3, obj.name_index) + self.assertEqual(3, obj.name_index) expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_mo_names, obj._names) + self.assertEqual(expected_mo_names, obj._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -288,7 +288,7 @@ def test_add_multiple_names(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_name(self): """ @@ -303,7 +303,7 @@ def test_remove_name(self): obj.names.append(names[1]) obj.names.append(names[2]) obj.names.pop(remove_index) - self.assertEquals(3, obj.name_index) + self.assertEqual(3, obj.name_index) expected_names = list() expected_mo_names = list() @@ -311,8 +311,8 @@ def test_remove_name(self): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_names, obj.names) - self.assertEquals(expected_mo_names, obj._names) + self.assertEqual(expected_names, obj.names) + self.assertEqual(expected_mo_names, obj._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -324,8 +324,8 @@ def test_remove_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_and_add_name(self): """ @@ -342,7 +342,7 @@ def test_remove_and_add_name(self): obj.names.pop() obj.names.pop() obj.names.append('dog') - self.assertEquals(4, obj.name_index) + self.assertEqual(4, obj.name_index) expected_names = ['bowser', 'dog'] expected_mo_names = list() @@ -350,8 +350,8 @@ def test_remove_and_add_name(self): 0)) expected_mo_names.append(sqltypes.ManagedObjectName(expected_names[1], 3)) - self.assertEquals(expected_names, obj.names) - self.assertEquals(expected_mo_names, obj._names) + self.assertEqual(expected_names, obj.names) + self.assertEqual(expected_mo_names, obj._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -363,8 +363,8 @@ def test_remove_and_add_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_add_name(self): """ @@ -404,8 +404,8 @@ def test_update_with_add_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_name(self): """ @@ -445,8 +445,8 @@ def test_update_with_remove_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_and_add_name(self): """ @@ -489,5 +489,5 @@ def test_update_with_remove_and_add_name(self): ManagedObject.unique_identifier == obj.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) diff --git a/kmip/tests/unit/pie/objects/test_symmetric_key.py b/kmip/tests/unit/pie/objects/test_symmetric_key.py index cf7f5dff..548c535f 100644 --- a/kmip/tests/unit/pie/objects/test_symmetric_key.py +++ b/kmip/tests/unit/pie/objects/test_symmetric_key.py @@ -184,11 +184,13 @@ def test_repr(self): self.bytes_128a ) - args = "{0}, {1}, {2}, {3}".format( + args = "{0}, {1}, {2}, {3}, {4}, {5}".format( "algorithm={0}".format(enums.CryptographicAlgorithm.AES), "length={0}".format(128), "value={0}".format(binascii.hexlify(self.bytes_128a)), - "key_wrapping_data={0}".format({}) + "masks={0}".format([]), + "names={0}".format(['Symmetric Key']), + "key_wrapping_data={0}".format({}), ) expected = "SymmetricKey({0})".format(args) observed = repr(key) @@ -442,11 +444,11 @@ def test_add_multiple_names(self): name=expected_names[0]) key.names.append(expected_names[1]) key.names.append(expected_names[2]) - self.assertEquals(3, key.name_index) + self.assertEqual(3, key.name_index) expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_mo_names, key._names) + self.assertEqual(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -458,7 +460,7 @@ def test_add_multiple_names(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_name(self): """ @@ -474,7 +476,7 @@ def test_remove_name(self): key.names.append(names[1]) key.names.append(names[2]) key.names.pop(remove_index) - self.assertEquals(3, key.name_index) + self.assertEqual(3, key.name_index) expected_names = list() expected_mo_names = list() @@ -482,8 +484,8 @@ def test_remove_name(self): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_names, key.names) - self.assertEquals(expected_mo_names, key._names) + self.assertEqual(expected_names, key.names) + self.assertEqual(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -495,8 +497,8 @@ def test_remove_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_and_add_name(self): """ @@ -514,7 +516,7 @@ def test_remove_and_add_name(self): key.names.pop() key.names.pop() key.names.append('dog') - self.assertEquals(4, key.name_index) + self.assertEqual(4, key.name_index) expected_names = ['bowser', 'dog'] expected_mo_names = list() @@ -522,8 +524,8 @@ def test_remove_and_add_name(self): 0)) expected_mo_names.append(sqltypes.ManagedObjectName(expected_names[1], 3)) - self.assertEquals(expected_names, key.names) - self.assertEquals(expected_mo_names, key._names) + self.assertEqual(expected_names, key.names) + self.assertEqual(expected_mo_names, key._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -535,8 +537,8 @@ def test_remove_and_add_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_add_name(self): """ @@ -577,8 +579,8 @@ def test_update_with_add_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_name(self): """ @@ -619,8 +621,8 @@ def test_update_with_remove_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_and_add_name(self): """ @@ -664,5 +666,5 @@ def test_update_with_remove_and_add_name(self): ManagedObject.unique_identifier == key.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) diff --git a/kmip/tests/unit/pie/objects/test_x509_certificate.py b/kmip/tests/unit/pie/objects/test_x509_certificate.py index f4d76ada..dba77617 100644 --- a/kmip/tests/unit/pie/objects/test_x509_certificate.py +++ b/kmip/tests/unit/pie/objects/test_x509_certificate.py @@ -348,11 +348,11 @@ def test_add_multiple_names(self): cert = X509Certificate(self.bytes_a, name=expected_names[0]) cert.names.append(expected_names[1]) cert.names.append(expected_names[2]) - self.assertEquals(3, cert.name_index) + self.assertEqual(3, cert.name_index) expected_mo_names = list() for i, name in enumerate(expected_names): expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_mo_names, cert._names) + self.assertEqual(expected_mo_names, cert._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -364,7 +364,7 @@ def test_add_multiple_names(self): ManagedObject.unique_identifier == cert.unique_identifier ).one() session.commit() - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_name(self): """ @@ -378,7 +378,7 @@ def test_remove_name(self): cert.names.append(names[1]) cert.names.append(names[2]) cert.names.pop(remove_index) - self.assertEquals(3, cert.name_index) + self.assertEqual(3, cert.name_index) expected_names = list() expected_mo_names = list() @@ -386,8 +386,8 @@ def test_remove_name(self): if i != remove_index: expected_names.append(name) expected_mo_names.append(sqltypes.ManagedObjectName(name, i)) - self.assertEquals(expected_names, cert.names) - self.assertEquals(expected_mo_names, cert._names) + self.assertEqual(expected_names, cert.names) + self.assertEqual(expected_mo_names, cert._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -399,8 +399,8 @@ def test_remove_name(self): ManagedObject.unique_identifier == cert.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_remove_and_add_name(self): """ @@ -416,7 +416,7 @@ def test_remove_and_add_name(self): cert.names.pop() cert.names.pop() cert.names.append('dog') - self.assertEquals(4, cert.name_index) + self.assertEqual(4, cert.name_index) expected_names = ['bowser', 'dog'] expected_mo_names = list() @@ -424,8 +424,8 @@ def test_remove_and_add_name(self): 0)) expected_mo_names.append(sqltypes.ManagedObjectName(expected_names[1], 3)) - self.assertEquals(expected_names, cert.names) - self.assertEquals(expected_mo_names, cert._names) + self.assertEqual(expected_names, cert.names) + self.assertEqual(expected_mo_names, cert._names) Session = sessionmaker(bind=self.engine, expire_on_commit=False) session = Session() @@ -437,8 +437,8 @@ def test_remove_and_add_name(self): ManagedObject.unique_identifier == cert.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_add_name(self): """ @@ -477,8 +477,8 @@ def test_update_with_add_name(self): ManagedObject.unique_identifier == cert.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_name(self): """ @@ -517,8 +517,8 @@ def test_update_with_remove_name(self): ManagedObject.unique_identifier == cert.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) def test_update_with_remove_and_add_name(self): """ @@ -560,5 +560,5 @@ def test_update_with_remove_and_add_name(self): ManagedObject.unique_identifier == cert.unique_identifier ).one() session.commit() - self.assertEquals(expected_names, get_obj.names) - self.assertEquals(expected_mo_names, get_obj._names) + self.assertEqual(expected_names, get_obj.names) + self.assertEqual(expected_mo_names, get_obj._names) diff --git a/kmip/tests/unit/services/server/auth/test_slugs.py b/kmip/tests/unit/services/server/auth/test_slugs.py index 51f56771..49fa0c99 100644 --- a/kmip/tests/unit/services/server/auth/test_slugs.py +++ b/kmip/tests/unit/services/server/auth/test_slugs.py @@ -137,10 +137,10 @@ def test_authenticate(self, mock_get_client_identity, mock_request_get): mock_get_client_identity.assert_called_once_with("test") mock_request_get.assert_any_call( - "http://127.0.0.1:8080/test/slugs/users/John Doe" + "http://127.0.0.1:8080/test/slugs/users/John Doe", timeout=10 ) mock_request_get.assert_any_call( - "http://127.0.0.1:8080/test/slugs/users/John Doe/groups" + "http://127.0.0.1:8080/test/slugs/users/John Doe/groups", timeout=10 ) self.assertEqual(('John Doe', ['Group A', 'Group B']), result) diff --git a/kmip/tests/unit/services/server/crypto/test_engine.py b/kmip/tests/unit/services/server/crypto/test_engine.py index 4adb222b..edb52832 100644 --- a/kmip/tests/unit/services/server/crypto/test_engine.py +++ b/kmip/tests/unit/services/server/crypto/test_engine.py @@ -247,8 +247,8 @@ def __init__(self): engine = crypto.CryptographyEngine() - # IDEA is not block cipher so cmac should raise exception - args = [enums.CryptographicAlgorithm.IDEA, key, data] + # RC4 is not block cipher so cmac should raise exception + args = [enums.CryptographicAlgorithm.RC4, key, data] self.assertRaises( exceptions.CryptographicFailure, engine.mac, diff --git a/kmip/tests/unit/services/test_kmip_client.py b/kmip/tests/unit/services/test_kmip_client.py index d2b0f823..fa13a204 100644 --- a/kmip/tests/unit/services/test_kmip_client.py +++ b/kmip/tests/unit/services/test_kmip_client.py @@ -81,7 +81,7 @@ def setUp(self): self.cred_factory = CredentialFactory() self.secret_factory = SecretFactory() - self.client = KMIPProxy() + self.client = KMIPProxy(config_file="/dev/null") KMIP_PORT = 9090 CA_CERTS_PATH = os.path.normpath(os.path.join(os.path.dirname( diff --git a/kmip/version.py b/kmip/version.py index f4e53cd9..7d6667c0 100644 --- a/kmip/version.py +++ b/kmip/version.py @@ -13,4 +13,4 @@ # License for the specific language governing permissions and limitations # under the License. -__version__ = "0.11.0dev1" +__version__ = "0.11.0.dev1" diff --git a/setup.py b/setup.py index eba36b10..19904f1a 100644 --- a/setup.py +++ b/setup.py @@ -18,11 +18,8 @@ import setuptools # Dynamically set __version__ -version_path = os.path.join( - os.path.dirname(os.path.realpath(__file__)), - "kmip", - "version.py" -) +this_dir = os.path.dirname(os.path.realpath(__file__)) +version_path = os.path.join(this_dir, "kmip", "version.py") with open(version_path, 'r') as f: m = re.search( r"^__version__ = \"(\d+\.\d+\..*)\"$", @@ -30,6 +27,9 @@ re.MULTILINE ) __version__ = m.group(1) +readme_path = os.path.join(this_dir, "README.rst") +with open(readme_path, 'r') as f: + long_description = f.read() setuptools.setup( name='PyKMIP', @@ -40,6 +40,8 @@ author_email='peter.hamilton@jhuapl.edu', url='https://github.com/OpenKMIP/PyKMIP', license='Apache License, Version 2.0', + long_description=long_description, + long_description_content_type="text/x-rst", packages=setuptools.find_packages(exclude=["kmip.tests", "kmip.tests.*"]), package_data={'kmip': ['kmipconfig.ini', 'logconfig.ini'], 'kmip.demos': ['certs/server.crt', 'certs/server.key']}, diff --git a/test-requirements.txt b/test-requirements.txt index e85409b8..1ab6197d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,5 +6,5 @@ fixtures mock slugs sphinx -PyYAML<=5.2 -bandit==1.5.1 +PyYAML +bandit diff --git a/tox.ini b/tox.ini index f7b61c10..31cb52fd 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] -envlist = pep8,py27,py34,py35,py36,py37,bandit,docs +envlist = pep8,py38,py310,bandit,docs [testenv] -passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH +passenv = * deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt @@ -48,3 +48,4 @@ commands = [flake8] exclude = .git,.tox,dist,rpmbuild,*.egg-info +max-line-length = 88