From d02430a4320757a12c955753ad7be2760bdb27f6 Mon Sep 17 00:00:00 2001 From: akshbhu <39866697+akshbhu@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:53:34 -0800 Subject: [PATCH] fix: fixes auth migration e2e (#8756) * fix: fixes auth migration e2e * fix: signIn SignOut test --- .../handlers/resource-handlers.ts | 6 +--- .../amplify-e2e-core/src/categories/auth.ts | 24 ++++++++----- .../overrides/auth-migration.test.ts | 34 +++---------------- 3 files changed, 22 insertions(+), 42 deletions(-) diff --git a/packages/amplify-category-auth/src/provider-utils/awscloudformation/handlers/resource-handlers.ts b/packages/amplify-category-auth/src/provider-utils/awscloudformation/handlers/resource-handlers.ts index d7cadd6ac02..93a686b10e9 100644 --- a/packages/amplify-category-auth/src/provider-utils/awscloudformation/handlers/resource-handlers.ts +++ b/packages/amplify-category-auth/src/provider-utils/awscloudformation/handlers/resource-handlers.ts @@ -89,11 +89,7 @@ export const getAddAuthHandler = export const getUpdateAuthHandler = (context: any) => async (request: ServiceQuestionHeadlessResult | CognitoConfiguration) => { const { defaultValuesFilename } = getSupportedServices()[request.serviceName]; - // loading previous cli-inputs - const resourceName = await getAuthResourceName(context); - const cliState = new AuthInputState(resourceName); - let prevCliInputs: CognitoCLIInputs = cliState.getCLIInputPayload(); - const requestWithDefaults = await getUpdateAuthDefaultsApplier(context, defaultValuesFilename, prevCliInputs!.cognitoConfig)(request); + const requestWithDefaults = await getUpdateAuthDefaultsApplier(context, defaultValuesFilename, context.updatingAuth)(request); const resources = context.amplify.getProjectDetails().amplifyMeta; if (resources.auth.userPoolGroups) { await updateUserPoolGroups(context, requestWithDefaults.resourceName!, requestWithDefaults.userPoolGroupList); diff --git a/packages/amplify-e2e-core/src/categories/auth.ts b/packages/amplify-e2e-core/src/categories/auth.ts index ba0d4a9a577..d450f16a828 100644 --- a/packages/amplify-e2e-core/src/categories/auth.ts +++ b/packages/amplify-e2e-core/src/categories/auth.ts @@ -346,8 +346,9 @@ export function addAuthWithCustomTrigger(cwd: string, settings: any): Promise { + const testingWithLatestCodebase = settings.testingWithLatestCodebase ?? false; return new Promise((resolve, reject) => { - const chain = spawn(getCLIPath(), ['update', 'auth'], { cwd, stripColors: true }); + const chain = spawn(getCLIPath(testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true }); if (settings?.overrides?.category === 'auth') { chain.wait(`Do you want to migrate this ${settings.overrides.resourceName} to support overrides?`).sendConfirmYes(); } @@ -384,8 +385,9 @@ export function updateAuthSignInSignOutUrl(cwd: string, settings: any): Promise< } export function updateAuthToRemoveFederation(cwd: string, settings: any): Promise { + const testingWithLatestCodebase = settings.testingWithLatestCodebase ?? false; return new Promise((resolve, reject) => { - const chain = spawn(getCLIPath(), ['update', 'auth'], { cwd, stripColors: true }); + const chain = spawn(getCLIPath(testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true }); if (settings?.overrides?.category === 'auth') { chain.wait(`Do you want to migrate this ${settings.overrides.resourceName} to support overrides?`).sendConfirmYes(); } @@ -405,8 +407,9 @@ export function updateAuthToRemoveFederation(cwd: string, settings: any): Promis } export function updateAuthWithoutCustomTrigger(cwd: string, settings: any): Promise { + const testingWithLatestCodebase = settings.testingWithLatestCodebase ?? false; return new Promise((resolve, reject) => { - const chain = spawn(getCLIPath(), ['update', 'auth'], { cwd, stripColors: true }); + const chain = spawn(getCLIPath(testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true }); if (settings?.overrides?.category === 'auth') { chain.wait(`Do you want to migrate this ${settings.overrides.resourceName} to support overrides?`).sendConfirmYes(); } @@ -498,8 +501,11 @@ export function addAuthWithRecaptchaTrigger(cwd: string, settings: any): Promise } export function updateAuthRemoveRecaptchaTrigger(cwd: string, settings: any): Promise { + const testingWithLatestCodebase = settings.testingWithLatestCodebase ?? false; + console.log(testingWithLatestCodebase); + console.log(settings); return new Promise((resolve, reject) => { - const chain = spawn(getCLIPath(), ['update', 'auth'], { cwd, stripColors: true }); + const chain = spawn(getCLIPath(testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true }); if (settings?.overrides?.category === 'auth') { chain.wait(`Do you want to migrate this ${settings.overrides.resourceName} to support overrides?`).sendConfirmYes(); } @@ -1262,9 +1268,9 @@ export function updateAuthAddUserGroups(projectDir: string, groupNames: string[] if (groupNames.length == 0) { return; } - + const testingWithLatestCodebase = settings.testingWithLatestCodebase ?? false; return new Promise((resolve, reject) => { - const chain = spawn(getCLIPath(), ['update', 'auth'], { cwd: projectDir, stripColors: true }); + const chain = spawn(getCLIPath(testingWithLatestCodebase), ['update', 'auth'], { cwd: projectDir, stripColors: true }); if (settings?.overrides?.category === 'auth') { chain.wait(`Do you want to migrate this ${settings.overrides.resourceName} to support overrides?`).sendConfirmYes(); } @@ -1583,8 +1589,9 @@ export function addAuthUserPoolOnlyNoOAuth(cwd: string, settings: AddAuthUserPoo } export function updateAuthAddAdminQueries(projectDir: string, groupName: string = 'adminQueriesGroup', settings?: any): Promise { + const testingWithLatestCodebase = settings.testingWithLatestCodebase ?? false; return new Promise((resolve, reject) => { - const chain = spawn(getCLIPath(), ['update', 'auth'], { cwd: projectDir, stripColors: true }); + const chain = spawn(getCLIPath(testingWithLatestCodebase), ['update', 'auth'], { cwd: projectDir, stripColors: true }); if (settings?.overrides?.category === 'auth') { chain.wait(`Do you want to migrate this ${settings.overrides.resourceName} to support overrides?`).sendConfirmYes(); } @@ -1614,8 +1621,9 @@ export function updateAuthAddAdminQueries(projectDir: string, groupName: string } export function updateAuthWithoutTrigger(cwd: string, settings: any): Promise { + const testingWithLatestCodebase = settings.testingWithLatestCodebase ?? false; return new Promise((resolve, reject) => { - const chain = spawn(getCLIPath(), ['update', 'auth'], { cwd, stripColors: true }); + const chain = spawn(getCLIPath(testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true }); if (settings?.overrides?.category === 'auth') { chain.wait(`Do you want to migrate this ${settings.overrides.resourceName} to support overrides?`).sendConfirmYes(); } diff --git a/packages/amplify-migration-tests/src/__tests__/migration_tests/overrides/auth-migration.test.ts b/packages/amplify-migration-tests/src/__tests__/migration_tests/overrides/auth-migration.test.ts index 9b1b2a32e90..b72425edcd8 100644 --- a/packages/amplify-migration-tests/src/__tests__/migration_tests/overrides/auth-migration.test.ts +++ b/packages/amplify-migration-tests/src/__tests__/migration_tests/overrides/auth-migration.test.ts @@ -9,6 +9,7 @@ import { deleteProject, deleteProjectDir, getAwsAndroidConfig, + getBackendAmplifyMeta, getLambdaFunction, getProjectMeta, getUserPool, @@ -116,7 +117,7 @@ describe('amplify auth migration', () => { }; await updateAuthRemoveRecaptchaTrigger(projRoot, { testingWithLatestCodebase: true, overrides: overridesObj }); - await amplifyPushAuth(projRoot); + await amplifyPushAuth(projRoot, true); meta = getAwsAndroidConfig(projRoot); expect(meta.Auth.Default.authenticationFlowType).toBeDefined(); expect(meta.Auth.Default.authenticationFlowType).toEqual('USER_SRP_AUTH'); @@ -131,10 +132,7 @@ describe('amplify auth migration', () => { }; await initAndroidProjectWithProfile(projRoot, defaultSettings); await addAuthWithSignInSignOutUrl(projRoot, settings); - // turn ON feature flag - const meta = getAwsAndroidConfig(projRoot); - - const amplifyMeta = getProjectMeta(projRoot); + const amplifyMeta = getBackendAmplifyMeta(projRoot); const authResourceName = Object.keys(amplifyMeta.auth).filter(resourceName => amplifyMeta.auth[resourceName].service === 'Cognito')[0]; // update and push with codebase const overridesObj: $TSAny = { @@ -142,29 +140,7 @@ describe('amplify auth migration', () => { category: 'auth', service: 'cognito', }; - const overrideSettings = Object.assign(settings, { testingWithLatestCodebase: true, overrides: overridesObj }); - await updateAuthSignInSignOutUrl(projRoot, overrideSettings); - }); - - it('...should init an android project and add customAuth flag, and remove flag when custom auth triggers are removed upon update ', async () => { - await initAndroidProjectWithProfile(projRoot, defaultSettings); - await addAuthWithRecaptchaTrigger(projRoot, {}); - await amplifyPushAuth(projRoot); - let meta = getAwsAndroidConfig(projRoot); - expect(meta.Auth.Default.authenticationFlowType).toBeDefined(); - expect(meta.Auth.Default.authenticationFlowType).toEqual('CUSTOM_AUTH'); - const amplifyMeta = getProjectMeta(projRoot); - const authResourceName = Object.keys(amplifyMeta.auth).filter(resourceName => amplifyMeta.auth[resourceName].service === 'Cognito')[0]; // update and push with codebase - const overridesObj: $TSAny = { - resourceName: authResourceName, - category: 'auth', - service: 'cognito', - }; - await updateAuthRemoveRecaptchaTrigger(projRoot, { testingWithLatestCodebase: true, overrides: overridesObj }); - await amplifyPushAuth(projRoot); - meta = getAwsAndroidConfig(projRoot); - expect(meta.Auth.Default.authenticationFlowType).toBeDefined(); - expect(meta.Auth.Default.authenticationFlowType).toEqual('USER_SRP_AUTH'); + await updateAuthSignInSignOutUrl(projRoot, { testingWithLatestCodebase: true, overrides: overridesObj }); }); it('updates existing auth resource', async () => { @@ -192,7 +168,7 @@ describe('amplify auth migration', () => { await initJSProjectWithProfile(projRoot, defaultSettings); await addAuthWithDefault(projRoot, {}); await updateHeadlessAuth(projRoot, updateAuthRequest, {}); - await amplifyPushAuth(projRoot); + await amplifyPushAuth(projRoot, true); const meta = getProjectMeta(projRoot); const id = Object.keys(meta.auth).map(key => meta.auth[key])[0].output.UserPoolId; const userPool = await getUserPool(id, meta.providers.awscloudformation.Region);