Skip to content

Commit fe7d5d2

Browse files
fix(data-classes): normalize authorizer ALL verb (#8445)
1 parent 3bd47e2 commit fe7d5d2

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

aws_lambda_powertools/utilities/data_classes/api_gateway_authorizer_event.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,11 @@ def _add_route(self, effect: str, http_method: str, resource: str, conditions: l
520520
"""Adds a route to the internal lists of allowed or denied routes. Each object in
521521
the internal list contains a resource ARN and a condition statement. The condition
522522
statement can be null."""
523-
if http_method != "*" and http_method not in HttpVerb.__members__:
524-
allowed_values = [verb.value for verb in HttpVerb]
523+
allowed_values = [verb.value for verb in HttpVerb]
524+
if http_method in HttpVerb.__members__:
525+
http_method = HttpVerb[http_method].value
526+
527+
if http_method not in allowed_values:
525528
raise ValueError(f"Invalid HTTP verb: '{http_method}'. Use either '{allowed_values}'")
526529

527530
if not self._resource_pattern.match(resource):

tests/unit/data_classes/required_dependencies/test_api_gateway_authorizer.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ def test_authorizer_response_deny_route(builder: APIGatewayAuthorizerResponse):
130130
}
131131

132132

133+
def test_authorizer_response_deny_route_all_methods(builder: APIGatewayAuthorizerResponse):
134+
builder.allow_all_routes()
135+
builder.deny_route(http_method="ALL", resource="/admin/*")
136+
137+
assert builder.asdict()["policyDocument"]["Statement"] == [
138+
{
139+
"Action": "execute-api:Invoke",
140+
"Effect": "Allow",
141+
"Resource": ["arn:aws:execute-api:us-west-1:123456789:fantom/dev/*/*"],
142+
},
143+
{
144+
"Action": "execute-api:Invoke",
145+
"Effect": "Deny",
146+
"Resource": ["arn:aws:execute-api:us-west-1:123456789:fantom/dev/*/admin/*"],
147+
},
148+
]
149+
150+
133151
def test_authorizer_response_allow_route_with_conditions(builder: APIGatewayAuthorizerResponse):
134152
condition = {"StringEquals": {"method.request.header.Content-Type": "text/html"}}
135153
builder.allow_route(

0 commit comments

Comments
 (0)