Skip to content

Commit 6d3b39f

Browse files
authored
fix: add error message when JwtConfiguration is not a map (#3567)
1 parent 48554be commit 6d3b39f

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

samtranslator/model/apigatewayv2.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ def __init__( # type: ignore[no-untyped-def] # noqa: PLR0913
129129
self.api_logical_id = api_logical_id
130130
self.name = name
131131
self.authorization_scopes = authorization_scopes
132-
self.jwt_configuration: Optional[JwtConfiguration] = self._get_jwt_configuration(jwt_configuration)
132+
self.jwt_configuration: Optional[JwtConfiguration] = self._get_jwt_configuration(
133+
jwt_configuration, api_logical_id
134+
)
133135
self.id_source = id_source
134136
self.function_arn = function_arn
135137
self.function_invoke_role = function_invoke_role
@@ -344,7 +346,9 @@ def _get_identity_source(self, auth_identity: Dict[str, Any]) -> List[str]:
344346
return identity_source
345347

346348
@staticmethod
347-
def _get_jwt_configuration(props: Optional[Dict[str, Union[str, List[str]]]]) -> Optional[JwtConfiguration]:
349+
def _get_jwt_configuration(
350+
props: Optional[Dict[str, Union[str, List[str]]]], api_logical_id: str
351+
) -> Optional[JwtConfiguration]:
348352
"""Make sure that JWT configuration dict keys are lower case.
349353
350354
ApiGatewayV2Authorizer doesn't create `AWS::ApiGatewayV2::Authorizer` but generates
@@ -359,13 +363,14 @@ def _get_jwt_configuration(props: Optional[Dict[str, Union[str, List[str]]]]) ->
359363
360364
Parameters
361365
----------
362-
props
363-
jwt configuration dict with the keys either lower case or capitalized
366+
props: jwt configuration dict with the keys either lower case or capitalized
367+
api_logical_id: logical id of the Serverless Api resource with the jwt configuration
364368
365369
Returns
366370
-------
367371
jwt configuration dict with low case keys
368372
"""
369373
if not props:
370374
return None
375+
sam_expect(props, api_logical_id, "JwtConfiguration").to_be_a_map()
371376
return {k.lower(): v for k, v in props.items()}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Resources:
2+
MyApi:
3+
Type: AWS::Serverless::HttpApi
4+
Properties:
5+
Tags:
6+
Tag1: value1
7+
Tag2: value2
8+
Auth:
9+
Authorizers:
10+
MyLambdaAuth:
11+
FunctionArn:
12+
Fn::GetAtt:
13+
- MyAuthFn
14+
- Arn
15+
FunctionInvokeRole:
16+
Fn::GetAtt:
17+
- MyAuthFnRole
18+
- Arn
19+
Identity:
20+
Context:
21+
- contextVar
22+
Headers:
23+
- Authorization
24+
QueryStrings:
25+
- petId
26+
StageVariables:
27+
- stageVar
28+
ReauthorizeEvery: 23
29+
EnableSimpleResponses: true
30+
AuthorizerPayloadFormatVersion: 2.0
31+
MyOAuth2Auth:
32+
AuthorizationScopes:
33+
- scope4
34+
JwtConfiguration:
35+
- issuer: https://openid-connect.onelogin.com/oidc
36+
IdentitySource: $request.querystring.param
37+
DefaultAuthorizer: MyOAuth2Auth
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Resource with id [MyApi] is invalid. ",
6+
"Property 'JwtConfiguration' should be a map."
7+
],
8+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Property 'JwtConfiguration' should be a map."
9+
}

0 commit comments

Comments
 (0)