Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -437,8 +437,15 @@ class APIGatewayAuthorizerResponse:
- https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
"""

path_regex = r"^[/.a-zA-Z0-9-_\*]+$"
"""The regular expression used to validate resource paths for the policy"""
path_regex = r"^[/.a-zA-Z0-9-_\*{}+]+$"
"""The regular expression used to validate resource paths for the policy.

Supports standard path characters and API Gateway path parameters:
- Standard: `/path/to/resource`
- Wildcard: `/path/*` or `/path/*/resource`
- Path parameter: `/path/{param}`
- Greedy path parameter: `/{proxy+}` or `/path/{proxy+}`
"""

def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,60 @@ def test_parse_api_gateway_arn_with_resource():
response = authorizer_policy.asdict()

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


def test_authorizer_response_allow_route_with_proxy_plus(builder: APIGatewayAuthorizerResponse):
"""Test that {proxy+} greedy path parameter is supported.

See: https://github.com/aws-powertools/powertools-lambda-python/issues/7979
"""
builder.allow_route(http_method="*", resource="/{proxy+}")
assert builder.asdict() == {
"principalId": "foo",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Resource": ["arn:aws:execute-api:us-west-1:123456789:fantom/dev/*/{proxy+}"],
},
],
},
}


def test_authorizer_response_allow_route_with_path_parameter(builder: APIGatewayAuthorizerResponse):
"""Test that standard path parameters like {id} are supported."""
builder.allow_route(http_method="GET", resource="/users/{userId}")
assert builder.asdict() == {
"principalId": "foo",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Resource": ["arn:aws:execute-api:us-west-1:123456789:fantom/dev/GET/users/{userId}"],
},
],
},
}


def test_authorizer_response_allow_route_with_nested_proxy(builder: APIGatewayAuthorizerResponse):
"""Test that {proxy+} can be used with a path prefix."""
builder.allow_route(http_method="*", resource="/api/v1/{proxy+}")
assert builder.asdict() == {
"principalId": "foo",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Resource": ["arn:aws:execute-api:us-west-1:123456789:fantom/dev/*/api/v1/{proxy+}"],
},
],
},
}