File tree 2 files changed +26
-1
lines changed
aws_lambda_powertools/utilities/data_classes
tests/functional/data_classes
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:
60
60
api_id = api_gateway_arn_parts [0 ],
61
61
stage = api_gateway_arn_parts [1 ],
62
62
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 "" ,
64
65
)
65
66
66
67
Original file line number Diff line number Diff line change 3
3
from aws_lambda_powertools .utilities .data_classes .api_gateway_authorizer_event import (
4
4
DENY_ALL_RESPONSE ,
5
5
APIGatewayAuthorizerResponse ,
6
+ APIGatewayAuthorizerTokenEvent ,
6
7
HttpVerb ,
7
8
)
8
9
@@ -195,3 +196,26 @@ def test_authorizer_response_allow_route_with_underscore(builder: APIGatewayAuth
195
196
],
196
197
},
197
198
}
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