Skip to content

Commit 2ad7dc4

Browse files
author
Michael Brewer
authored
fix(data-classes): underscore support in api gateway authorizer resource name (#969)
1 parent 5b2ad90 commit 2ad7dc4

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Diff for: aws_lambda_powertools/utilities/data_classes/api_gateway_authorizer_event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class APIGatewayAuthorizerResponse:
356356
- https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
357357
"""
358358

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

362362
def __init__(

Diff for: tests/functional/data_classes/test_api_gateway_authorizer.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def test_authorizer_response_no_statement(builder: APIGatewayAuthorizerResponse)
2424

2525
def test_authorizer_response_invalid_verb(builder: APIGatewayAuthorizerResponse):
2626
with pytest.raises(ValueError, match="Invalid HTTP verb: 'INVALID'"):
27-
# GIVEN a invalid http_method
27+
# GIVEN an invalid http_method
2828
# WHEN calling deny_method
2929
builder.deny_route(http_method="INVALID", resource="foo")
3030

3131

3232
def test_authorizer_response_invalid_resource(builder: APIGatewayAuthorizerResponse):
3333
with pytest.raises(ValueError, match="Invalid resource path: \$."): # noqa: W605
34-
# GIVEN a invalid resource path "$"
34+
# GIVEN an invalid resource path "$"
3535
# WHEN calling deny_method
3636
builder.deny_route(http_method=HttpVerb.GET.value, resource="$")
3737

@@ -178,3 +178,20 @@ def test_deny_all():
178178
"Effect": "Deny",
179179
"Resource": ["*"],
180180
}
181+
182+
183+
def test_authorizer_response_allow_route_with_underscore(builder: APIGatewayAuthorizerResponse):
184+
builder.allow_route(http_method="GET", resource="/has_underscore")
185+
assert builder.asdict() == {
186+
"principalId": "foo",
187+
"policyDocument": {
188+
"Version": "2012-10-17",
189+
"Statement": [
190+
{
191+
"Action": "execute-api:Invoke",
192+
"Effect": "Allow",
193+
"Resource": ["arn:aws:execute-api:us-west-1:123456789:fantom/dev/GET/has_underscore"],
194+
}
195+
],
196+
},
197+
}

0 commit comments

Comments
 (0)