Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Validate Trigger field and test Cognito properties with intrinsic functions #2092

Merged
merged 8 commits into from Jul 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion samtranslator/model/eventsources/push.py
Expand Up @@ -947,7 +947,7 @@ class Cognito(PushEventSource):

property_types = {
"UserPool": PropertyType(True, is_str()),
"Trigger": PropertyType(True, one_of(is_str(), list_of(is_str()))),
"Trigger": PropertyType(True, one_of(is_str(), list_of(is_str())), False),
}

def resources_to_link(self, resources):
Expand Down
18 changes: 13 additions & 5 deletions tests/translator/input/cognito_userpool_with_event.yaml
Expand Up @@ -2,8 +2,16 @@ Resources:
UserPool:
Type: AWS::Cognito::UserPool
Properties:
LambdaConfig:
PreAuthentication: "Test"
UserPoolName: UserPoolName
Policies:
PasswordPolicy:
MinimumLength: 8
UsernameAttributes:
- email
Schema:
- AttributeDataType: String
Name: email
Required: false
ImplicitApiFunction:
Type: AWS::Serverless::Function
Properties:
Expand All @@ -14,12 +22,12 @@ Resources:
OneTrigger:
Type: Cognito
Properties:
UserPool:
UserPool:
Ref: UserPool
Trigger: PreSignUp
TwoTrigger:
Type: Cognito
Properties:
UserPool:
UserPool:
Ref: UserPool
Trigger: [Test1, Test2]
Trigger: [PostConfirmation, VerifyAuthChallengeResponse]
28 changes: 28 additions & 0 deletions tests/translator/input/error_cognito_trigger_invalid_type.yaml
@@ -0,0 +1,28 @@
Resources:
UserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: UserPoolName
Policies:
PasswordPolicy:
MinimumLength: 8
UsernameAttributes:
- email
Schema:
- AttributeDataType: String
Name: email
Required: false
ImplicitApiFunction:
Type: AWS::Serverless::Function
Properties:
InlineCode: |
exports.handler = async () => ‘Hello World!'
Handler: index.handler
Runtime: nodejs12.x
Events:
OneTrigger:
Type: Cognito
Properties:
UserPool:
Ref: UserPool
Trigger: !Join [ "", [ "Pre", "Sign", "Up"] ]
68 changes: 42 additions & 26 deletions tests/translator/output/aws-cn/cognito_userpool_with_event.json
Expand Up @@ -6,60 +6,67 @@
"LambdaConfig": {
"PreSignUp": {
"Fn::GetAtt": [
"ImplicitApiFunction", "Arn"
"ImplicitApiFunction",
"Arn"
]
},
"PreAuthentication": "Test",
"Test1": {
"PostConfirmation": {
"Fn::GetAtt": [
"ImplicitApiFunction",
"Arn"
]
},
"Test2": {
"VerifyAuthChallengeResponse": {
"Fn::GetAtt": [
"ImplicitApiFunction",
"Arn"
]
}
}
},
"Policies": {
"PasswordPolicy": {
"MinimumLength": 8
}
},
"Schema": [
{
"AttributeDataType": "String",
"Name": "email",
"Required": false
}
],
"UsernameAttributes": [
"email"
],
"UserPoolName": "UserPoolName"
}
},
"ImplicitApiFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "index.gethtml",
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Bucket": "sam-demo-bucket",
"S3Key": "member_portal.zip"
},
},
"Handler": "index.gethtml",
"Role": {
"Fn::GetAtt": [
"ImplicitApiFunctionRole",
"ImplicitApiFunctionRole",
"Arn"
]
},
},
"Runtime": "nodejs12.x",
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
}
},
"ImplicitApiFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
Expand All @@ -75,24 +82,33 @@
}
}
]
}
},
"ManagedPolicyArns": [
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
}
},
},
"ImplicitApiFunctionCognitoPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "ImplicitApiFunction"
},
"Principal": "cognito-idp.amazonaws.com",
"SourceArn": {
"Fn::GetAtt": [
"UserPool",
"Arn"
]
},
"Principal": "cognito-idp.amazonaws.com"
}
}
}
}
}
}
Expand Up @@ -6,60 +6,67 @@
"LambdaConfig": {
"PreSignUp": {
"Fn::GetAtt": [
"ImplicitApiFunction", "Arn"
"ImplicitApiFunction",
"Arn"
]
},
"PreAuthentication": "Test",
"Test1": {
"PostConfirmation": {
"Fn::GetAtt": [
"ImplicitApiFunction",
"Arn"
]
},
"Test2": {
"VerifyAuthChallengeResponse": {
"Fn::GetAtt": [
"ImplicitApiFunction",
"Arn"
]
}
}
},
"Policies": {
"PasswordPolicy": {
"MinimumLength": 8
}
},
"Schema": [
{
"AttributeDataType": "String",
"Name": "email",
"Required": false
}
],
"UsernameAttributes": [
"email"
],
"UserPoolName": "UserPoolName"
}
},
"ImplicitApiFunction": {
"Type": "AWS::Lambda::Function",
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "index.gethtml",
"Code": {
"S3Bucket": "sam-demo-bucket",
"S3Bucket": "sam-demo-bucket",
"S3Key": "member_portal.zip"
},
},
"Handler": "index.gethtml",
"Role": {
"Fn::GetAtt": [
"ImplicitApiFunctionRole",
"ImplicitApiFunctionRole",
"Arn"
]
},
},
"Runtime": "nodejs12.x",
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
}
},
"ImplicitApiFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"ManagedPolicyArns": [
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Value": "SAM",
"Key": "lambda:createdBy"
}
],
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
Expand All @@ -75,24 +82,33 @@
}
}
]
}
},
"ManagedPolicyArns": [
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Tags": [
{
"Key": "lambda:createdBy",
"Value": "SAM"
}
]
}
},
},
"ImplicitApiFunctionCognitoPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "ImplicitApiFunction"
},
"Principal": "cognito-idp.amazonaws.com",
"SourceArn": {
"Fn::GetAtt": [
"UserPool",
"Arn"
]
},
"Principal": "cognito-idp.amazonaws.com"
}
}
}
}
}
}