|
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 | from moto.core import DEFAULT_ACCOUNT_ID as DEFAULT_MOTO_ACCOUNT_ID |
| 6 | +from rolo import Request |
6 | 7 |
|
7 | 8 | import localstack.aws.accounts |
8 | | -from localstack.aws.api import ServiceException, handler |
| 9 | +from localstack.aws.api import RequestContext, ServiceException, handler |
9 | 10 | from localstack.aws.forwarder import NotImplementedAvoidFallbackError |
| 11 | +from localstack.aws.spec import load_service |
10 | 12 | from localstack.constants import AWS_REGION_US_EAST_1 |
11 | 13 | from localstack.services import moto |
12 | 14 | from localstack.services.moto import MotoFallbackDispatcher |
@@ -229,6 +231,33 @@ def test_call_with_sqs_returns_service_response(): |
229 | 231 | assert create_queue_response["QueueUrl"].endswith(qname) |
230 | 232 |
|
231 | 233 |
|
| 234 | +@markers.aws.only_localstack |
| 235 | +def test_call_with_sns_with_full_uri(): |
| 236 | + # when requests are being forwarded by a Proxy, the HTTP request can contain the full URI and not only the path |
| 237 | + # see https://github.com/localstack/localstack/pull/8962 |
| 238 | + # by using `request.path`, we would use a full URI in the request, as Werkzeug has issue parsing those proxied |
| 239 | + # requests |
| 240 | + topic_name = f"queue-{short_uid()}" |
| 241 | + sns_request = Request( |
| 242 | + "POST", |
| 243 | + "/", |
| 244 | + raw_path="http://localhost:4566/", |
| 245 | + body=f"Action=CreateTopic&Name={topic_name}&Version=2010-03-31", |
| 246 | + headers={"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}, |
| 247 | + ) |
| 248 | + sns_service = load_service("sns") |
| 249 | + context = RequestContext() |
| 250 | + context.account = "test" |
| 251 | + context.region = "us-west-1" |
| 252 | + context.service = sns_service |
| 253 | + context.request = sns_request |
| 254 | + context.operation = sns_service.operation_model("CreateTopic") |
| 255 | + |
| 256 | + create_topic_response = moto.call_moto(context) |
| 257 | + |
| 258 | + assert create_topic_response["TopicArn"].endswith(topic_name) |
| 259 | + |
| 260 | + |
232 | 261 | class FakeSqsApi: |
233 | 262 | @handler("ListQueues", expand=False) |
234 | 263 | def list_queues(self, context, request): |
|
0 commit comments