Skip to content

Commit

Permalink
chore: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed Jul 17, 2023
1 parent 73e93b3 commit b1a8d78
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 1 deletion.
102 changes: 102 additions & 0 deletions packages/amplify-e2e-core/src/categories/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,108 @@ export function updateAuthToAddSignInSignOutUrlAfterPull(
.runAsync();
}

export function updateAuthDomainPrefixWithAllProvidersConfigured(
cwd: string,
settings: { domainPrefix: string; testingWithLatestCodebase?: boolean },
): Promise<void> {
const testingWithLatestCodebase = settings.testingWithLatestCodebase ?? false;
const chain = spawn(getCLIPath(testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true });
const {
FACEBOOK_APP_ID,
FACEBOOK_APP_SECRET,
GOOGLE_APP_ID,
GOOGLE_APP_SECRET,
AMAZON_APP_ID,
AMAZON_APP_SECRET,
APPLE_APP_ID,
APPLE_KEY_ID,
APPLE_TEAM_ID,
APPLE_PRIVATE_KEY,
} = getSocialProviders(true);

return chain
.wait('What do you want to do?')
.send(KEY_DOWN_ARROW)
.send(KEY_DOWN_ARROW)
.sendCarriageReturn()
.wait('Select the authentication/authorization services that you want to use:')
.sendCarriageReturn()
.wait('Do you want to add User Pool Groups?')
.sendCarriageReturn()
.wait('Do you want to add an admin queries API?')
.sendCarriageReturn()
.wait('Multifactor authentication (MFA) user login options:')
.sendCarriageReturn()
.wait('Email based user registration/forgot password:')
.sendCarriageReturn()
.wait('Specify an email verification subject:')
.sendCarriageReturn()
.wait('Specify an email verification message:')
.sendCarriageReturn()
.wait('Do you want to override the default password policy for this User Pool?')
.sendCarriageReturn()
.wait("Specify the app's refresh token expiration period (in days):")
.sendCarriageReturn()
.wait('Do you want to specify the user attributes this app can read and write?')
.sendCarriageReturn()
.wait('Do you want to enable any of the following capabilities?')
.sendCarriageReturn()
.wait('Do you want to use an OAuth flow?')
.sendCarriageReturn()
.wait('What domain name prefix do you want to use?')
.sendLine(settings.domainPrefix)
.wait('Which redirect signin URIs do you want to edit?')
.sendCarriageReturn()
.wait('Do you want to add redirect signin URIs?')
.sendNo()
.sendCarriageReturn()
.wait('Which redirect signout URIs do you want to edit?')
.sendCarriageReturn()
.wait('Do you want to add redirect signout URIs?')
.sendNo()
.sendCarriageReturn()
.wait('Select the OAuth flows enabled for this project')
.sendCarriageReturn()
.wait('Select the OAuth scopes enabled for this project')
.sendCarriageReturn()
.wait('Select the identity providers you want to configure for your user pool:')
.sendCarriageReturn()
.wait('Enter your Facebook App ID for your OAuth flow:')
.send(FACEBOOK_APP_ID)
.sendCarriageReturn()
.wait('Enter your Facebook App Secret for your OAuth flow:')
.send(FACEBOOK_APP_SECRET)
.sendCarriageReturn()
.wait('Enter your Google Web Client ID for your OAuth flow:')
.send(GOOGLE_APP_ID)
.sendCarriageReturn()
.wait('Enter your Google Web Client Secret for your OAuth flow:')
.send(GOOGLE_APP_SECRET)
.sendCarriageReturn()
.wait('Enter your Amazon App ID for your OAuth flow:')
.send(AMAZON_APP_ID)
.sendCarriageReturn()
.wait('Enter your Amazon App Secret for your OAuth flow:')
.send(AMAZON_APP_SECRET)
.sendCarriageReturn()
.wait('Enter your Services ID for your OAuth flow:')
.send(APPLE_APP_ID)
.sendCarriageReturn()
.wait('Enter your Team ID for your OAuth flow:')
.send(APPLE_TEAM_ID)
.sendCarriageReturn()
.wait('Enter your Key ID for your OAuth flow:')
.send(APPLE_KEY_ID)
.sendCarriageReturn()
.wait('Enter your Private Key for your OAuth flow')
.send(APPLE_PRIVATE_KEY)
.sendCarriageReturn()
.wait('Do you want to configure Lambda Triggers for Cognito?')
.sendNo()
.sendCarriageReturn()
.runAsync();
}

export function updateAuthToRemoveFederation(cwd: string, settings: any): Promise<void> {
const testingWithLatestCodebase = settings.testingWithLatestCodebase ?? false;
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/utils/nexpect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ function chain(context: Context): ExecutionContext {
},
name: '_send',
shift: true,
description: "'[send] Y <CR>",
description: "'[send] N <CR>",
requiresInput: false,
};
context.queue.push(_send);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getUserPoolDomain,
getUserPoolId,
updateAuthAddUserGroups,
updateAuthDomainPrefixWithAllProvidersConfigured,
updateHeadlessAuth,
} from '@aws-amplify/amplify-e2e-core';
import { initJSProjectWithProfileV12 } from '../../migration-helpers-v12/init';
Expand Down Expand Up @@ -149,6 +150,34 @@ describe('amplify auth hosted ui', () => {

await updateHeadlessAuth(projRoot, updateAuthRequest, { testingWithLatestCodebase: true });
await amplifyPushNonInteractive(projRoot, true);

const userPoolId = getUserPoolId(projRoot);
const hostedUIDomain = getHostedUIDomain(projRoot);

expect(userPoolId).toEqual(originalUserPoolId);
const userPoolRes = await getUserPool(userPoolId, region);
expect(hostedUIDomain).not.toEqual(originalHostedUIDomain);
expect(hostedUIDomain).toMatch(updatedDomainPrefix);
expect(hostedUIDomain).toEqual(userPoolRes.UserPool.Domain);

const updatedDomainRes = await getUserPoolDomain(hostedUIDomain, region);
expect(updatedDomainRes).toBeDefined();
const originalDomainRes = await getUserPoolDomain(originalHostedUIDomain, region);
expect(originalDomainRes).toEqual({ DomainDescription: {} });

const deleteOriginalDomainRes = await deleteUserPoolDomain(originalHostedUIDomain, userPoolId, region);
// undefined response as it throws InvalidParameterException: No such domain or user pool exists.
expect(deleteOriginalDomainRes).toBeUndefined();
});

it('updates hosted ui domain with new version and pushes', async () => {
const updatedDomainPrefix = `new-prefix-${generateRandomShortId()}`;
await updateAuthDomainPrefixWithAllProvidersConfigured(projRoot, {
domainPrefix: updatedDomainPrefix,
testingWithLatestCodebase: true,
});
await amplifyPushAuth(projRoot, true);

const userPoolId = getUserPoolId(projRoot);
const hostedUIDomain = getHostedUIDomain(projRoot);

Expand Down

0 comments on commit b1a8d78

Please sign in to comment.