Skip to content

Commit

Permalink
fix: auth e2e fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akshbhu committed Nov 10, 2021
1 parent fd006a7 commit 911185b
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ export class AmplifyAuthCognitoStack extends cdk.Stack implements AmplifyAuthCog
],
});
//TODO
this.mfaLambdaRole!.node.addDependency(this.userPoolClientInputs!.node!.defaultChild!);
this.openIdLambdaRole!.node.addDependency(this.userPoolClientInputs!.node!.defaultChild!);
// lambda function
/**
* Lambda which sets MFA config values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class AmplifyAuthTransform extends AmplifyCategoryTransform {
keys.forEach(key => {
let config: AuthTriggerConnection = {
triggerType: key === 'PreSignup' ? 'PreSignUp' : key,
lambdaFunctionName: key === 'PreSignup' ? 'PreSignUp' : `${this.resourceName}${key}`,
lambdaFunctionName: `${this.resourceName}${key}`,
};
authTriggerConnections.push(config);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function transformUserPoolGroupSchema(context) {
}
});

await generateUserPoolGroupStackTemplate(authResourceName);
await generateUserPoolGroupStackTemplate(context, authResourceName);
}

module.exports = {
Expand Down
12 changes: 6 additions & 6 deletions packages/amplify-e2e-core/src/categories/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function addApiWithOneModel(cwd: string, opts: Partial<AddApiOptions & {
const options = _.assign(defaultOptions, opts);
return new Promise<void>((resolve, reject) => {
spawn(getCLIPath(options.testingWithLatestCodebase), ['add', 'api'], { cwd, stripColors: true })
.wait('Please select from one of the below mentioned services:')
.wait('Select from one of the below mentioned services:')
.sendCarriageReturn()
.wait(/.*Here is the GraphQL API that we will create. Select a setting to edit or continue.*/)
.sendCarriageReturn()
Expand All @@ -95,7 +95,7 @@ export function addApiWithThreeModels(cwd: string, opts: Partial<AddApiOptions &
const options = _.assign(defaultOptions, opts);
return new Promise<void>((resolve, reject) => {
spawn(getCLIPath(options.testingWithLatestCodebase), ['add', 'api'], { cwd, stripColors: true })
.wait('Please select from one of the below mentioned services:')
.wait('Select from one of the below mentioned services:')
.sendCarriageReturn()
.wait(/.*Here is the GraphQL API that we will create. Select a setting to edit or continue.*/)
.sendCarriageReturn()
Expand Down Expand Up @@ -189,7 +189,7 @@ export function addApiWithAllAuthModesV2(cwd: string, opts: Partial<AddApiOption
const options = _.assign(defaultOptions, opts);
return new Promise<void>((resolve, reject) => {
spawn(getCLIPath(), ['add', 'api'], { cwd, stripColors: true })
.wait('Please select from one of the below mentioned services:')
.wait('Select from one of the below mentioned services:')
.sendCarriageReturn()
.wait(/.*Here is the GraphQL API that we will create. Select a setting to edit or continue.*/)
.sendKeyUp(3)
Expand Down Expand Up @@ -311,7 +311,7 @@ export function updateApiWithMultiAuth(cwd: string, settings: any) {
export function apiEnableDataStore(cwd: string, settings: any) {
return new Promise<void>((resolve, reject) => {
spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'api'], { cwd, stripColors: true })
.wait('Please select from one of the below mentioned services:')
.wait('Select from one of the below mentioned services:')
.sendCarriageReturn()
.wait(/.*Select a setting to edit.*/)
.sendKeyDown()
Expand Down Expand Up @@ -378,7 +378,7 @@ export function updateAPIWithResolutionStrategyWithoutModels(cwd: string, settin
export function updateAPIWithResolutionStrategyWithModels(cwd: string, settings: any) {
return new Promise<void>((resolve, reject) => {
spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'api'], { cwd, stripColors: true })
.wait('Please select from one of the below mentioned services:')
.wait('Select from one of the below mentioned services:')
.sendCarriageReturn()
.wait(/.*Select a setting to edit.*/)
.sendKeyDown()
Expand Down Expand Up @@ -418,7 +418,7 @@ export function addRestApi(cwd: string, settings: any) {
if (settings.path) {
chain
.sendConfirmYes()
.wait('Please select the REST API you would want to update')
.wait('Select the REST API you would want to update')
.sendCarriageReturn() // Select the first REST API
.wait('Provide a path')
.sendLine(settings.path)
Expand Down
14 changes: 7 additions & 7 deletions packages/amplify-e2e-core/src/categories/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export function addAuthWithCustomTrigger(cwd: string, settings: any): Promise<vo

export function updateAuthSignInSignOutUrl(cwd: string, settings: any): Promise<void> {
return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true });
const chain = spawn(getCLIPath(), ['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 @@ -385,7 +385,7 @@ export function updateAuthSignInSignOutUrl(cwd: string, settings: any): Promise<

export function updateAuthToRemoveFederation(cwd: string, settings: any): Promise<void> {
return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true });
const chain = spawn(getCLIPath(), ['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 @@ -406,7 +406,7 @@ export function updateAuthToRemoveFederation(cwd: string, settings: any): Promis

export function updateAuthWithoutCustomTrigger(cwd: string, settings: any): Promise<void> {
return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true });
const chain = spawn(getCLIPath(), ['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 @@ -499,7 +499,7 @@ export function addAuthWithRecaptchaTrigger(cwd: string, settings: any): Promise

export function updateAuthRemoveRecaptchaTrigger(cwd: string, settings: any): Promise<void> {
return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true });
const chain = spawn(getCLIPath(), ['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 @@ -1264,7 +1264,7 @@ export function updateAuthAddUserGroups(projectDir: string, groupNames: string[]
}

return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'auth'], { cwd: projectDir, stripColors: true });
const chain = spawn(getCLIPath(), ['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 @@ -1584,7 +1584,7 @@ export function addAuthUserPoolOnlyNoOAuth(cwd: string, settings: AddAuthUserPoo

export function updateAuthAddAdminQueries(projectDir: string, groupName: string = 'adminQueriesGroup', settings?: any): Promise<void> {
return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'auth'], { cwd: projectDir, stripColors: true });
const chain = spawn(getCLIPath(), ['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 @@ -1615,7 +1615,7 @@ export function updateAuthAddAdminQueries(projectDir: string, groupName: string

export function updateAuthWithoutTrigger(cwd: string, settings: any): Promise<void> {
return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(settings.testingWithLatestCodebase), ['update', 'auth'], { cwd, stripColors: true });
const chain = spawn(getCLIPath(), ['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
14 changes: 14 additions & 0 deletions packages/amplify-e2e-core/src/utils/projectMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function getParameterPath(projRoot: string, category: string, resourceName: stri
return path.join(projRoot, 'amplify', 'backend', category, resourceName, 'build', 'parameters.json');
}

function getCLIInputsPath(projRoot: string, category: string, resourceName: string) {
return path.join(projRoot, 'amplify', 'backend', category, resourceName, 'cli-inputs.json');
}

function getCategoryParameterPath(projRoot: string, category: string, resourceName: string) {
return path.join(projRoot, 'amplify', 'backend', category, resourceName, `${category}-parameters.json`);
}
Expand Down Expand Up @@ -135,6 +139,16 @@ function setParameters(projRoot: string, category: string, resourceName: string,
JSONUtilities.writeJson(parametersPath, parameters);
}

export function getCLIInputs(projRoot: string, category: string, resourceName: string): any {
const parametersPath = getCLIInputsPath(projRoot, category, resourceName);
return JSONUtilities.parse(fs.readFileSync(parametersPath, 'utf8'));
}

export function setCLIInputs(projRoot: string, category: string, resourceName: string, parameters: unknown) {
const parametersPath = getCLIInputsPath(projRoot, category, resourceName);
JSONUtilities.writeJson(parametersPath, parameters);
}

function getCategoryParameters(projRoot: string, category: string, resourceName: string): any {
const filepath = getCategoryParameterPath(projRoot, category, resourceName);
return JSONUtilities.parse(fs.readFileSync(filepath, 'utf8'));
Expand Down
14 changes: 8 additions & 6 deletions packages/amplify-e2e-tests/src/__tests__/auth_1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
initIosProjectWithProfile,
getAwsAndroidConfig,
initAndroidProjectWithProfile,
getCLIInputs,
setCLIInputs,
} from 'amplify-e2e-core';
import { addAuthWithDefault, runAmplifyAuthConsole, removeAuthWithDefault } from 'amplify-e2e-core';
import { createNewProjectDir, deleteProjectDir, getProjectMeta, getUserPool } from 'amplify-e2e-core';
Expand Down Expand Up @@ -55,9 +57,9 @@ describe('amplify add auth...', () => {
expect(clients[0].UserPoolClient.ClientSecret).toBeUndefined();

//update parameter to generate client Secret
const parameters = getParameters(projRoot, 'auth', id);
parameters.userpoolClientGenerateSecret = true;
setParameters(projRoot, 'auth', id, parameters);
const parameters = getCLIInputs(projRoot, 'auth', id);
parameters.cognitoConfig.userpoolClientGenerateSecret = true;
setCLIInputs(projRoot, 'auth', id, parameters);

await amplifyPushAuth(projRoot);

Expand All @@ -84,9 +86,9 @@ describe('amplify add auth...', () => {
let clients = await getUserPoolClients(authMeta.output.UserPoolId, clientIds, meta.providers.awscloudformation.Region);

expect(clients[0].UserPoolClient.ClientSecret).toBeUndefined();
const parameters = getParameters(projRoot, 'auth', id);
parameters.userpoolClientGenerateSecret = true;
setParameters(projRoot, 'auth', id, parameters);
const parameters = getCLIInputs(projRoot, 'auth', id);
parameters.cognitoConfig.userpoolClientGenerateSecret = true;
setCLIInputs(projRoot, 'auth', id, parameters);

await amplifyPushAuth(projRoot);

Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-tests/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('amplify init', () => {
fs.writeFileSync(localEnvPath, JSON.stringify(localEnvData, null, 2));
});

it.only('should init the project and override root and push', async () => {
it('should init the project and override root and push', async () => {
await initJSProjectWithProfile(projRoot, {});
const meta = getProjectMeta(projRoot).providers.awscloudformation;
expect(meta.Region).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ describe('nodejs version migration tests', () => {
'amplify',
'backend',
'auth',
'build',
authResourceName,
`${authResourceName}-cloudformation-template.yml`,
`${authResourceName}-cloudformation-template.json`,
);
let authStackContent = fs.readFileSync(authStackFileName).toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ export async function transformResourceWithOverrides(context: $TSContext, resour
return;
}
try {
const { transformCategoryStack } = await import(`@aws-amplify/amplify-category-${resource.category}`);
if (transformCategoryStack) {
return transformCategoryStack(context, resource);
if (resource) {
const { transformCategoryStack } = await import(`@aws-amplify/amplify-category-${resource.category}`);
if (transformCategoryStack) {
return transformCategoryStack(context, resource);
} else {
printer.info('Overrides functionality is not impleented for this category');
}
} else {
printer.info('Overrides functionality is not impleented for this category');
}
if (FeatureFlags.getBoolean('overrides.project')) {
await transformRootStack(context);
if (FeatureFlags.getBoolean('overrides.project')) {
await transformRootStack(context);
}
}
} catch (err) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function uploadAuthTriggerTemplate(context: $TSContext): Promise<{
}

const resourceDir = path.join(pathManager.getBackendDirPath(), categoryName, cognitoResource.resourceName);
const authTriggerCfnFilePath = path.join(resourceDir, AUTH_TRIGGER_TEMPLATE);
const authTriggerCfnFilePath = path.join(resourceDir, 'build', AUTH_TRIGGER_TEMPLATE);
const deploymentBucketName = _.get(amplifyMeta, ['providers', ProviderName, 'DeploymentBucketName']);

// This should not happen, so throw
Expand All @@ -43,7 +43,7 @@ export async function uploadAuthTriggerTemplate(context: $TSContext): Promise<{
return defaultResult;
}

await uploadTemplateToS3(context, path.join(resourceDir, AUTH_TRIGGER_TEMPLATE), categoryName, '', null);
await uploadTemplateToS3(context, authTriggerCfnFilePath, categoryName, '', null);

return {
AuthTriggerTemplateURL: `https://s3.amazonaws.com/${deploymentBucketName}/amplify-cfn-templates/${S3_UPLOAD_PATH}`,
Expand Down

0 comments on commit 911185b

Please sign in to comment.