Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes auth migration e2e #8756

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 16 additions & 8 deletions packages/amplify-e2e-core/src/categories/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ export function addAuthWithCustomTrigger(cwd: string, settings: any): Promise<vo
}

export function updateAuthSignInSignOutUrl(cwd: string, settings: any): Promise<void> {
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();
}
Expand Down Expand Up @@ -384,8 +385,9 @@ export function updateAuthSignInSignOutUrl(cwd: string, settings: any): Promise<
}

export function updateAuthToRemoveFederation(cwd: string, settings: any): Promise<void> {
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();
}
Expand All @@ -405,8 +407,9 @@ export function updateAuthToRemoveFederation(cwd: string, settings: any): Promis
}

export function updateAuthWithoutCustomTrigger(cwd: string, settings: any): Promise<void> {
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();
}
Expand Down Expand Up @@ -498,8 +501,11 @@ export function addAuthWithRecaptchaTrigger(cwd: string, settings: any): Promise
}

export function updateAuthRemoveRecaptchaTrigger(cwd: string, settings: any): Promise<void> {
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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -1583,8 +1589,9 @@ export function addAuthUserPoolOnlyNoOAuth(cwd: string, settings: AddAuthUserPoo
}

export function updateAuthAddAdminQueries(projectDir: string, groupName: string = 'adminQueriesGroup', settings?: any): Promise<void> {
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();
}
Expand Down Expand Up @@ -1614,8 +1621,9 @@ export function updateAuthAddAdminQueries(projectDir: string, groupName: string
}

export function updateAuthWithoutTrigger(cwd: string, settings: any): Promise<void> {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
deleteProject,
deleteProjectDir,
getAwsAndroidConfig,
getBackendAmplifyMeta,
getLambdaFunction,
getProjectMeta,
getUserPool,
Expand Down Expand Up @@ -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');
Expand All @@ -131,40 +132,15 @@ 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 = {
resourceName: authResourceName,
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 () => {
Expand Down Expand Up @@ -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);
Expand Down