From 46a57a4d8837f1d815ddabe073fdad402cbe2395 Mon Sep 17 00:00:00 2001 From: akshbhu <39866697+akshbhu@users.noreply.github.com> Date: Fri, 5 Nov 2021 12:07:51 -0700 Subject: [PATCH] fix: asana bug fixes (#8692) * fix: asana bug fixes * chore: removes commmented code --- packages/amplify-category-api/src/index.ts | 1 - .../awsCognito/CognitoCLIInputs.schema.json | 82 ++++++++++++++----- packages/amplify-category-auth/src/index.js | 15 +++- .../awsCognito-user-input-types.ts | 14 ++-- .../utils/transform-user-pool-group.js | 11 +-- .../amplify-helpers/resource-status.ts | 10 --- .../src/__tests__/auth_1.test.ts | 2 +- .../src/__tests__/interactions.test.ts | 8 +- 8 files changed, 90 insertions(+), 53 deletions(-) diff --git a/packages/amplify-category-api/src/index.ts b/packages/amplify-category-api/src/index.ts index 4ada1ab74d5..96ce70e2d74 100644 --- a/packages/amplify-category-api/src/index.ts +++ b/packages/amplify-category-api/src/index.ts @@ -6,7 +6,6 @@ import { getCfnApiArtifactHandler } from './provider-utils/awscloudformation/cfn import { askAuthQuestions } from './provider-utils/awscloudformation/service-walkthroughs/appSync-walkthrough'; import { getAppSyncResourceName, getAppSyncAuthConfig } from './provider-utils/awscloudformation//utils/amplify-meta-utils'; import { authConfigToAppSyncAuthType } from './provider-utils/awscloudformation/utils/auth-config-to-app-sync-auth-type-bi-di-mapper'; - export { NETWORK_STACK_LOGICAL_ID } from './category-constants'; export { DEPLOYMENT_MECHANISM } from './provider-utils/awscloudformation/base-api-stack'; export { EcsStack } from './provider-utils/awscloudformation/ecs-apigw-stack'; diff --git a/packages/amplify-category-auth/resources/schemas/awsCognito/CognitoCLIInputs.schema.json b/packages/amplify-category-auth/resources/schemas/awsCognito/CognitoCLIInputs.schema.json index 549764f7c3c..cb80e005369 100644 --- a/packages/amplify-category-auth/resources/schemas/awsCognito/CognitoCLIInputs.schema.json +++ b/packages/amplify-category-auth/resources/schemas/awsCognito/CognitoCLIInputs.schema.json @@ -10,10 +10,10 @@ "$ref": "#/definitions/ServiceQuestionsBaseResult" }, { - "$ref": "#/definitions/Pick" + "$ref": "#/definitions/OAuthResult" }, { - "$ref": "#/definitions/Pick" + "$ref": "#/definitions/SocialProviderResult" }, { "$ref": "#/definitions/IdentityPoolResult" @@ -127,21 +127,14 @@ }, "userpoolClientLambdaRole": { "type": "string" + }, + "useEnabledMfas": { + "type": "boolean" } }, - "required": [ - "authSelections", - "requiredAttributes", - "resourceName", - "serviceName", - "useDefault", - "userpoolClientGenerateSecret", - "userpoolClientLambdaRole", - "userpoolClientReadAttributes", - "userpoolClientWriteAttributes" - ] + "required": ["authSelections", "resourceName", "serviceName", "useDefault"] }, - "Pick": { + "OAuthResult": { "type": "object", "properties": { "hostedUI": { @@ -151,10 +144,33 @@ "type": "string" }, "hostedUIProviderMeta": {}, + "hostedUIProviderCreds": {}, + "AllowedOAuthFlows": { + "enum": ["code", "implicit"], + "type": "string" + }, + "AllowedOAuthScopes": { + "type": "array", + "items": { + "type": "string" + } + }, + "newCallbackURLs": { + "type": "array", + "items": { + "type": "string" + } + }, + "newLogoutURLs": { + "type": "array", + "items": { + "type": "string" + } + }, "oAuthMetadata": {} } }, - "Pick": { + "SocialProviderResult": { "type": "object", "properties": { "authProvidersUserPool": { @@ -162,6 +178,36 @@ "items": { "type": "string" } + }, + "facebookAppIdUserPool": { + "type": "string" + }, + "facebookAppSecretUserPool": { + "type": "string" + }, + "googleAppIdUserPool": { + "type": "string" + }, + "googleAppSecretUserPool": { + "type": "string" + }, + "loginwithamazonAppIdUserPool": { + "type": "string" + }, + "loginwithamazonAppSecretUserPool": { + "type": "string" + }, + "signinwithappleClientIdUserPool": { + "type": "string" + }, + "signinwithappleTeamIdUserPool": { + "type": "string" + }, + "signinwithappleKeyIdUserPool": { + "type": "string" + }, + "signinwithapplePrivateKeyUserPool": { + "type": "string" } } }, @@ -245,8 +291,7 @@ "type": "string" } } - }, - "required": ["autoVerifiedAttributes"] + } }, "MfaResult": { "type": "object", @@ -265,8 +310,7 @@ "smsAuthenticationMessage": { "type": "string" } - }, - "required": ["mfaConfiguration"] + } }, "AdminQueriesResult": { "type": "object", diff --git a/packages/amplify-category-auth/src/index.js b/packages/amplify-category-auth/src/index.js index 10e93f85e45..7dd8b87c878 100644 --- a/packages/amplify-category-auth/src/index.js +++ b/packages/amplify-category-auth/src/index.js @@ -138,8 +138,11 @@ async function externalAuthEnable(context, externalCategory, resourceName, requi const authPropsValues = authExists ? Object.assign(defaults.functionMap[requirements.authSelections](currentAuthName), currentAuthParams, immutables, requirements) : Object.assign(defaults.functionMap[requirements.authSelections](currentAuthName), requirements, { - resourceName: `cognito${defaults.sharedId}`, + resourceName: currentAuthName, sharedId: defaults.sharedId, + serviceName: 'Cognito', + useDefault: 'manual', + authSelections: requirements.authSelections, }); //eslint-disable-line /* eslint-enable */ const { roles } = defaults; @@ -150,7 +153,6 @@ async function externalAuthEnable(context, externalCategory, resourceName, requi try { authProps = await removeDeprecatedProps(authProps); - await generateAuthStackTemplate(context, currentAuthName); // replace secret keys from cli inputs to be stored in deployment secrets let sharedParams = Object.assign({}, authProps); @@ -166,6 +168,15 @@ async function externalAuthEnable(context, externalCategory, resourceName, requi } }); context.amplify.saveEnvResourceParameters(context, category, authExists, envSpecificParams); + const cognitoCLIInputs = { + version: '1', + cognitoConfig: cliInputs, + }; + const cliState = new AuthInputState(cognitoCLIInputs.cognitoConfig.resourceName); + // saving cli-inputs except secrets + await cliState.saveCLIInputPayload(cognitoCLIInputs); + await generateAuthStackTemplate(context, currentAuthName); + const resourceDirPath = path.join(amplify.pathManager.getBackendDirPath(), 'auth', authProps.resourceName, 'build', 'parameters.json'); const authParameters = await amplify.readJsonFile(resourceDirPath); if (!authExists) { diff --git a/packages/amplify-category-auth/src/provider-utils/awscloudformation/service-walkthrough-types/awsCognito-user-input-types.ts b/packages/amplify-category-auth/src/provider-utils/awscloudformation/service-walkthrough-types/awsCognito-user-input-types.ts index 7096a83237b..425e4fb72ae 100644 --- a/packages/amplify-category-auth/src/provider-utils/awscloudformation/service-walkthrough-types/awsCognito-user-input-types.ts +++ b/packages/amplify-category-auth/src/provider-utils/awscloudformation/service-walkthrough-types/awsCognito-user-input-types.ts @@ -18,7 +18,7 @@ export interface ServiceQuestionsBaseResult { resourceName: string; useDefault: 'default' | 'defaultSocial' | 'manual'; updateFlow?: 'default' | 'defaultSocial' | 'manual' | 'callbacks' | 'providers' | 'updateUserPoolGroups' | 'updateAdminQueries'; - requiredAttributes: string[]; + requiredAttributes?: string[]; authSelections: 'userPoolOnly' | 'identityPoolAndUserPool' | 'identityPoolOnly'; userPoolName?: string; usernameAttributes?: UsernameAttributes[]; @@ -26,15 +26,15 @@ export interface ServiceQuestionsBaseResult { userPoolGroups?: boolean; userPoolGroupList?: string[]; userpoolClientRefreshTokenValidity?: number; - userpoolClientReadAttributes: string[]; - userpoolClientWriteAttributes: string[]; + userpoolClientReadAttributes?: string[]; + userpoolClientWriteAttributes?: string[]; userpoolClientSetAttributes?: boolean; usernameCaseSensitive?: boolean; verificationBucketName?: string; resourceNameTruncated?: string; sharedId?: string; - userpoolClientGenerateSecret: boolean; - userpoolClientLambdaRole: string; + userpoolClientGenerateSecret?: boolean; + userpoolClientLambdaRole?: string; useEnabledMfas?: boolean; } @@ -83,11 +83,11 @@ export interface PasswordRecoveryResult { emailVerificationMessage?: string; emailVerificationSubject?: string; smsVerificationMessage?: string; - autoVerifiedAttributes: string[]; + autoVerifiedAttributes?: string[]; } export interface MfaResult { - mfaConfiguration: 'OPTIONAL' | 'ON' | 'OFF'; + mfaConfiguration?: 'OPTIONAL' | 'ON' | 'OFF'; mfaTypes?: ('SMS Text Message' | 'TOTP')[]; smsAuthenticationMessage?: string; } diff --git a/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/transform-user-pool-group.js b/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/transform-user-pool-group.js index d2712bde9e2..e954b090cea 100644 --- a/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/transform-user-pool-group.js +++ b/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/transform-user-pool-group.js @@ -42,16 +42,7 @@ async function transformUserPoolGroupSchema(context) { } }); - // validating cli-inputs - const cliState = new AuthInputState(authResourceName); - const identityPoolName = cliState.getCLIInputPayload().identityPoolName; - const props = { - groups, - cognitoResourceName: authResourceName, - identityPoolName: identityPoolName, - }; - - await generateUserPoolGroupStackTemplate(props); + await generateUserPoolGroupStackTemplate(authResourceName); } module.exports = { diff --git a/packages/amplify-cli/src/extensions/amplify-helpers/resource-status.ts b/packages/amplify-cli/src/extensions/amplify-helpers/resource-status.ts index 1ac416c8e4d..c9506f32972 100644 --- a/packages/amplify-cli/src/extensions/amplify-helpers/resource-status.ts +++ b/packages/amplify-cli/src/extensions/amplify-helpers/resource-status.ts @@ -32,11 +32,6 @@ export async function showStatusTable(tableViewFilter: ViewResourceTableParams) print.info('\nTag Changes Detected'); } - //4. Display Root Stack Status - if (rootStackUpdated) { - print.info('Root Stack Changes Detected'); - } - //4. Display Detailed Diffs (Cfn/NonCfn) if (tableViewFilter.verbose) { await viewResourceDiffs({ resourcesToBeUpdated, resourcesToBeDeleted, resourcesToBeCreated }); @@ -73,11 +68,6 @@ export async function showResourceTable(category?, resourceName?, filteredResour print.info('\nTag Changes Detected'); } - //4. Display root stack Status - if (rootStackUpdated) { - print.info('\n RootStack Changes Detected'); - } - const resourceChanged = resourcesToBeCreated.length + resourcesToBeUpdated.length + resourcesToBeSynced.length + resourcesToBeDeleted.length > 0 || tagsUpdated || diff --git a/packages/amplify-e2e-tests/src/__tests__/auth_1.test.ts b/packages/amplify-e2e-tests/src/__tests__/auth_1.test.ts index 7ecf496af61..5baf0d5fc54 100644 --- a/packages/amplify-e2e-tests/src/__tests__/auth_1.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/auth_1.test.ts @@ -71,7 +71,7 @@ describe('amplify add auth...', () => { expect(clients[0].UserPoolClient.ClientSecret).toBeDefined(); }); - it.only('...should init an Android project and add default auth', async () => { + it('...should init an Android project and add default auth', async () => { await initAndroidProjectWithProfile(projRoot, defaultsSettings); await addAuthWithDefault(projRoot, {}); await amplifyPushAuth(projRoot); diff --git a/packages/amplify-e2e-tests/src/__tests__/interactions.test.ts b/packages/amplify-e2e-tests/src/__tests__/interactions.test.ts index f8418c87c21..188b8760953 100644 --- a/packages/amplify-e2e-tests/src/__tests__/interactions.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/interactions.test.ts @@ -25,9 +25,11 @@ describe('amplify add interactions', () => { await addSampleInteraction(projRoot, {}); await amplifyPushAuth(projRoot); const meta = getProjectMeta(projRoot); - const { FunctionArn: functionArn, BotName: botName, Region: region } = Object.keys(meta.interactions).map( - key => meta.interactions[key], - )[0].output; + const { + FunctionArn: functionArn, + BotName: botName, + Region: region, + } = Object.keys(meta.interactions).map(key => meta.interactions[key])[0].output; expect(functionArn).toBeDefined(); expect(botName).toBeDefined(); expect(region).toBeDefined();