Skip to content
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
6 changes: 6 additions & 0 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,12 @@ def _set_default_authorizer(
if not default_authorizer:
return

if not isinstance(default_authorizer, string_types):
raise InvalidResourceException(
self.logical_id,
"DefaultAuthorizer is not a string.",
)

if not authorizers.get(default_authorizer) and default_authorizer != "AWS_IAM":
raise InvalidResourceException(
self.logical_id,
Expand Down
5 changes: 5 additions & 0 deletions samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,11 @@ class Cognito(PushEventSource):
def resources_to_link(self, resources):
if isinstance(self.UserPool, dict) and "Ref" in self.UserPool:
userpool_id = self.UserPool["Ref"]
if not isinstance(userpool_id, string_types):
raise InvalidEventException(
self.logical_id,
"Ref in Userpool is not a string.",
)
if userpool_id in resources:
return {"userpool": resources[userpool_id], "userpool_id": userpool_id}
raise InvalidEventException(
Expand Down
18 changes: 18 additions & 0 deletions tests/translator/input/error_cognito_userpool_not_string.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Resources:
UserPool:
Type: AWS::Cognito::UserPool

ImplicitApiFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.gethtml
Runtime: nodejs12.x
Events:
OneTrigger:
Type: Cognito
Properties:
UserPool:
Ref:
- NotAString
Trigger: PreSignUp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Resources:
MyApi:
Type: "AWS::Serverless::Api"
Properties:
StageName: Prod
Auth:
DefaultAuthorizer:
- NotAString
ApiKeyRequired: true
Authorizers:
MyLambdaTokenAuth:
FunctionPayloadType: TOKEN
FunctionArn: arn:aws
FunctionInvokeRole: arn:aws:iam::123456789012:role/S3Access
Identity:
Header: MyCustomAuthHeader
ValidationExpression: mycustomauthexpression
ReauthorizeEvery: 20

StateMachine:
Type: AWS::Serverless::StateMachine
Properties:
Name: MyStateMachine
Type: STANDARD
Definition:
Comment: A Hello World example of the Amazon States Language using Pass states
StartAt: Hello
States:
Hello:
Type: Pass
Result: Hello
Next: World
World:
Type: Pass
Result: World
End: true
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Deny
Action: "*"
Resource: "*"
Events:
WithNoAuthorizer:
Type: Api
Properties:
Path: /startNoAuth
Method: post
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ImplicitApiFunction] is invalid. Event with id [ImplicitApiFunctionOneTrigger] is invalid. Ref in Userpool is not a string."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. DefaultAuthorizer is not a string."
}
2 changes: 2 additions & 0 deletions tests/translator/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_sw
"error_state_machine_with_api_auth_none",
"error_state_machine_with_no_api_authorizers",
"error_state_machine_with_undefined_api_authorizer",
"error_state_machine_with_invalid_default_authorizer",
"error_cognito_userpool_duplicate_trigger",
"error_cognito_userpool_not_string",
"error_api_duplicate_methods_same_path",
"error_api_gateway_responses_nonnumeric_status_code",
"error_api_gateway_responses_unknown_responseparameter",
Expand Down