Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 805920f

Browse files
authored
fix SQS json requests sent to query route (localstack#9634)
1 parent 6adf6da commit 805920f

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

‎localstack/services/sqs/query_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from botocore.exceptions import ClientError
1010
from botocore.model import OperationModel
1111
from werkzeug.datastructures import Headers
12+
from werkzeug.exceptions import NotFound
1213

1314
from localstack.aws.api import CommonServiceException
1415
from localstack.aws.connect import connect_to
@@ -134,6 +135,12 @@ def __init__(self, boto_response):
134135

135136

136137
def handle_request(request: Request, region: str) -> Response:
138+
# some SDK (PHP) still send requests to the Queue URL even though the JSON spec does not allow it in the
139+
# documentation. If the request is `json`, raise `NotFound` so that we continue the handler chain and the provider
140+
# can handle the request
141+
if request.headers.get("Content-Type", "").lower() == "application/x-amz-json-1.0":
142+
raise NotFound
143+
137144
request_id = long_uid()
138145

139146
try:

‎tests/aws/services/sqs/test_sqs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4173,6 +4173,27 @@ def test_get_without_query_json_format_returns_returns_xml(
41734173
# TODO: write tests for making POST requests (not clear how signing would work without custom code)
41744174
# https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-making-api-requests.html#structure-post-request
41754175

4176+
@markers.aws.validated
4177+
def test_send_message_via_queue_url_with_json_protocol(
4178+
self,
4179+
sqs_create_queue,
4180+
aws_client_factory,
4181+
snapshot,
4182+
):
4183+
queue_url = sqs_create_queue()
4184+
# that is what the PHP SDK is doing in a way, sending the request against the queue URL directly when `json`
4185+
# protocol should target the root path
4186+
sqs_client = aws_client_factory(
4187+
endpoint_url=queue_url,
4188+
).sqs
4189+
4190+
response = sqs_client.receive_message(QueueUrl=queue_url, WaitTimeSeconds=1)
4191+
assert (
4192+
response["ResponseMetadata"]["HTTPHeaders"]["content-type"]
4193+
== "application/x-amz-json-1.0"
4194+
)
4195+
snapshot.match("receive-json-on-queue-url", response)
4196+
41764197

41774198
class TestSQSMultiAccounts:
41784199
@pytest.mark.parametrize("strategy", ["standard", "domain", "path"])

‎tests/aws/services/sqs/test_sqs.snapshot.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,5 +1323,17 @@
13231323
}
13241324
}
13251325
}
1326+
},
1327+
"tests/aws/services/sqs/test_sqs.py::TestSqsQueryApi::test_send_message_via_queue_url_with_json_protocol": {
1328+
"recorded-date": "14-11-2023, 21:27:28",
1329+
"recorded-content": {
1330+
"receive-json-on-queue-url": {
1331+
"Messages": [],
1332+
"ResponseMetadata": {
1333+
"HTTPHeaders": {},
1334+
"HTTPStatusCode": 200
1335+
}
1336+
}
1337+
}
13261338
}
13271339
}

0 commit comments

Comments
 (0)