File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
aws_lambda_powertools/utilities/data_classes
tests/functional/data_classes Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,8 @@ def parse_api_gateway_arn(arn: str) -> APIGatewayRouteArn:
6060 api_id = api_gateway_arn_parts [0 ],
6161 stage = api_gateway_arn_parts [1 ],
6262 http_method = api_gateway_arn_parts [2 ],
63- resource = api_gateway_arn_parts [3 ] if len (api_gateway_arn_parts ) == 4 else "" ,
63+ # conditional allow us to handle /path/{proxy+} resources, as their length changes.
64+ resource = "/" .join (api_gateway_arn_parts [3 :]) if len (api_gateway_arn_parts ) >= 4 else "" ,
6465 )
6566
6667
Original file line number Diff line number Diff line change 33from aws_lambda_powertools .utilities .data_classes .api_gateway_authorizer_event import (
44 DENY_ALL_RESPONSE ,
55 APIGatewayAuthorizerResponse ,
6+ APIGatewayAuthorizerTokenEvent ,
67 HttpVerb ,
78)
89
@@ -195,3 +196,26 @@ def test_authorizer_response_allow_route_with_underscore(builder: APIGatewayAuth
195196 ],
196197 },
197198 }
199+
200+
201+ def test_parse_api_gateway_arn_with_resource ():
202+ mock_event = {
203+ "type" : "TOKEN" ,
204+ "methodArn" : "arn:aws:execute-api:us-east-2:1234567890:abcd1234/latest/GET/path/part/part/1" ,
205+ "authorizationToken" : "Bearer TOKEN" ,
206+ }
207+ event = APIGatewayAuthorizerTokenEvent (mock_event )
208+ event_arn = event .parsed_arn
209+ assert event_arn .resource == "path/part/part/1"
210+
211+ authorizer_policy = APIGatewayAuthorizerResponse (
212+ principal_id = "fooPrinciple" ,
213+ region = event_arn .region ,
214+ aws_account_id = event_arn .aws_account_id ,
215+ api_id = event_arn .api_id ,
216+ stage = event_arn .stage ,
217+ )
218+ authorizer_policy .allow_route (http_method = event_arn .http_method , resource = event_arn .resource )
219+ response = authorizer_policy .asdict ()
220+
221+ assert mock_event ["methodArn" ] == response ["policyDocument" ]["Statement" ][0 ]["Resource" ][0 ]
You can’t perform that action at this time.
0 commit comments