From 07bb84321475807c1f906a62dce1024b1804b504 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Sat, 28 Aug 2021 13:42:45 +0100 Subject: [PATCH] Fix regex URLs so that a dot is actually interpreted as a dot (#4110) --- moto/acm/urls.py | 2 +- moto/athena/urls.py | 2 +- moto/autoscaling/urls.py | 2 +- moto/cloudformation/urls.py | 2 +- moto/codecommit/urls.py | 2 +- moto/codepipeline/urls.py | 2 +- moto/config/urls.py | 2 +- moto/datapipeline/urls.py | 2 +- moto/datasync/urls.py | 2 +- moto/dms/urls.py | 4 +-- moto/dynamodb/urls.py | 2 +- moto/dynamodb2/urls.py | 2 +- moto/ecr/urls.py | 5 +++- moto/ecs/urls.py | 2 +- moto/events/urls.py | 2 +- moto/forecast/urls.py | 2 +- moto/glue/urls.py | 2 +- moto/iam/urls.py | 2 +- moto/iot/urls.py | 2 +- moto/kinesis/urls.py | 4 +-- moto/kms/urls.py | 2 +- moto/logs/urls.py | 2 +- moto/mediastore/urls.py | 4 +-- moto/organizations/urls.py | 2 +- moto/rds2/urls.py | 2 +- moto/redshift/urls.py | 2 +- moto/secretsmanager/urls.py | 2 +- moto/ses/urls.py | 5 +++- moto/sns/urls.py | 2 +- moto/sqs/urls.py | 2 +- moto/ssm/urls.py | 5 +++- moto/sts/urls.py | 2 +- moto/support/urls.py | 4 +-- moto/swf/urls.py | 2 +- moto/transcribe/urls.py | 2 +- tests/test_core/test_url_base_regex.py | 36 ++++++++++++++++++++++++++ 36 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 tests/test_core/test_url_base_regex.py diff --git a/moto/acm/urls.py b/moto/acm/urls.py index 8a8d3e2ef..befced81d 100644 --- a/moto/acm/urls.py +++ b/moto/acm/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import AWSCertificateManagerResponse -url_bases = ["https?://acm.(.+).amazonaws.com"] +url_bases = ["https?://acm\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": AWSCertificateManagerResponse.dispatch} diff --git a/moto/athena/urls.py b/moto/athena/urls.py index 4f8fdf7ee..c36c379cf 100644 --- a/moto/athena/urls.py +++ b/moto/athena/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import AthenaResponse -url_bases = ["https?://athena.(.+).amazonaws.com"] +url_bases = ["https?://athena\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": AthenaResponse.dispatch} diff --git a/moto/autoscaling/urls.py b/moto/autoscaling/urls.py index 5fb33c25d..1a8750ecf 100644 --- a/moto/autoscaling/urls.py +++ b/moto/autoscaling/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import AutoScalingResponse -url_bases = ["https?://autoscaling.(.+).amazonaws.com"] +url_bases = [r"https?://autoscaling\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": AutoScalingResponse.dispatch} diff --git a/moto/cloudformation/urls.py b/moto/cloudformation/urls.py index 84251e82b..63ed9ddb1 100644 --- a/moto/cloudformation/urls.py +++ b/moto/cloudformation/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import CloudFormationResponse -url_bases = ["https?://cloudformation.(.+).amazonaws.com"] +url_bases = [r"https?://cloudformation\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": CloudFormationResponse.dispatch} diff --git a/moto/codecommit/urls.py b/moto/codecommit/urls.py index 1e3cdb1b4..1d3acaa7a 100644 --- a/moto/codecommit/urls.py +++ b/moto/codecommit/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import CodeCommitResponse -url_bases = ["https?://codecommit.(.+).amazonaws.com"] +url_bases = [r"https?://codecommit\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": CodeCommitResponse.dispatch} diff --git a/moto/codepipeline/urls.py b/moto/codepipeline/urls.py index 7111020a5..5c57d9885 100644 --- a/moto/codepipeline/urls.py +++ b/moto/codepipeline/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import CodePipelineResponse -url_bases = ["https?://codepipeline.(.+).amazonaws.com"] +url_bases = [r"https?://codepipeline\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": CodePipelineResponse.dispatch} diff --git a/moto/config/urls.py b/moto/config/urls.py index 62cf34a52..a7c4b01e2 100644 --- a/moto/config/urls.py +++ b/moto/config/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import ConfigResponse -url_bases = ["https?://config.(.+).amazonaws.com"] +url_bases = [r"https?://config\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": ConfigResponse.dispatch} diff --git a/moto/datapipeline/urls.py b/moto/datapipeline/urls.py index 078b44b19..ae6d3c468 100644 --- a/moto/datapipeline/urls.py +++ b/moto/datapipeline/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import DataPipelineResponse -url_bases = ["https?://datapipeline.(.+).amazonaws.com"] +url_bases = [r"https?://datapipeline\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": DataPipelineResponse.dispatch} diff --git a/moto/datasync/urls.py b/moto/datasync/urls.py index 69ba3cccb..4868eec58 100644 --- a/moto/datasync/urls.py +++ b/moto/datasync/urls.py @@ -2,6 +2,6 @@ from __future__ import unicode_literals from .responses import DataSyncResponse -url_bases = ["https?://(.*?)(datasync)(.*?).amazonaws.com"] +url_bases = [r"https?://(.*\.)?(datasync)\.(.+).amazonaws.com"] url_paths = {"{0}/$": DataSyncResponse.dispatch} diff --git a/moto/dms/urls.py b/moto/dms/urls.py index 74041ad97..ef1ce0fc9 100644 --- a/moto/dms/urls.py +++ b/moto/dms/urls.py @@ -1,9 +1,7 @@ from __future__ import unicode_literals from .responses import DatabaseMigrationServiceResponse -url_bases = [ - "https?://dms.(.+).amazonaws.com", -] +url_bases = [r"https?://dms\.(.+)\.amazonaws\.com"] url_paths = { diff --git a/moto/dynamodb/urls.py b/moto/dynamodb/urls.py index 26f0701a2..af5a74830 100644 --- a/moto/dynamodb/urls.py +++ b/moto/dynamodb/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import DynamoHandler -url_bases = ["https?://dynamodb.(.+).amazonaws.com"] +url_bases = [r"https?://dynamodb\.(.+)\.amazonaws\.com"] url_paths = {"{0}/": DynamoHandler.dispatch} diff --git a/moto/dynamodb2/urls.py b/moto/dynamodb2/urls.py index 26f0701a2..af5a74830 100644 --- a/moto/dynamodb2/urls.py +++ b/moto/dynamodb2/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import DynamoHandler -url_bases = ["https?://dynamodb.(.+).amazonaws.com"] +url_bases = [r"https?://dynamodb\.(.+)\.amazonaws\.com"] url_paths = {"{0}/": DynamoHandler.dispatch} diff --git a/moto/ecr/urls.py b/moto/ecr/urls.py index a25874e43..9042338a6 100644 --- a/moto/ecr/urls.py +++ b/moto/ecr/urls.py @@ -1,6 +1,9 @@ from __future__ import unicode_literals from .responses import ECRResponse -url_bases = ["https?://ecr.(.+).amazonaws.com", "https?://api.ecr.(.+).amazonaws.com"] +url_bases = [ + r"https?://ecr\.(.+)\.amazonaws\.com", + r"https?://api\.ecr\.(.+)\.amazonaws\.com", +] url_paths = {"{0}/$": ECRResponse.dispatch} diff --git a/moto/ecs/urls.py b/moto/ecs/urls.py index a5adc5923..a8ed67dc8 100644 --- a/moto/ecs/urls.py +++ b/moto/ecs/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import EC2ContainerServiceResponse -url_bases = ["https?://ecs.(.+).amazonaws.com"] +url_bases = [r"https?://ecs\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": EC2ContainerServiceResponse.dispatch} diff --git a/moto/events/urls.py b/moto/events/urls.py index 39e6a3462..385fe28f1 100644 --- a/moto/events/urls.py +++ b/moto/events/urls.py @@ -2,6 +2,6 @@ from __future__ import unicode_literals from .responses import EventsHandler -url_bases = ["https?://events.(.+).amazonaws.com"] +url_bases = [r"https?://events\.(.+)\.amazonaws\.com"] url_paths = {"{0}/": EventsHandler.dispatch} diff --git a/moto/forecast/urls.py b/moto/forecast/urls.py index 221659e6f..f2535fc80 100644 --- a/moto/forecast/urls.py +++ b/moto/forecast/urls.py @@ -2,6 +2,6 @@ from __future__ import unicode_literals from .responses import ForecastResponse -url_bases = ["https?://forecast.(.+).amazonaws.com"] +url_bases = [r"https?://forecast\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": ForecastResponse.dispatch} diff --git a/moto/glue/urls.py b/moto/glue/urls.py index 2c7854732..dbb0c2102 100644 --- a/moto/glue/urls.py +++ b/moto/glue/urls.py @@ -2,6 +2,6 @@ from __future__ import unicode_literals from .responses import GlueResponse -url_bases = ["https?://glue(.*).amazonaws.com"] +url_bases = [r"https?://glue\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": GlueResponse.dispatch} diff --git a/moto/iam/urls.py b/moto/iam/urls.py index c4ce1d81f..504f3bdb0 100644 --- a/moto/iam/urls.py +++ b/moto/iam/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import IamResponse -url_bases = ["https?://iam(.*).amazonaws.com"] +url_bases = [r"https?://iam\.(.*\.)?amazonaws\.com"] url_paths = {"{0}/$": IamResponse.dispatch} diff --git a/moto/iot/urls.py b/moto/iot/urls.py index a4d6436d0..086720bbc 100644 --- a/moto/iot/urls.py +++ b/moto/iot/urls.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from .responses import IoTResponse -url_bases = ["https?://iot.(.+).amazonaws.com"] +url_bases = [r"https?://iot\.(.+)\.amazonaws\.com"] response = IoTResponse() diff --git a/moto/kinesis/urls.py b/moto/kinesis/urls.py index a33225d60..33d6bf215 100644 --- a/moto/kinesis/urls.py +++ b/moto/kinesis/urls.py @@ -3,8 +3,8 @@ from .responses import KinesisResponse url_bases = [ # Need to avoid conflicting with kinesisvideo - r"https?://kinesis\.(.+).amazonaws.com", - "https?://firehose.(.+).amazonaws.com", + r"https?://kinesis\.(.+)\.amazonaws\.com", + r"https?://firehose\.(.+)\.amazonaws\.com", ] url_paths = {"{0}/$": KinesisResponse.dispatch} diff --git a/moto/kms/urls.py b/moto/kms/urls.py index 97e1a3720..38c164868 100644 --- a/moto/kms/urls.py +++ b/moto/kms/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import KmsResponse -url_bases = ["https?://kms.(.+).amazonaws.com"] +url_bases = [r"https?://kms\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": KmsResponse.dispatch} diff --git a/moto/logs/urls.py b/moto/logs/urls.py index e4e1f5a88..74cfcaef0 100644 --- a/moto/logs/urls.py +++ b/moto/logs/urls.py @@ -1,5 +1,5 @@ from .responses import LogsResponse -url_bases = ["https?://logs.(.+).amazonaws.com"] +url_bases = [r"https?://logs\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": LogsResponse.dispatch} diff --git a/moto/mediastore/urls.py b/moto/mediastore/urls.py index 15520ab70..9034be1e3 100644 --- a/moto/mediastore/urls.py +++ b/moto/mediastore/urls.py @@ -2,9 +2,7 @@ from __future__ import unicode_literals from .responses import MediaStoreResponse -url_bases = [ - "https?://mediastore.(.+).amazonaws.com", -] +url_bases = [r"https?://mediastore\.(.+)\.amazonaws\.com"] response = MediaStoreResponse() diff --git a/moto/organizations/urls.py b/moto/organizations/urls.py index d0909bbef..940afc78d 100644 --- a/moto/organizations/urls.py +++ b/moto/organizations/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import OrganizationsResponse -url_bases = ["https?://organizations.(.+).amazonaws.com"] +url_bases = [r"https?://organizations\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": OrganizationsResponse.dispatch} diff --git a/moto/rds2/urls.py b/moto/rds2/urls.py index d937554e0..2175c659e 100644 --- a/moto/rds2/urls.py +++ b/moto/rds2/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import RDS2Response -url_bases = ["https?://rds.(.+).amazonaws.com", "https?://rds.amazonaws.com"] +url_bases = [r"https?://rds\.(.+)\.amazonaws\.com", r"https?://rds\.amazonaws\.com"] url_paths = {"{0}/$": RDS2Response.dispatch} diff --git a/moto/redshift/urls.py b/moto/redshift/urls.py index 8494669ee..fbc31be33 100644 --- a/moto/redshift/urls.py +++ b/moto/redshift/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import RedshiftResponse -url_bases = ["https?://redshift.(.+).amazonaws.com"] +url_bases = [r"https?://redshift\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": RedshiftResponse.dispatch} diff --git a/moto/secretsmanager/urls.py b/moto/secretsmanager/urls.py index 57cbac0e4..d06b28e4a 100644 --- a/moto/secretsmanager/urls.py +++ b/moto/secretsmanager/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import SecretsManagerResponse -url_bases = ["https?://secretsmanager.(.+).amazonaws.com"] +url_bases = [r"https?://secretsmanager\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": SecretsManagerResponse.dispatch} diff --git a/moto/ses/urls.py b/moto/ses/urls.py index 5c26d2152..61f3f75a5 100644 --- a/moto/ses/urls.py +++ b/moto/ses/urls.py @@ -1,6 +1,9 @@ from __future__ import unicode_literals from .responses import EmailResponse -url_bases = ["https?://email.(.+).amazonaws.com", "https?://ses.(.+).amazonaws.com"] +url_bases = [ + r"https?://email\.(.+)\.amazonaws\.com", + r"https?://ses\.(.+)\.amazonaws\.com", +] url_paths = {"{0}/$": EmailResponse.dispatch} diff --git a/moto/sns/urls.py b/moto/sns/urls.py index 8c38bb12c..ff4a09ea8 100644 --- a/moto/sns/urls.py +++ b/moto/sns/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import SNSResponse -url_bases = ["https?://sns.(.+).amazonaws.com"] +url_bases = [r"https?://sns\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": SNSResponse.dispatch} diff --git a/moto/sqs/urls.py b/moto/sqs/urls.py index 54fd44650..b1202fe3f 100644 --- a/moto/sqs/urls.py +++ b/moto/sqs/urls.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from .responses import SQSResponse -url_bases = ["https?://(.*?)(queue|sqs)(.*?).amazonaws.com"] +url_bases = [r"https?://(.*\.)?(queue|sqs)\.(.*\.)?amazonaws\.com"] dispatch = SQSResponse().dispatch diff --git a/moto/ssm/urls.py b/moto/ssm/urls.py index bd6706dfa..e470f457f 100644 --- a/moto/ssm/urls.py +++ b/moto/ssm/urls.py @@ -1,6 +1,9 @@ from __future__ import unicode_literals from .responses import SimpleSystemManagerResponse -url_bases = ["https?://ssm.(.+).amazonaws.com", "https?://ssm.(.+).amazonaws.com.cn"] +url_bases = [ + r"https?://ssm\.(.+)\.amazonaws\.com", + r"https?://ssm\.(.+)\.amazonaws\.com\.cn", +] url_paths = {"{0}/$": SimpleSystemManagerResponse.dispatch} diff --git a/moto/sts/urls.py b/moto/sts/urls.py index 031fd9b04..e6247a8f3 100644 --- a/moto/sts/urls.py +++ b/moto/sts/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import TokenResponse -url_bases = ["https?://sts(.*).amazonaws.com(|.cn)"] +url_bases = [r"https?://sts\.(.*\.)?amazonaws\.com(|.cn)"] url_paths = {"{0}/$": TokenResponse.dispatch} diff --git a/moto/support/urls.py b/moto/support/urls.py index 52633eefd..66a832b58 100644 --- a/moto/support/urls.py +++ b/moto/support/urls.py @@ -1,9 +1,7 @@ from __future__ import unicode_literals from .responses import SupportResponse -url_bases = [ - "https?://support.(.+).amazonaws.com", -] +url_bases = [r"https?://support\.(.+)\.amazonaws\.com"] url_paths = { diff --git a/moto/swf/urls.py b/moto/swf/urls.py index cafc39ad3..951faebe4 100644 --- a/moto/swf/urls.py +++ b/moto/swf/urls.py @@ -1,5 +1,5 @@ from .responses import SWFResponse -url_bases = ["https?://swf.(.+).amazonaws.com"] +url_bases = [r"https?://swf\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": SWFResponse.dispatch} diff --git a/moto/transcribe/urls.py b/moto/transcribe/urls.py index 175f6fea9..838f3f8a1 100644 --- a/moto/transcribe/urls.py +++ b/moto/transcribe/urls.py @@ -2,6 +2,6 @@ from __future__ import unicode_literals from .responses import TranscribeResponse -url_bases = ["https?://transcribe.(.+).amazonaws.com"] +url_bases = [r"https?://transcribe\.(.+)\.amazonaws\.com"] url_paths = {"{0}/$": TranscribeResponse.dispatch} diff --git a/tests/test_core/test_url_base_regex.py b/tests/test_core/test_url_base_regex.py new file mode 100644 index 000000000..a9a1bf278 --- /dev/null +++ b/tests/test_core/test_url_base_regex.py @@ -0,0 +1,36 @@ +import boto3 +import moto +import pytest +from moto import mock_s3 + + +service_names = [ + (d[5:], "") + for d in dir(moto) + if d.startswith("mock_") + and not d.endswith("_deprecated") + and not d == "mock_xray_client" + and not d == "mock_all" +] + + +class TestMockBucketStartingWithServiceName: + """ + https://github.com/spulec/moto/issues/4099 + """ + + @pytest.mark.parametrize( + "service_name,decorator", service_names, + ) + def test_bucketname_starting_with_service_name(self, service_name, decorator): + + decorator = getattr(moto, "mock_{}".format(service_name)) + with decorator(): + with mock_s3(): + s3_client = boto3.client("s3", "eu-west-1") + bucket_name = "{}-bucket".format(service_name) + s3_client.create_bucket( + ACL="private", + Bucket=bucket_name, + CreateBucketConfiguration={"LocationConstraint": "eu-west-1"}, + )