Skip to content

fix(lambda-authorizer): allow proxy resources path in arn #1051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def parse_api_gateway_arn(arn: str) -> APIGatewayRouteArn:
api_id=api_gateway_arn_parts[0],
stage=api_gateway_arn_parts[1],
http_method=api_gateway_arn_parts[2],
resource=api_gateway_arn_parts[3] if len(api_gateway_arn_parts) == 4 else "",
resource="/".join(api_gateway_arn_parts[3:]) if len(api_gateway_arn_parts) >= 4 else "",
)


Expand Down
24 changes: 24 additions & 0 deletions tests/functional/data_classes/test_api_gateway_authorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from aws_lambda_powertools.utilities.data_classes.api_gateway_authorizer_event import (
DENY_ALL_RESPONSE,
APIGatewayAuthorizerResponse,
APIGatewayAuthorizerTokenEvent,
HttpVerb,
)

Expand Down Expand Up @@ -195,3 +196,26 @@ def test_authorizer_response_allow_route_with_underscore(builder: APIGatewayAuth
],
},
}


def test_parse_api_gateway_arn_with_resource():
mock_event = {
"type": "TOKEN",
"methodArn": "arn:aws:execute-api:us-east-2:1234567890:abcd1234/latest/GET/path/part/part/1",
"authorizationToken": "Bearer TOKEN",
}
event = APIGatewayAuthorizerTokenEvent(mock_event)
event_arn = event.parsed_arn
assert event_arn.resource == "path/part/part/1"

authorizer_policy = APIGatewayAuthorizerResponse(
principal_id="fooPrinciple",
region=event_arn.region,
aws_account_id=event_arn.aws_account_id,
api_id=event_arn.api_id,
stage=event_arn.stage,
)
authorizer_policy.allow_route(http_method=event_arn.http_method, resource=event_arn.resource)
response = authorizer_policy.asdict()

assert mock_event["methodArn"] == response["policyDocument"]["Statement"][0]["Resource"][0]