@@ -159,13 +159,34 @@ def test_parse_user_request_path(
159
159
assert context .invocation_request ["path" ] == "/foo%2Fbar/ed"
160
160
assert context .invocation_request ["raw_path" ] == "//foo%2Fbar/ed"
161
161
162
- @pytest .mark .parametrize ("addressing" , ["host" , "user_request" ])
162
+ def test_parse_localstack_only_path (
163
+ self , dummy_deployment , parse_handler_chain , get_invocation_context
164
+ ):
165
+ # simulate a path request
166
+ request = Request (
167
+ "GET" ,
168
+ path = f"/_aws/execute-api/{ TEST_API_ID } /{ TEST_API_STAGE } /foo/bar/ed" ,
169
+ raw_path = f"/_aws/execute-api/{ TEST_API_ID } /{ TEST_API_STAGE } //foo%2Fbar/ed" ,
170
+ )
171
+
172
+ context = get_invocation_context (request )
173
+ context .deployment = dummy_deployment
174
+
175
+ parse_handler_chain .handle (context , Response ())
176
+
177
+ # assert that the user request prefix has been stripped off
178
+ assert context .invocation_request ["path" ] == "/foo%2Fbar/ed"
179
+ assert context .invocation_request ["raw_path" ] == "//foo%2Fbar/ed"
180
+
181
+ @pytest .mark .parametrize ("addressing" , ["host" , "user_request" , "path_style" ])
163
182
def test_parse_path_same_as_stage (
164
183
self , dummy_deployment , parse_handler_chain , get_invocation_context , addressing
165
184
):
166
185
path = TEST_API_STAGE
167
186
if addressing == "host" :
168
187
full_path = f"/{ TEST_API_STAGE } /{ path } "
188
+ elif addressing == "path_style" :
189
+ full_path = f"/_aws/execute-api/{ TEST_API_ID } /{ TEST_API_STAGE } /{ path } "
169
190
else :
170
191
full_path = f"/restapis/{ TEST_API_ID } /{ TEST_API_STAGE } /_user_request_/{ path } "
171
192
@@ -181,6 +202,27 @@ def test_parse_path_same_as_stage(
181
202
assert context .invocation_request ["path" ] == f"/{ TEST_API_STAGE } "
182
203
assert context .invocation_request ["raw_path" ] == f"/{ TEST_API_STAGE } "
183
204
205
+ @pytest .mark .parametrize ("addressing" , ["user_request" , "path_style" ])
206
+ def test_cased_api_id_in_path (
207
+ self , dummy_deployment , parse_handler_chain , get_invocation_context , addressing
208
+ ):
209
+ if addressing == "path_style" :
210
+ full_path = f"/_aws/execute-api/TestApi/{ TEST_API_STAGE } /test"
211
+ else :
212
+ full_path = f"/restapis/{ TEST_API_ID } /TestApi/_user_request_/test"
213
+
214
+ # simulate a path request
215
+ request = Request ("GET" , path = full_path )
216
+
217
+ context = get_invocation_context (request )
218
+ context .deployment = dummy_deployment
219
+
220
+ parse_handler_chain .handle (context , Response ())
221
+
222
+ # assert that the user request prefix has been stripped off
223
+ assert context .invocation_request ["path" ] == "/test"
224
+ assert context .invocation_request ["raw_path" ] == "/test"
225
+
184
226
def test_trace_id_logic (self ):
185
227
headers = Headers ({"x-amzn-trace-id" : "Root=trace;Parent=parent" })
186
228
trace = InvocationRequestParser .populate_trace_id (headers )
@@ -336,10 +378,13 @@ def deployment_with_any_routes(self, dummy_deployment):
336
378
def get_path_from_addressing (path : str , addressing : str ) -> str :
337
379
if addressing == "host" :
338
380
return f"/{ TEST_API_STAGE } { path } "
339
- else :
381
+ elif addressing == "user_request" :
340
382
return f"/restapis/{ TEST_API_ID } /{ TEST_API_STAGE } /_user_request_/{ path } "
383
+ else :
384
+ # this new style allows following the regular order in an easier way, stage is always before path
385
+ return f"/_aws/execute-api/{ TEST_API_ID } /{ TEST_API_STAGE } { path } "
341
386
342
- @pytest .mark .parametrize ("addressing" , ["host" , "user_request" ])
387
+ @pytest .mark .parametrize ("addressing" , ["host" , "user_request" , "path_style" ])
343
388
def test_route_request_no_param (
344
389
self , deployment_with_routes , parse_handler_chain , get_invocation_context , addressing
345
390
):
@@ -364,7 +409,7 @@ def test_route_request_no_param(
364
409
assert context .invocation_request ["path_parameters" ] == {}
365
410
assert context .stage_variables == {"foo" : "bar" }
366
411
367
- @pytest .mark .parametrize ("addressing" , ["host" , "user_request" ])
412
+ @pytest .mark .parametrize ("addressing" , ["host" , "user_request" , "path_style" ])
368
413
def test_route_request_with_path_parameter (
369
414
self , deployment_with_routes , parse_handler_chain , get_invocation_context , addressing
370
415
):
@@ -389,7 +434,7 @@ def test_route_request_with_path_parameter(
389
434
assert context .context_variables ["resourcePath" ] == "/foo/{param}"
390
435
assert context .context_variables ["resourceId" ] == context .resource ["id" ]
391
436
392
- @pytest .mark .parametrize ("addressing" , ["host" , "user_request" ])
437
+ @pytest .mark .parametrize ("addressing" , ["host" , "user_request" , "path_style" ])
393
438
def test_route_request_with_greedy_parameter (
394
439
self , deployment_with_routes , parse_handler_chain , get_invocation_context , addressing
395
440
):
@@ -448,7 +493,7 @@ def test_route_request_with_greedy_parameter(
448
493
"proxy" : "test2/is/a/proxy/req2%Fuest"
449
494
}
450
495
451
- @pytest .mark .parametrize ("addressing" , ["host" , "user_request" ])
496
+ @pytest .mark .parametrize ("addressing" , ["host" , "user_request" , "path_style" ])
452
497
def test_route_request_no_match_on_path (
453
498
self , deployment_with_routes , parse_handler_chain , get_invocation_context , addressing
454
499
):
@@ -466,7 +511,7 @@ def test_route_request_no_match_on_path(
466
511
with pytest .raises (MissingAuthTokenError ):
467
512
handler (parse_handler_chain , context , Response ())
468
513
469
- @pytest .mark .parametrize ("addressing" , ["host" , "user_request" ])
514
+ @pytest .mark .parametrize ("addressing" , ["host" , "user_request" , "path_style" ])
470
515
def test_route_request_no_match_on_method (
471
516
self , deployment_with_routes , parse_handler_chain , get_invocation_context , addressing
472
517
):
@@ -484,7 +529,7 @@ def test_route_request_no_match_on_method(
484
529
with pytest .raises (MissingAuthTokenError ):
485
530
handler (parse_handler_chain , context , Response ())
486
531
487
- @pytest .mark .parametrize ("addressing" , ["host" , "user_request" ])
532
+ @pytest .mark .parametrize ("addressing" , ["host" , "user_request" , "path_style" ])
488
533
def test_route_request_with_double_slash_and_trailing_and_encoded (
489
534
self , deployment_with_routes , parse_handler_chain , get_invocation_context , addressing
490
535
):
@@ -504,7 +549,7 @@ def test_route_request_with_double_slash_and_trailing_and_encoded(
504
549
assert context .resource ["path" ] == "/foo/{param}"
505
550
assert context .invocation_request ["path_parameters" ] == {"param" : "foo%2Fbar" }
506
551
507
- @pytest .mark .parametrize ("addressing" , ["host" , "user_request" ])
552
+ @pytest .mark .parametrize ("addressing" , ["host" , "user_request" , "path_style" ])
508
553
def test_route_request_any_is_last (
509
554
self , deployment_with_any_routes , parse_handler_chain , get_invocation_context , addressing
510
555
):
0 commit comments