Skip to content

Commit

Permalink
chore(cognito): integ tests for sign up
Browse files Browse the repository at this point in the history
Configuring the correct properties for sign up and testing it is hard.

This PR - #6938 - shows how it can be
easily mis-configured.

Testing the correct configuration is hard and requires a certain amount
of set up and the correct set of calls to the 'SignUp' API.

The integ tests here encode all of this in a way that can be easily
replicated when any part of sign up is being modified or needs to be
tested.
  • Loading branch information
Niranjan Jayakar committed Mar 24, 2020
1 parent 1edd507 commit 6a0a740
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"Resources": {
"myuserpoolsmsRole0E16FDD9": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "integuserpoolsignupcodemyuserpool08E7AAA5"
}
},
"Effect": "Allow",
"Principal": {
"Service": "cognito-idp.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"Policies": [
{
"PolicyDocument": {
"Statement": [
{
"Action": "sns:Publish",
"Effect": "Allow",
"Resource": "*"
}
],
"Version": "2012-10-17"
},
"PolicyName": "sns-publish"
}
]
}
},
"myuserpool01998219": {
"Type": "AWS::Cognito::UserPool",
"Properties": {
"AdminCreateUserConfig": {
"AllowAdminCreateUserOnly": false
},
"AutoVerifiedAttributes": [
"email",
"phone_number"
],
"EmailVerificationMessage": "integ-test: Account verification code is {####}",
"EmailVerificationSubject": "integ-test: Verify your account",
"LambdaConfig": {},
"Policies": {
"PasswordPolicy": {
"MinimumLength": 8,
"RequireLowercase": false,
"RequireNumbers": false,
"RequireSymbols": false,
"RequireUppercase": false
}
},
"SmsConfiguration": {
"ExternalId": "integuserpoolsignupcodemyuserpool08E7AAA5",
"SnsCallerArn": {
"Fn::GetAtt": [
"myuserpoolsmsRole0E16FDD9",
"Arn"
]
}
},
"SmsVerificationMessage": "integ-test: Account verification code is {####}",
"UserPoolName": "MyUserPool",
"VerificationMessageTemplate": {
"DefaultEmailOption": "CONFIRM_WITH_CODE",
"EmailMessage": "integ-test: Account verification code is {####}",
"EmailSubject": "integ-test: Verify your account",
"SmsMessage": "integ-test: Account verification code is {####}"
}
}
},
"myuserpoolclient8A58A3E4": {
"Type": "AWS::Cognito::UserPoolClient",
"Properties": {
"UserPoolId": {
"Ref": "myuserpool01998219"
},
"ClientName": "signup-test",
"GenerateSecret": false
}
}
},
"Outputs": {
"userpoolid": {
"Value": {
"Ref": "myuserpool01998219"
}
},
"clientid": {
"Value": {
"Ref": "myuserpoolclient8A58A3E4"
}
}
}
}
50 changes: 50 additions & 0 deletions packages/@aws-cdk/aws-cognito/test/integ.user-pool-signup-code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { App, CfnOutput, Stack } from '@aws-cdk/core';
import { UserPool, UserPoolClient, VerificationEmailStyle } from '../lib';

/*
* Stack verification steps:
* * `aws cognito-idp sign-up --client-id <cfnoutput-client-id> --username user-1 --password pass1234 \
* --user-attributes Name="phone_number",Value="<valid-phone-number-with-intl-extension>"
* * `aws cognito-idp sign-up --client-id <cfnoutput-client-id> --username user-2 --password pass1234 \
* --user-attributes Name="email",Value="<valid-email-address>"
* * An email with the message 'integ-test: Account verification code is <code>' should be received.
* * An SMS with the message 'integ-test: Account verification code is <code>' should be received.
*/

const app = new App();
const stack = new Stack(app, 'integ-user-pool-signup-code');

const userpool = new UserPool(stack, 'myuserpool', {
userPoolName: 'MyUserPool',
autoVerify: {
email: true,
phone: true,
},
selfSignUpEnabled: true,
userVerification: {
emailStyle: VerificationEmailStyle.CODE,
emailSubject: 'integ-test: Verify your account',
emailBody: 'integ-test: Account verification code is {####}',
smsMessage: 'integ-test: Account verification code is {####}',
},
passwordPolicy: {
requireUppercase: false,
requireLowercase: false,
requireDigits: false,
requireSymbols: false,
}
});

const client = new UserPoolClient(stack, 'myuserpoolclient', {
userPool: userpool,
userPoolClientName: 'signup-test',
generateSecret: false,
});

new CfnOutput(stack, 'user-pool-id', {
value: userpool.userPoolId,
});

