From e4726a44a10d60142e946a3918ca1486dfac454e Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Tue, 15 Aug 2023 13:40:32 +0100 Subject: [PATCH 1/2] parser: making scope field optional --- aws_lambda_powertools/utilities/parser/models/apigwv2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/parser/models/apigwv2.py b/aws_lambda_powertools/utilities/parser/models/apigwv2.py index 3be793dd951..8f0f8dbf50c 100644 --- a/aws_lambda_powertools/utilities/parser/models/apigwv2.py +++ b/aws_lambda_powertools/utilities/parser/models/apigwv2.py @@ -25,7 +25,7 @@ class RequestContextV2AuthorizerIam(BaseModel): class RequestContextV2AuthorizerJwt(BaseModel): claims: Dict[str, Any] - scopes: List[str] + scopes: Optional[List[str]] = None class RequestContextV2Authorizer(BaseModel): From ff6b53d8ab1765056047d77ee0407b54de14d15f Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Tue, 15 Aug 2023 17:27:47 +0100 Subject: [PATCH 2/2] parser: adding test --- tests/unit/parser/test_apigwv2.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/parser/test_apigwv2.py b/tests/unit/parser/test_apigwv2.py index 9ffc7f525bc..b52bad28b40 100644 --- a/tests/unit/parser/test_apigwv2.py +++ b/tests/unit/parser/test_apigwv2.py @@ -63,6 +63,13 @@ def test_apigw_v2_event_jwt_authorizer(): assert parsed_event.stageVariables == raw_event["stageVariables"] +def test_apigw_v2_event_empty_jwt_scopes(): + raw_event = load_event("apiGatewayProxyV2Event.json") + raw_event["requestContext"]["authorizer"]["jwt"]["scopes"] = None + + APIGatewayProxyEventV2Model(**raw_event) + + def test_api_gateway_proxy_v2_event_lambda_authorizer(): raw_event = load_event("apiGatewayProxyV2LambdaAuthorizerEvent.json") parsed_event: APIGatewayProxyEventV2Model = APIGatewayProxyEventV2Model(**raw_event)