From 850e63d34b015abb05ef3ff7b39d0b32f4fa4d16 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Fri, 24 Apr 2020 11:18:39 -0700 Subject: [PATCH 1/2] chore: fix pylint-test configuration --- test_vector_handlers/test/pylintrc | 16 ++++++++++++++++ test_vector_handlers/tox.ini | 2 -- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test_vector_handlers/test/pylintrc diff --git a/test_vector_handlers/test/pylintrc b/test_vector_handlers/test/pylintrc new file mode 100644 index 000000000..794e2039f --- /dev/null +++ b/test_vector_handlers/test/pylintrc @@ -0,0 +1,16 @@ +[MESSAGES CONTROL] +# Disabling messages that we either don't care about for tests or are necessary to break for tests. +disable = + invalid-name, # we prefer long, descriptive, names for tests + missing-docstring, # we don't write docstrings for tests + bad-continuation, # we let black handle this + ungrouped-imports, # we let isort handle this + useless-object-inheritance, # we need to support Python 2, so no, not useless + duplicate-code, # unit tests for similar things tend to be similar + redefined-outer-name, # raised when using decorators + +[FORMAT] +max-line-length = 120 + +[REPORTS] +msg-template = {path}:{line}: [{msg_id}({symbol}), {obj}] {msg} diff --git a/test_vector_handlers/tox.ini b/test_vector_handlers/tox.ini index d62bc38ea..4c6e4edf9 100644 --- a/test_vector_handlers/tox.ini +++ b/test_vector_handlers/tox.ini @@ -145,8 +145,6 @@ deps = {[testenv:pylint]deps} commands = pylint \ --rcfile=test/pylintrc \ - test/unit/ \ - test/functional/ \ test/integration/ \ {posargs} From 53699038fef99fbba7f977102a01b098ceb1c6a0 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Fri, 24 Apr 2020 11:19:02 -0700 Subject: [PATCH 2/2] chore: clean up linting issues in test vector handler --- .../src/awses_test_vectors/__init__.py | 1 + .../src/awses_test_vectors/commands/__init__.py | 1 + .../commands/full_message_decrypt.py | 4 +--- .../commands/full_message_encrypt.py | 4 +--- .../src/awses_test_vectors/internal/__init__.py | 6 ++++++ .../src/awses_test_vectors/internal/aws_kms.py | 4 +--- .../src/awses_test_vectors/internal/defaults.py | 4 +--- .../src/awses_test_vectors/internal/mypy_types.py | 4 +--- .../src/awses_test_vectors/internal/util.py | 14 ++++++-------- .../src/awses_test_vectors/manifests/__init__.py | 1 + .../manifests/full_message/__init__.py | 1 + .../manifests/full_message/decrypt.py | 5 +++-- .../src/awses_test_vectors/manifests/keys.py | 1 + test_vector_handlers/src/pylintrc | 1 + 14 files changed, 26 insertions(+), 25 deletions(-) diff --git a/test_vector_handlers/src/awses_test_vectors/__init__.py b/test_vector_handlers/src/awses_test_vectors/__init__.py index bc29247ad..983918476 100644 --- a/test_vector_handlers/src/awses_test_vectors/__init__.py +++ b/test_vector_handlers/src/awses_test_vectors/__init__.py @@ -10,4 +10,5 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +"""Static test vector handling logic for the AWS Encyrption SDK.""" __version__ = "1.0.0" diff --git a/test_vector_handlers/src/awses_test_vectors/commands/__init__.py b/test_vector_handlers/src/awses_test_vectors/commands/__init__.py index 1ccc7fa1a..17b493032 100644 --- a/test_vector_handlers/src/awses_test_vectors/commands/__init__.py +++ b/test_vector_handlers/src/awses_test_vectors/commands/__init__.py @@ -10,3 +10,4 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +"""CLI commands.""" diff --git a/test_vector_handlers/src/awses_test_vectors/commands/full_message_decrypt.py b/test_vector_handlers/src/awses_test_vectors/commands/full_message_decrypt.py index f6ed65c3f..05dbfb4de 100644 --- a/test_vector_handlers/src/awses_test_vectors/commands/full_message_decrypt.py +++ b/test_vector_handlers/src/awses_test_vectors/commands/full_message_decrypt.py @@ -10,9 +10,7 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -""" -AWS Encryption SDK full message decrypt command. -""" +"""AWS Encryption SDK full message decrypt command.""" import argparse from awses_test_vectors.manifests.full_message.decrypt import MessageDecryptionManifest diff --git a/test_vector_handlers/src/awses_test_vectors/commands/full_message_encrypt.py b/test_vector_handlers/src/awses_test_vectors/commands/full_message_encrypt.py index c48ccd0bb..e5a6558f1 100644 --- a/test_vector_handlers/src/awses_test_vectors/commands/full_message_encrypt.py +++ b/test_vector_handlers/src/awses_test_vectors/commands/full_message_encrypt.py @@ -10,9 +10,7 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -""" -AWS Encryption SDK full message encrypt command. -""" +"""AWS Encryption SDK full message encrypt command.""" import argparse from awses_test_vectors.manifests.full_message.encrypt import MessageEncryptionManifest diff --git a/test_vector_handlers/src/awses_test_vectors/internal/__init__.py b/test_vector_handlers/src/awses_test_vectors/internal/__init__.py index 1ccc7fa1a..34bfd8a1d 100644 --- a/test_vector_handlers/src/awses_test_vectors/internal/__init__.py +++ b/test_vector_handlers/src/awses_test_vectors/internal/__init__.py @@ -10,3 +10,9 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +"""Internal implementation details. + +.. warning:: + No guarantee is provided on the modules and APIs within this + namespace staying consistent. Directly reference at your own risk. +""" diff --git a/test_vector_handlers/src/awses_test_vectors/internal/aws_kms.py b/test_vector_handlers/src/awses_test_vectors/internal/aws_kms.py index 286f95c60..5893c6270 100644 --- a/test_vector_handlers/src/awses_test_vectors/internal/aws_kms.py +++ b/test_vector_handlers/src/awses_test_vectors/internal/aws_kms.py @@ -10,9 +10,7 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -""" -Helper utilities for interacting with AWS KMS. -""" +"""Helper utilities for interacting with AWS KMS.""" try: from aws_encryption_sdk.identifiers import AlgorithmSuite except ImportError: diff --git a/test_vector_handlers/src/awses_test_vectors/internal/defaults.py b/test_vector_handlers/src/awses_test_vectors/internal/defaults.py index bc17ef658..d72a9287d 100644 --- a/test_vector_handlers/src/awses_test_vectors/internal/defaults.py +++ b/test_vector_handlers/src/awses_test_vectors/internal/defaults.py @@ -10,8 +10,6 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -""" -Default values for use in AWS Encryption SDK test vector handlers. -""" +"""Default values for use in AWS Encryption SDK test vector handlers.""" ENCODING = "utf-8" diff --git a/test_vector_handlers/src/awses_test_vectors/internal/mypy_types.py b/test_vector_handlers/src/awses_test_vectors/internal/mypy_types.py index 49147619e..e669c8a2f 100644 --- a/test_vector_handlers/src/awses_test_vectors/internal/mypy_types.py +++ b/test_vector_handlers/src/awses_test_vectors/internal/mypy_types.py @@ -10,9 +10,7 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -""" -MyPy types for use in AWS Encryption SDK test vector handlers. -""" +"""MyPy types for use in AWS Encryption SDK test vector handlers.""" # mypy types confuse pylint: disable=invalid-name try: # Python 3.5.0 and 3.5.1 have incompatible typing modules diff --git a/test_vector_handlers/src/awses_test_vectors/internal/util.py b/test_vector_handlers/src/awses_test_vectors/internal/util.py index ff6981db7..4963ff5e7 100644 --- a/test_vector_handlers/src/awses_test_vectors/internal/util.py +++ b/test_vector_handlers/src/awses_test_vectors/internal/util.py @@ -10,9 +10,7 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. -""" -Utility functions for use in AWS Encryption SDK test vector handlers. -""" +"""Utility functions for use in AWS Encryption SDK test vector handlers.""" import os import struct from binascii import unhexlify @@ -100,7 +98,7 @@ def membership_validator(allowed): def _validate_membership(instance, attribute, value): # type: (object, Attribute, Any) -> None # pylint: disable=unused-argument - """""" + """Perform membership check.""" if value not in allowed: raise ValueError( 'Unknown "{name}" value "{actual}" not in {expected}'.format( @@ -178,9 +176,9 @@ def algorithm_suite_from_string_id(string_id): return AlgorithmSuite.get_by_id(numeric_id) -# TODO: I want to replace these functions with an extensible "URI Handler" class -# that will abstract away any file handling. This will vastly simply extending -# these handlers to work with files in some non-local location, such as S3. +# I want to replace these functions with an extensible "URI Handler" class +# that will abstract away any file handling. This will vastly simply extending +# these handlers to work with files in some non-local location, such as S3. def file_writer(parent_dir): # type: (str) -> Callable[[str, bytes], str] """Return a caller that will write the requested named data to a file and return @@ -214,7 +212,7 @@ def _write_file(name, data): def file_reader(parent_dir): # type: (str) -> Callable[[str], bytes] - """Returns a callable that accepts a URI identifying a file relative to ``parent_dir`` + """Return a callable that accepts a URI identifying a file relative to ``parent_dir`` and returns the binary contents of that file. :param str parent_dir: Parent directory to use as the relative root for all URIs diff --git a/test_vector_handlers/src/awses_test_vectors/manifests/__init__.py b/test_vector_handlers/src/awses_test_vectors/manifests/__init__.py index 1ccc7fa1a..e2472c3bb 100644 --- a/test_vector_handlers/src/awses_test_vectors/manifests/__init__.py +++ b/test_vector_handlers/src/awses_test_vectors/manifests/__init__.py @@ -10,3 +10,4 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +"""Test vector manifest handlers.""" diff --git a/test_vector_handlers/src/awses_test_vectors/manifests/full_message/__init__.py b/test_vector_handlers/src/awses_test_vectors/manifests/full_message/__init__.py index 1ccc7fa1a..090bd995e 100644 --- a/test_vector_handlers/src/awses_test_vectors/manifests/full_message/__init__.py +++ b/test_vector_handlers/src/awses_test_vectors/manifests/full_message/__init__.py @@ -10,3 +10,4 @@ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. +"""Full-message test vector manifest handlers.""" diff --git a/test_vector_handlers/src/awses_test_vectors/manifests/full_message/decrypt.py b/test_vector_handlers/src/awses_test_vectors/manifests/full_message/decrypt.py index 640c4d24a..9418afd7b 100644 --- a/test_vector_handlers/src/awses_test_vectors/manifests/full_message/decrypt.py +++ b/test_vector_handlers/src/awses_test_vectors/manifests/full_message/decrypt.py @@ -51,6 +51,7 @@ @attr.s(init=False) class MessageDecryptionTestScenario(object): + # pylint: disable=too-many-arguments """Data class for a single full message decrypt test scenario. Handles serialization and deserialization to and from manifest specs. @@ -156,12 +157,12 @@ def run(self, name): """ plaintext, _header = aws_encryption_sdk.decrypt(source=self.ciphertext, key_provider=self.master_key_provider) if plaintext != self.plaintext: - # TODO: Actually do something here - raise Exception("TODO: ERROR MESSAGE") + raise ValueError("Decrypted plaintext does not match expected value.") @attr.s(init=False) class MessageDecryptionManifest(object): + # pylint: disable=too-many-arguments """AWS Encryption SDK Decrypt Message manifest handler. Described in AWS Crypto Tools Test Vector Framework feature #0003 AWS Encryption SDK Decrypt Message. diff --git a/test_vector_handlers/src/awses_test_vectors/manifests/keys.py b/test_vector_handlers/src/awses_test_vectors/manifests/keys.py index 095b3330a..441caac01 100644 --- a/test_vector_handlers/src/awses_test_vectors/manifests/keys.py +++ b/test_vector_handlers/src/awses_test_vectors/manifests/keys.py @@ -108,6 +108,7 @@ def manifest_spec(self): @attr.s(init=False) class ManualKeySpec(KeySpec): + # pylint: disable=too-many-arguments """Manual key specification. Allowed values described in AWS Crypto Tools Test Vector Framework feature #0002 Keys Manifest. diff --git a/test_vector_handlers/src/pylintrc b/test_vector_handlers/src/pylintrc index 78463742c..2fba3ddfa 100644 --- a/test_vector_handlers/src/pylintrc +++ b/test_vector_handlers/src/pylintrc @@ -4,6 +4,7 @@ disable = bad-continuation, # we let black handle this ungrouped-imports, # we let isort handle this useless-object-inheritance, # we need to support Python 2, so no, not useless + duplicate-code, # the manifest handlers have a lot of similar code [FORMAT] max-line-length = 120