From 56806fb310e4a26484ebe38c8e411469ce2d02ee Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Wed, 27 Apr 2022 22:51:51 +0000 Subject: [PATCH] SQS - Accept queue-names as QueueUrl-parameter (#5073) --- moto/sqs/exceptions.py | 10 ---------- moto/sqs/responses.py | 4 ++-- tests/test_sqs/test_sqs.py | 15 ++++----------- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/moto/sqs/exceptions.py b/moto/sqs/exceptions.py index c2dcbc2a0..230d9af80 100644 --- a/moto/sqs/exceptions.py +++ b/moto/sqs/exceptions.py @@ -128,13 +128,3 @@ class OverLimit(RESTError): super().__init__( "OverLimit", "{} Actions were found, maximum allowed is 7.".format(count) ) - - -class InvalidAddress(RESTError): - code = 400 - - def __init__(self, address): - super().__init__( - "InvalidAddress", - "The address {} is not valid for this endpoint.".format(address), - ) diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index ed5413fa1..c6dea2601 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -12,7 +12,6 @@ from urllib.parse import urlparse from .exceptions import ( EmptyBatchRequest, - InvalidAddress, InvalidAttributeName, ReceiptHandleIsInvalid, BatchEntryIdsNotDistinct, @@ -53,7 +52,8 @@ class SQSResponse(BaseResponse): if queue_url.startswith("http://") or queue_url.startswith("https://"): return queue_url.split("/")[-1] else: - raise InvalidAddress(queue_url) + # The parameter could be the name itself, which AWS also accepts + return queue_url except TypeError: # Fallback to reading from the URL for botocore return self.path.split("/")[-1] diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index d55f13c82..6169dd231 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -3018,7 +3018,7 @@ def test_fifo_send_message_when_same_group_id_is_in_dlq(): @mock_sqs -def test_receive_message_should_not_accept_invalid_urls(): +def test_receive_message_using_name__should_return_name_as_url(): sqs = boto3.resource("sqs", region_name="us-east-1") conn = boto3.client("sqs", region_name="us-east-1") name = str(uuid4())[0:6] @@ -3029,17 +3029,10 @@ def test_receive_message_should_not_accept_invalid_urls(): working_url.should.match(f"/{ACCOUNT_ID}/{name}") queue = sqs.Queue(name) - with pytest.raises(ClientError) as e: - queue.send_message(MessageBody="this is a test message") - err = e.value.response["Error"] - err["Code"].should.equal("InvalidAddress") - err["Message"].should.equal(f"The address {name} is not valid for this endpoint.") + queue.send_message(MessageBody="this is a test message") - with pytest.raises(ClientError) as e: - conn.receive_message(QueueUrl=name) - err = e.value.response["Error"] - err["Code"].should.equal("InvalidAddress") - err["Message"].should.equal(f"The address {name} is not valid for this endpoint.") + resp = queue.receive_messages() + resp[0].queue_url.should.equal(name) @mock_sqs