Skip to content

Commit

Permalink
test: split hosted ui test (#13478)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed Dec 15, 2023
1 parent 49b946f commit 51241f7
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 64 deletions.
13 changes: 11 additions & 2 deletions codebuild_specs/e2e_workflow_generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2302,12 +2302,21 @@ batch:
CLI_REGION: us-west-2
depend-on:
- upb
- identifier: l_auth_hosted_ui_lambda_migration_v12
- identifier: l_auth_hosted_ui_lambda_migration_1_v12
buildspec: codebuild_specs/migration_tests_v12.yml
env:
variables:
compute-type: BUILD_GENERAL1_SMALL
TEST_SUITE: src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration.test.ts
TEST_SUITE: src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration-1.test.ts
CLI_REGION: us-west-2
depend-on:
- upb
- identifier: l_auth_hosted_ui_lambda_migration_2_v12
buildspec: codebuild_specs/migration_tests_v12.yml
env:
variables:
compute-type: BUILD_GENERAL1_SMALL
TEST_SUITE: src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration-2.test.ts
CLI_REGION: eu-central-1
depend-on:
- upb
Expand Down
3 changes: 2 additions & 1 deletion codebuild_specs/wait_for_ids.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"l_auth_9_custom_resources_env_5",
"l_auth_add_all_migration_v10",
"l_auth_app_client_secret_migration_v12",
"l_auth_hosted_ui_lambda_migration_v12",
"l_auth_hosted_ui_lambda_migration_1_v12",
"l_auth_hosted_ui_lambda_migration_2_v12",
"l_auth_lambda_callout_migration_rollback_v12",
"l_auth_lambda_callout_migration_v12",
"l_auth_migration_amplify_remove_api_2a",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { allowedVersionsToMigrateFrom, versionCheck } from '../../migration-helpers';
import {
addAuthUserPoolOnlyWithOAuth,
AddAuthUserPoolOnlyWithOAuthSettings,
amplifyPushAuth,
amplifyPushForce,
amplifyPushNonInteractive,
createNewProjectDir,
createUserPoolOnlyWithOAuthSettings,
deleteProject,
deleteProjectDir,
generateRandomShortId,
getHostedUIDomain,
getProjectMeta,
getUserPool,
getUserPoolId,
tryScheduleCredentialRefresh,
updateAuthAddUserGroups,
updateHeadlessAuth,
} from '@aws-amplify/amplify-e2e-core';
import { initJSProjectWithProfileV12 } from '../../migration-helpers-v12/init';
import { UpdateAuthRequest } from 'amplify-headless-interface';

describe('amplify auth hosted ui', () => {
beforeAll(async () => {
tryScheduleCredentialRefresh();

const migrateFromVersion = { v: '12.0.3' };
const migrateToVersion = { v: 'uninitialized' };

await versionCheck(process.cwd(), false, migrateFromVersion);
await versionCheck(process.cwd(), true, migrateToVersion);

expect(allowedVersionsToMigrateFrom).toContain(migrateFromVersion.v);
});

let projRoot: string;

beforeEach(async () => {
projRoot = await createNewProjectDir('hostedUIMigration');
});

afterEach(async () => {
await deleteProject(projRoot, null, true);
deleteProjectDir(projRoot);
});

describe('project with hosted ui created by old version', () => {
let oauthSettings: AddAuthUserPoolOnlyWithOAuthSettings;
let originalUserPoolId: string;
let originalHostedUIDomain: string;
let region: string;
beforeEach(async () => {
oauthSettings = createUserPoolOnlyWithOAuthSettings('hui', generateRandomShortId());
await initJSProjectWithProfileV12(projRoot);
await addAuthUserPoolOnlyWithOAuth(projRoot, oauthSettings);
await amplifyPushAuth(projRoot);
originalUserPoolId = getUserPoolId(projRoot);
originalHostedUIDomain = getHostedUIDomain(projRoot);
const meta = getProjectMeta(projRoot);
region = meta.providers.awscloudformation.Region;
expect(originalHostedUIDomain).toMatch(oauthSettings.domainPrefix);
});

it('keeps hosted ui domain after force push with new version', async () => {
await amplifyPushForce(projRoot, true);
const userPoolId = getUserPoolId(projRoot);
const hostedUIDomain = getHostedUIDomain(projRoot);

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

it('keeps hosted ui domain after update and push with new version', async () => {
await updateAuthAddUserGroups(projRoot, ['group1', 'group2'], { testingWithLatestCodebase: true, updateUserPoolGroupsPosition: 5 });
await amplifyPushAuth(projRoot, true);
const userPoolId = getUserPoolId(projRoot);
const hostedUIDomain = getHostedUIDomain(projRoot);

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

it('keeps hosted ui domain after headless update and push with new version', async () => {
const updateAuthRequest: UpdateAuthRequest = {
version: 2,
serviceModification: {
serviceName: 'Cognito',
userPoolModification: {
autoVerifiedAttributes: [
{
type: 'EMAIL',
},
],
userPoolGroups: [
{
groupName: 'group1',
},
{
groupName: 'group2',
},
],
},
includeIdentityPool: false,
},
};

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).toEqual(originalHostedUIDomain);
expect(hostedUIDomain).toEqual(userPoolRes.UserPool.Domain);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
addAuthUserPoolOnlyWithOAuth,
AddAuthUserPoolOnlyWithOAuthSettings,
amplifyPushAuth,
amplifyPushForce,
amplifyPushNonInteractive,
createNewProjectDir,
createUserPoolOnlyWithOAuthSettings,
Expand All @@ -17,7 +16,6 @@ import {
getUserPoolDomain,
getUserPoolId,
tryScheduleCredentialRefresh,
updateAuthAddUserGroups,
updateAuthDomainPrefixWithAllProvidersConfigured,
updateHeadlessAuth,
} from '@aws-amplify/amplify-e2e-core';
Expand Down Expand Up @@ -65,64 +63,6 @@ describe('amplify auth hosted ui', () => {
expect(originalHostedUIDomain).toMatch(oauthSettings.domainPrefix);
});

it('keeps hosted ui domain after force push with new version', async () => {
await amplifyPushForce(projRoot, true);
const userPoolId = getUserPoolId(projRoot);
const hostedUIDomain = getHostedUIDomain(projRoot);

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

it('keeps hosted ui domain after update and push with new version', async () => {
await updateAuthAddUserGroups(projRoot, ['group1', 'group2'], { testingWithLatestCodebase: true, updateUserPoolGroupsPosition: 5 });
await amplifyPushAuth(projRoot, true);
const userPoolId = getUserPoolId(projRoot);
const hostedUIDomain = getHostedUIDomain(projRoot);

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

it('keeps hosted ui domain after headless update and push with new version', async () => {
const updateAuthRequest: UpdateAuthRequest = {
version: 2,
serviceModification: {
serviceName: 'Cognito',
userPoolModification: {
autoVerifiedAttributes: [
{
type: 'EMAIL',
},
],
userPoolGroups: [
{
groupName: 'group1',
},
{
groupName: 'group2',
},
],
},
includeIdentityPool: false,
},
};

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).toEqual(originalHostedUIDomain);
expect(hostedUIDomain).toEqual(userPoolRes.UserPool.Domain);
});

it('updates hosted ui domain headless with new version and pushes', async () => {
const updatedDomainPrefix = `new-prefix-${generateRandomShortId()}`;
const updateAuthRequest: UpdateAuthRequest = {
Expand Down
3 changes: 2 additions & 1 deletion scripts/split-e2e-test-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const migrationFromV10Tests = [
export const migrationFromV12Tests = [
'src/__tests__/migration_tests_v12/auth.migration.test.ts',
'src/__tests__/migration_tests_v12/auth-app-client-secret-migration.test.ts',
'src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration.test.ts',
'src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration-1.test.ts',
'src/__tests__/migration_tests_v12/auth-hosted-ui-lambda-migration-2.test.ts',
'src/__tests__/migration_tests_v12/auth-lambda-callout-migration.test.ts',
'src/__tests__/migration_tests_v12/auth-lambda-callout-migration-rollback.test.ts',
'src/__tests__/migration_tests_v12/auth-oauth-lambda-migration.test.ts',
Expand Down

0 comments on commit 51241f7

Please sign in to comment.