Skip to content

Commit

Permalink
Fix regex URLs so that a dot is actually interpreted as a dot (#4110)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Aug 28, 2021
1 parent 8f79edb commit 07bb843
Show file tree
Hide file tree
Showing 36 changed files with 81 additions and 42 deletions.
2 changes: 1 addition & 1 deletion moto/acm/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/athena/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/autoscaling/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/cloudformation/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/codecommit/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/codepipeline/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/config/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/datapipeline/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/datasync/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from .responses import DataSyncResponse

url_bases = ["https?://(.*?)(datasync)(.*?).amazonaws.com"]
url_bases = [r"https?://(.*\.)?(datasync)\.(.+).amazonaws.com"]

url_paths = {"{0}/$": DataSyncResponse.dispatch}
4 changes: 1 addition & 3 deletions moto/dms/urls.py
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion moto/dynamodb/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/dynamodb2/urls.py
Original file line number Diff line number Diff line change
@@ -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}
5 changes: 4 additions & 1 deletion moto/ecr/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/ecs/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/events/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from .responses import EventsHandler

url_bases = ["https?://events.(.+).amazonaws.com"]
url_bases = [r"https?://events\.(.+)\.amazonaws\.com"]

url_paths = {"{0}/": EventsHandler.dispatch}
2 changes: 1 addition & 1 deletion moto/forecast/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from .responses import ForecastResponse

url_bases = ["https?://forecast.(.+).amazonaws.com"]
url_bases = [r"https?://forecast\.(.+)\.amazonaws\.com"]

url_paths = {"{0}/$": ForecastResponse.dispatch}
2 changes: 1 addition & 1 deletion moto/glue/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from .responses import GlueResponse

url_bases = ["https?://glue(.*).amazonaws.com"]
url_bases = [r"https?://glue\.(.+)\.amazonaws\.com"]

url_paths = {"{0}/$": GlueResponse.dispatch}
2 changes: 1 addition & 1 deletion moto/iam/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/iot/urls.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 2 additions & 2 deletions moto/kinesis/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

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}
2 changes: 1 addition & 1 deletion moto/kms/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/logs/urls.py
Original file line number Diff line number Diff line change
@@ -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}
4 changes: 1 addition & 3 deletions moto/mediastore/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from .responses import MediaStoreResponse

url_bases = [
"https?://mediastore.(.+).amazonaws.com",
]
url_bases = [r"https?://mediastore\.(.+)\.amazonaws\.com"]

response = MediaStoreResponse()

Expand Down
2 changes: 1 addition & 1 deletion moto/organizations/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/rds2/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/redshift/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/secretsmanager/urls.py
Original file line number Diff line number Diff line change
@@ -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}
5 changes: 4 additions & 1 deletion moto/ses/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/sns/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/sqs/urls.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 4 additions & 1 deletion moto/ssm/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/sts/urls.py
Original file line number Diff line number Diff line change
@@ -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}
4 changes: 1 addition & 3 deletions moto/support/urls.py
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion moto/swf/urls.py
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion moto/transcribe/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from .responses import TranscribeResponse

url_bases = ["https?://transcribe.(.+).amazonaws.com"]
url_bases = [r"https?://transcribe\.(.+)\.amazonaws\.com"]

url_paths = {"{0}/$": TranscribeResponse.dispatch}
36 changes: 36 additions & 0 deletions tests/test_core/test_url_base_regex.py
Original file line number Diff line number Diff line change
@@ -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"},
)

0 comments on commit 07bb843

Please sign in to comment.