Skip to content

fix(data-classes): underscore support in api gateway authorizer resource name #969

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
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 @@ -356,7 +356,7 @@ class APIGatewayAuthorizerResponse:
- https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
"""

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

def __init__(
Expand Down
21 changes: 19 additions & 2 deletions tests/functional/data_classes/test_api_gateway_authorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def test_authorizer_response_no_statement(builder: APIGatewayAuthorizerResponse)

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


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

Expand Down Expand Up @@ -178,3 +178,20 @@ def test_deny_all():
"Effect": "Deny",
"Resource": ["*"],
}


def test_authorizer_response_allow_route_with_underscore(builder: APIGatewayAuthorizerResponse):
builder.allow_route(http_method="GET", resource="/has_underscore")
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/has_underscore"],
}
],
},
}