-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Attila Hajdrik
committed
Dec 19, 2021
1 parent
ef93353
commit d5b4e8f
Showing
3 changed files
with
125 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/amplify-e2e-tests/src/__tests__/auth_9.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { | ||
addAuthWithRecaptchaTrigger, | ||
amplifyPushAuth, | ||
createNewProjectDir, | ||
deleteProject, | ||
deleteProjectDir, | ||
getCLIPath, | ||
getProjectMeta, | ||
getUserPool, | ||
initJSProjectWithProfile, | ||
nspawn as spawn, | ||
} from 'amplify-e2e-core'; | ||
import { CognitoIdentityServiceProvider } from 'aws-sdk'; | ||
|
||
const defaultsSettings = { | ||
name: 'authTest', | ||
}; | ||
|
||
describe('amplify auth with trigger', () => { | ||
let projRoot: string; | ||
|
||
beforeEach(async () => { | ||
projRoot = await createNewProjectDir('auth'); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteProject(projRoot); | ||
deleteProjectDir(projRoot); | ||
}); | ||
|
||
it('add auth with trigger, push, update auth, push, verify trigger attachment', async () => { | ||
await initJSProjectWithProfile(projRoot, defaultsSettings); | ||
await addAuthWithRecaptchaTrigger(projRoot, {}); | ||
await amplifyPushAuth(projRoot); | ||
|
||
const meta = getProjectMeta(projRoot); | ||
const userPoolId = Object.keys(meta.auth).map(key => meta.auth[key])[0].output.UserPoolId; | ||
let userPool = (await getUserPool( | ||
userPoolId, | ||
meta.providers.awscloudformation.Region, | ||
)) as CognitoIdentityServiceProvider.DescribeUserPoolResponse; | ||
|
||
expect(userPool.UserPool).toBeDefined(); | ||
expect(userPool.UserPool.LambdaConfig).toBeDefined(); | ||
expect(userPool.UserPool.LambdaConfig.CreateAuthChallenge).toBeDefined(); | ||
expect(userPool.UserPool.LambdaConfig.DefineAuthChallenge).toBeDefined(); | ||
expect(userPool.UserPool.LambdaConfig.VerifyAuthChallengeResponse).toBeDefined(); | ||
|
||
await updateAuthChangeToUserPoolOnlyAndSetCodeMessages(projRoot, {}); | ||
|
||
await amplifyPushAuth(projRoot); | ||
|
||
userPool = (await getUserPool( | ||
userPoolId, | ||
meta.providers.awscloudformation.Region, | ||
)) as CognitoIdentityServiceProvider.DescribeUserPoolResponse; | ||
|
||
expect(userPool.UserPool).toBeDefined(); | ||
expect(userPool.UserPool.EmailVerificationSubject).toBe('New code'); | ||
expect(userPool.UserPool.EmailVerificationMessage).toBe('New code is {####}'); | ||
expect(userPool.UserPool.LambdaConfig).toBeDefined(); | ||
expect(userPool.UserPool.LambdaConfig.CreateAuthChallenge).toBeDefined(); | ||
expect(userPool.UserPool.LambdaConfig.DefineAuthChallenge).toBeDefined(); | ||
expect(userPool.UserPool.LambdaConfig.VerifyAuthChallengeResponse).toBeDefined(); | ||
}); | ||
|
||
const updateAuthChangeToUserPoolOnlyAndSetCodeMessages = async (cwd: string, settings: any): Promise<void> => { | ||
return new Promise((resolve, reject) => { | ||
const chain = spawn(getCLIPath(), ['update', 'auth'], { cwd, stripColors: true }); | ||
|
||
chain | ||
.wait('What do you want to do') | ||
.sendKeyDown() | ||
.sendCarriageReturn() | ||
.wait('Select the authentication/authorization services that you want to use') | ||
.sendKeyDown() | ||
.sendCarriageReturn() | ||
.wait('Do you want to add User Pool Groups') | ||
.sendKeyDown() | ||
.sendCarriageReturn() // No | ||
.wait('Do you want to add an admin queries API') | ||
.sendKeyDown() | ||
.sendCarriageReturn() // No | ||
.wait('Multifactor authentication (MFA) user login options') | ||
.sendCarriageReturn() // Select Off | ||
.wait('Email based user registration/forgot password') | ||
.sendCarriageReturn() // Enabled | ||
.wait('Specify an email verification subject') | ||
.sendLine('New code') // New code | ||
.wait('Specify an email verification message') | ||
.sendLine('New code is {####}') // New code is {####} | ||
.wait('Do you want to override the default password policy') | ||
.sendConfirmNo() | ||
.wait("Specify the app's refresh token expiration period") | ||
.sendCarriageReturn() // 30 | ||
.wait('Do you want to specify the user attributes this app can read and write') | ||
.sendConfirmNo() | ||
.wait('Do you want to enable any of the following capabilities') | ||
.sendCarriageReturn() // Preserve recaptcha trigger | ||
.wait('Do you want to use an OAuth flow') | ||
.sendKeyDown() | ||
.sendCarriageReturn() // No | ||
.wait('Do you want to configure Lambda Triggers for Cognito') | ||
.sendConfirmNo() | ||
.sendEof() | ||
.run((err: Error) => (err ? reject(err) : resolve())); | ||
}); | ||
}; | ||
}); |