new CfnOutput(stack, 'client-id', {
value: client.userPoolClientId
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"Resources": {
"myuserpoolsmsRole0E16FDD9": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "integuserpoolsignuplinkmyuserpoolA8374994"
}
},
"Effect": "Allow",
"Principal": {
"Service": "cognito-idp.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"Policies": [
{
"PolicyDocument": {
"Statement": [
{
"Action": "sns:Publish",
"Effect": "Allow",
"Resource": "*"
}
],
"Version": "2012-10-17"
},
"PolicyName": "sns-publish"
}
]
}
},
"myuserpool01998219": {
"Type": "AWS::Cognito::UserPool",
"Properties": {
"AdminCreateUserConfig": {
"AllowAdminCreateUserOnly": false
},
"AutoVerifiedAttributes": [
"email",
"phone_number"
],
"LambdaConfig": {},
"Policies": {
"PasswordPolicy": {
"MinimumLength": 8,
"RequireLowercase": false,
"RequireNumbers": false,
"RequireSymbols": false,
"RequireUppercase": false
}
},
"SmsConfiguration": {
"ExternalId": "integuserpoolsignuplinkmyuserpoolA8374994",
"SnsCallerArn": {
"Fn::GetAtt": [
"myuserpoolsmsRole0E16FDD9",
"Arn"
]
}
},
"SmsVerificationMessage": "integ-test: Account verification code is {####}",
"UserPoolName": "MyUserPool",
"VerificationMessageTemplate": {
"DefaultEmailOption": "CONFIRM_WITH_LINK",
"EmailMessageByLink": "integ-test: Verify by clicking on {##Verify Email##}",
"EmailSubjectByLink": "integ-test: Verify your account",
"SmsMessage": "integ-test: Account verification code is {####}"
}
}
},
"myuserpoolclient8A58A3E4": {
"Type": "AWS::Cognito::UserPoolClient",
"Properties": {
"UserPoolId": {
"Ref": "myuserpool01998219"
},
"ClientName": "signup-test",
"GenerateSecret": false
}
},
"myuserpooldomain": {
"Type": "AWS::Cognito::UserPoolDomain",
"Properties": {
"Domain": "integuserpoolsignuplinkmyuserpoolA8374994",
"UserPoolId": {
"Ref": "myuserpool01998219"
}
}
}
},
"Outputs": {
"userpoolid": {
"Value": {
"Ref": "myuserpool01998219"
}
},
"clientid": {
"Value": {
"Ref": "myuserpoolclient8A58A3E4"
}
}
}
}
56 changes: 56 additions & 0 deletions packages/@aws-cdk/aws-cognito/test/integ.user-pool-signup-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { App, CfnOutput, Stack } from '@aws-cdk/core';
import { CfnUserPoolDomain, UserPool, UserPoolClient, VerificationEmailStyle } from '../lib';

/*
* Stack verification steps:
* * `aws cognito-idp sign-up --client-id <cfnoutput-client-id> --username user-1 --password pass1234 \
* --user-attributes Name="phone_number",Value="<valid-phone-number-with-intl-extension>"
* * `aws cognito-idp sign-up --client-id <cfnoutput-client-id> --username user-2 --password pass1234 \
* --user-attributes Name="email",Value="<valid-email-address>"
* * An email with the message 'integ-test: Verify by clicking on <link>' should be received.
* * An SMS with the message 'integ-test: Account verification code is <code>' should be received.
*/

const app = new App();
const stack = new Stack(app, 'integ-user-pool-signup-link');

const userpool = new UserPool(stack, 'myuserpool', {
userPoolName: 'MyUserPool',
autoVerify: {
email: true,
phone: true,
},
selfSignUpEnabled: true,
userVerification: {
emailStyle: VerificationEmailStyle.LINK,
emailSubject: 'integ-test: Verify your account',
emailBody: 'integ-test: Verify by clicking on {##Verify Email##}',
smsMessage: 'integ-test: Account verification code is {####}',
},
passwordPolicy: {
requireUppercase: false,
requireLowercase: false,
requireDigits: false,
requireSymbols: false,
}
});

const client = new UserPoolClient(stack, 'myuserpoolclient', {
userPool: userpool,
userPoolClientName: 'signup-test',
generateSecret: false,
});

// replace with L2 once Domain support is available
new CfnUserPoolDomain(stack, 'myuserpooldomain', {
userPoolId: userpool.userPoolId,
domain: userpool.node.uniqueId,
});

new CfnOutput(stack, 'user-pool-id', {
value: userpool.userPoolId,
});

new CfnOutput(stack, 'client-id', {
value: client.userPoolClientId
});

0 comments on commit 6a0a740

Please sign in to comment.