From 457b18b2db02324dcc7e6e64c51ce32f08648c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C4=83t=C4=83lin?= Date: Fri, 23 Jul 2021 12:25:50 +0200 Subject: [PATCH] Test iot certs' validity dates --- moto/ec2/responses/amis.py | 0 moto/iam/models.py | 0 moto/iot/models.py | 6 +++--- moto/iot/responses.py | 2 +- scripts/ec2_get_instance_type_offerings.py | 7 ++++--- scripts/get_instance_info.py | 6 ++---- setup.py | 22 ++++++++++++---------- tests/test_iot/test_iot.py | 6 +++++- update_version_from_git.py | 16 +++++++++++----- 9 files changed, 38 insertions(+), 27 deletions(-) mode change 100755 => 100644 moto/ec2/responses/amis.py mode change 100755 => 100644 moto/iam/models.py diff --git a/moto/ec2/responses/amis.py b/moto/ec2/responses/amis.py old mode 100755 new mode 100644 diff --git a/moto/iam/models.py b/moto/iam/models.py old mode 100755 new mode 100644 diff --git a/moto/iot/models.py b/moto/iot/models.py index ba311094..3b3451b3 100644 --- a/moto/iot/models.py +++ b/moto/iot/models.py @@ -144,8 +144,8 @@ class FakeCertificate(BaseModel): self.transfer_data = {} self.creation_date = time.time() self.last_modified_date = self.creation_date - self.validity_not_before = (time.time() - 86400) - self.validity_not_after = (time.time() + 86400) + self.validity_not_before = time.time() - 86400 + self.validity_not_after = time.time() + 86400 self.ca_certificate_id = None self.ca_certificate_pem = ca_certificate_pem if ca_certificate_pem: @@ -177,7 +177,7 @@ class FakeCertificate(BaseModel): "lastModifiedDate": self.last_modified_date, "validity": { "notBefore": self.validity_not_before, - "notAfter": self.validity_not_after + "notAfter": self.validity_not_after, }, "transferData": self.transfer_data, } diff --git a/moto/iot/responses.py b/moto/iot/responses.py index 3a2804d9..c0de6007 100644 --- a/moto/iot/responses.py +++ b/moto/iot/responses.py @@ -49,7 +49,7 @@ class IoTResponse(BaseResponse): next_token = str(max_results) if len(thing_types) > max_results else None else: token = int(previous_next_token) - result = thing_types[token: token + max_results] + result = thing_types[token : token + max_results] next_token = ( str(token + max_results) if len(thing_types) > token + max_results diff --git a/scripts/ec2_get_instance_type_offerings.py b/scripts/ec2_get_instance_type_offerings.py index 66ce4449..c7961b71 100755 --- a/scripts/ec2_get_instance_type_offerings.py +++ b/scripts/ec2_get_instance_type_offerings.py @@ -37,7 +37,9 @@ def main(): for region in regions: for location_type in TYPES: ec2 = boto3.client("ec2", region_name=region) - dest = os.path.join(root_dir, "{0}/{1}/{2}.json".format(PATH, location_type, region)) + dest = os.path.join( + root_dir, "{0}/{1}/{2}.json".format(PATH, location_type, region) + ) try: instances = [] offerings = ec2.describe_instance_type_offerings( @@ -47,8 +49,7 @@ def main(): next_token = offerings.get("NextToken", "") while next_token: offerings = ec2.describe_instance_type_offerings( - LocationType=location_type, - NextToken=next_token + LocationType=location_type, NextToken=next_token ) instances.extend(offerings["InstanceTypeOfferings"]) next_token = offerings.get("NextToken", None) diff --git a/scripts/get_instance_info.py b/scripts/get_instance_info.py index d8f0b418..56d962a7 100755 --- a/scripts/get_instance_info.py +++ b/scripts/get_instance_info.py @@ -26,9 +26,7 @@ def main(): instances.extend(offerings["InstanceTypes"]) next_token = offerings.get("NextToken", "") while next_token: - offerings = ec2.describe_instance_types( - NextToken=next_token - ) + offerings = ec2.describe_instance_types(NextToken=next_token) instances.extend(offerings["InstanceTypes"]) next_token = offerings.get("NextToken", None) except Exception: @@ -39,7 +37,7 @@ def main(): print("Parsing data") result = {} for instance in instances: - result[instance.get('InstanceType')] = instance + result[instance.get("InstanceType")] = instance root_dir = ( subprocess.check_output(["git", "rev-parse", "--show-toplevel"]) diff --git a/setup.py b/setup.py index dfb6a585..325f847e 100755 --- a/setup.py +++ b/setup.py @@ -104,11 +104,19 @@ all_server_deps = all_extra_deps + ["flask", "flask-cors"] # i.e. even those without extra dependencies. # Would be good for future-compatibility, I guess. extras_per_service = { - "apigateway": [_dep_python_jose_py2, _dep_python_jose_py3, _dep_python_jose_ecdsa_pin], + "apigateway": [ + _dep_python_jose_py2, + _dep_python_jose_py3, + _dep_python_jose_ecdsa_pin, + ], "awslambda": [_dep_docker], "batch": [_dep_docker], "cloudformation": [_dep_docker, _dep_PyYAML, _dep_cfn_lint, _dep_decorator], - "cognitoidp": [_dep_python_jose_py2, _dep_python_jose_py3, _dep_python_jose_ecdsa_pin], + "cognitoidp": [ + _dep_python_jose_py2, + _dep_python_jose_py3, + _dep_python_jose_ecdsa_pin, + ], "dynamodb2": [_dep_docker], "dynamodbstreams": [_dep_docker], "ec2": [_dep_docker, _dep_sshpubkeys_py2, _dep_sshpubkeys_py3], @@ -145,11 +153,7 @@ setup( author="Steve Pulec", author_email="spulec@gmail.com", url="https://github.com/spulec/moto", - entry_points={ - "console_scripts": [ - "moto_server = moto.server:main", - ], - }, + entry_points={"console_scripts": ["moto_server = moto.server:main",],}, packages=find_packages(exclude=("tests", "tests.*")), install_requires=install_requires, extras_require=extras_require, @@ -167,7 +171,5 @@ setup( "License :: OSI Approved :: Apache Software License", "Topic :: Software Development :: Testing", ], - project_urls={ - "Documentation": "http://docs.getmoto.org/en/latest/", - }, + project_urls={"Documentation": "http://docs.getmoto.org/en/latest/",}, ) diff --git a/tests/test_iot/test_iot.py b/tests/test_iot/test_iot.py index 1f9c940e..a6de07be 100644 --- a/tests/test_iot/test_iot.py +++ b/tests/test_iot/test_iot.py @@ -538,6 +538,10 @@ def test_certs(): cert_desc.should.have.key("certificateArn").which.should_not.be.none cert_desc.should.have.key("certificateId").which.should_not.be.none cert_desc.should.have.key("certificatePem").which.should_not.be.none + cert_desc.should.have.key("validity").which.should_not.be.none + validity = cert_desc["validity"] + validity.should.have.key("notBefore").which.should_not.be.none + validity.should.have.key("notAfter").which.should_not.be.none cert_desc.should.have.key("status").which.should.equal("ACTIVE") cert_pem = cert_desc["certificatePem"] @@ -1019,7 +1023,7 @@ def test_delete_thing_group(): group_name_1a = "my-group-name-1a" group_name_2a = "my-group-name-2a" tree_dict = { - group_name_1a: {group_name_2a: {},}, + group_name_1a: {group_name_2a: {}, }, } group_catalog = generate_thing_group_tree(client, tree_dict) diff --git a/update_version_from_git.py b/update_version_from_git.py index 7a51a5c2..e08ad75f 100644 --- a/update_version_from_git.py +++ b/update_version_from_git.py @@ -54,7 +54,7 @@ def migrate_version(target_file, new_version): regex = r"['\"](.*)['\"]" migrate_source_attribute( "__version__", - "\"{new_version}\"".format(new_version=new_version), + '"{new_version}"'.format(new_version=new_version), target_file, regex, ) @@ -84,7 +84,9 @@ def prerelease_version(): assert ( initpy_ver > ver ), "the moto/__init__.py version should be newer than the last tagged release." - return "{}.{}.{}.dev{}".format(initpy_ver.major, initpy_ver.minor, initpy_ver.micro, commits_since) + return "{}.{}.{}.dev{}".format( + initpy_ver.major, initpy_ver.minor, initpy_ver.micro, commits_since + ) def read(*parts): @@ -116,7 +118,9 @@ def increase_patch_version(old_version): :param old_version: 2.0.1 :return: 2.0.2.dev """ - return "{}.{}.{}.dev".format(old_version.major, old_version.minor, old_version.micro + 1) + return "{}.{}.{}.dev".format( + old_version.major, old_version.minor, old_version.micro + 1 + ) def release_version_correct(): @@ -154,5 +158,7 @@ if __name__ == "__main__": initpy = os.path.abspath("moto/__init__.py") migrate_version(initpy, new_version) else: - print("Invalid usage. Supply 0 or 1 arguments. " - "Argument can be either a version '1.2.3' or 'patch' if you want to increase the patch-version (1.2.3 -> 1.2.4.dev)") + print( + "Invalid usage. Supply 0 or 1 arguments. " + "Argument can be either a version '1.2.3' or 'patch' if you want to increase the patch-version (1.2.3 -> 1.2.4.dev)" + )