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 @@ -514,6 +514,7 @@ def from_route_arn(
parsed_arn.stage,
context,
usage_identifier_key,
partition=parsed_arn.partition,
)

def _add_route(self, effect: str, http_method: str, resource: str, conditions: list[dict] | None = None):
Expand Down Expand Up @@ -667,6 +668,7 @@ def from_route_arn(
parsed_arn.stage,
context,
usage_identifier_key,
partition=parsed_arn.partition,
)

# Note: we need ignore[override] because we are removing the http_method field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,16 @@ def test_parse_api_gateway_arn_with_resource():
response = authorizer_policy.asdict()

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


@pytest.mark.parametrize("partition", ["aws", "aws-cn", "aws-us-gov"])
def test_authorizer_response_from_route_arn_keeps_partition(partition):
# GIVEN a method ARN from a non-commercial partition
arn = f"arn:{partition}:execute-api:cn-north-1:123456789012:api123/prod/GET/orders"

# WHEN the response is built with from_route_arn
builder = APIGatewayAuthorizerResponse.from_route_arn(arn, principal_id="foo")
builder.allow_route(http_method="GET", resource="/orders")

# THEN the policy resource is the ARN API Gateway sent, partition included
assert builder.asdict()["policyDocument"]["Statement"][0]["Resource"] == [arn]
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,16 @@ def test_authorizer_response_allow_route_with_underscore(builder: APIGatewayAuth
],
},
}


@pytest.mark.parametrize("partition", ["aws", "aws-cn", "aws-us-gov"])
def test_authorizer_response_from_route_arn_keeps_partition(partition):
# GIVEN a route ARN from a non-commercial partition
arn = f"arn:{partition}:execute-api:cn-north-1:123456789012:api123/prod/$connect"

# WHEN the response is built with from_route_arn
builder = APIGatewayAuthorizerResponseWebSocket.from_route_arn(arn, principal_id="foo")
builder.allow_route(resource="$connect")

# THEN the policy resource is the ARN API Gateway sent, partition included
assert builder.asdict()["policyDocument"]["Statement"][0]["Resource"] == [arn]