From 3b65a2a0f7dd2c1e9b71a40f5f2d14a1f99c986e Mon Sep 17 00:00:00 2001 From: Edward Foyle Date: Thu, 1 Oct 2020 14:51:02 -0700 Subject: [PATCH] fix: headless auth required attributes must be an array --- .../core-questions.test.js | 6 ++-- .../auth-request-adaptor.test.ts.snap | 30 +++++++++++++++++++ .../utils/auth-request-adaptor.test.ts | 23 ++++++++++++++ .../utils}/trigger-flow-auth-helper.test.js | 2 +- .../service-walkthrough-types.ts | 2 +- .../utils/auth-request-adaptors.ts | 2 +- 6 files changed, 59 insertions(+), 6 deletions(-) rename packages/amplify-category-auth/src/__tests__/provider-utils/{ => awscloudformation/question-factories}/core-questions.test.js (97%) create mode 100644 packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/__snapshots__/auth-request-adaptor.test.ts.snap create mode 100644 packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/auth-request-adaptor.test.ts rename packages/amplify-category-auth/src/__tests__/provider-utils/{ => awscloudformation/utils}/trigger-flow-auth-helper.test.js (90%) diff --git a/packages/amplify-category-auth/src/__tests__/provider-utils/core-questions.test.js b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/question-factories/core-questions.test.js similarity index 97% rename from packages/amplify-category-auth/src/__tests__/provider-utils/core-questions.test.js rename to packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/question-factories/core-questions.test.js index 81d84a3d9fa..07baec154a4 100644 --- a/packages/amplify-category-auth/src/__tests__/provider-utils/core-questions.test.js +++ b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/question-factories/core-questions.test.js @@ -1,8 +1,8 @@ /* eslint-disable max-len */ -const coreQuestions = require('../../provider-utils/awscloudformation/question-factories/core-questions'); -const defaults = require('../../provider-utils/awscloudformation/assets/cognito-defaults'); -const maps = require('../../provider-utils/awscloudformation/assets/string-maps'); +const coreQuestions = require('../../../../provider-utils/awscloudformation/question-factories/core-questions'); +const defaults = require('../../../../provider-utils/awscloudformation/assets/cognito-defaults'); +const maps = require('../../../../provider-utils/awscloudformation/assets/string-maps'); const defaultFileName = 'cognito-defaults'; const stringMapFileName = 'string-maps'; diff --git a/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/__snapshots__/auth-request-adaptor.test.ts.snap b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/__snapshots__/auth-request-adaptor.test.ts.snap new file mode 100644 index 00000000000..1ba418167b8 --- /dev/null +++ b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/__snapshots__/auth-request-adaptor.test.ts.snap @@ -0,0 +1,30 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`get add auth request adaptor valid translations translates request with minimal user pool config only 1`] = ` +Object { + "adminQueries": false, + "adminQueryGroup": undefined, + "authProviders": Array [], + "authSelections": "userPoolOnly", + "autoVerifiedAttributes": Array [], + "identityPoolName": undefined, + "mfaConfiguration": "OFF", + "requiredAttributes": Array [ + "email", + ], + "resourceName": "myTestAuth", + "serviceName": "Cognito", + "thirdPartyAuth": false, + "updateFlow": "manual", + "useDefault": "manual", + "userPoolGroupList": Array [], + "userPoolGroups": false, + "userPoolName": undefined, + "usernameAttributes": Array [ + "email", + ], + "userpoolClientReadAttributes": Array [], + "userpoolClientRefreshTokenValidity": undefined, + "userpoolClientWriteAttributes": Array [], +} +`; diff --git a/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/auth-request-adaptor.test.ts b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/auth-request-adaptor.test.ts new file mode 100644 index 00000000000..0915a9ddd2a --- /dev/null +++ b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/auth-request-adaptor.test.ts @@ -0,0 +1,23 @@ +import { AddAuthRequest, CognitoUserPoolSigninMethod, CognitoUserProperty } from 'amplify-headless-interface'; +import { getAddAuthRequestAdaptor } from '../../../../provider-utils/awscloudformation/utils/auth-request-adaptors'; + +describe('get add auth request adaptor', () => { + describe('valid translations', () => { + it('translates request with minimal user pool config only', () => { + const addAuthRequest: AddAuthRequest = { + version: 1, + resourceName: 'myTestAuth', + serviceConfiguration: { + serviceName: 'Cognito', + userPoolConfiguration: { + signinMethod: CognitoUserPoolSigninMethod.EMAIL, + requiredSignupAttributes: [CognitoUserProperty.EMAIL], + }, + includeIdentityPool: false, + }, + }; + + expect(getAddAuthRequestAdaptor('javascript')(addAuthRequest)).toMatchSnapshot(); + }); + }); +}); diff --git a/packages/amplify-category-auth/src/__tests__/provider-utils/trigger-flow-auth-helper.test.js b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/trigger-flow-auth-helper.test.js similarity index 90% rename from packages/amplify-category-auth/src/__tests__/provider-utils/trigger-flow-auth-helper.test.js rename to packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/trigger-flow-auth-helper.test.js index f5a62ee04ce..81fe66b8c6a 100644 --- a/packages/amplify-category-auth/src/__tests__/provider-utils/trigger-flow-auth-helper.test.js +++ b/packages/amplify-category-auth/src/__tests__/provider-utils/awscloudformation/utils/trigger-flow-auth-helper.test.js @@ -1,4 +1,4 @@ -const { handleTriggers } = require('../../provider-utils/awscloudformation/utils/trigger-flow-auth-helper'); +const { handleTriggers } = require('../../../../provider-utils/awscloudformation/utils/trigger-flow-auth-helper'); const defaults = { envVars: {}, diff --git a/packages/amplify-category-auth/src/provider-utils/awscloudformation/service-walkthrough-types.ts b/packages/amplify-category-auth/src/provider-utils/awscloudformation/service-walkthrough-types.ts index d7a184b4cfd..d9b18f1d317 100644 --- a/packages/amplify-category-auth/src/provider-utils/awscloudformation/service-walkthrough-types.ts +++ b/packages/amplify-category-auth/src/provider-utils/awscloudformation/service-walkthrough-types.ts @@ -18,7 +18,7 @@ export interface ServiceQuestionsBaseResult { requiredAttributes: string[]; authSelections: 'userPoolOnly' | 'identityPoolAndUserPool'; userPoolName?: string; - usernameAttributes?: UsernameAttributes; + usernameAttributes?: UsernameAttributes[]; userPoolGroups: boolean; userPoolGroupList?: string[]; userpoolClientRefreshTokenValidity?: number; diff --git a/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/auth-request-adaptors.ts b/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/auth-request-adaptors.ts index 776f4605f22..4cda745ed09 100644 --- a/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/auth-request-adaptors.ts +++ b/packages/amplify-category-auth/src/provider-utils/awscloudformation/utils/auth-request-adaptors.ts @@ -74,7 +74,7 @@ export const getUpdateAuthRequestAdaptor = (projectType: string, requiredAttribu const immutableAttributeAdaptor = (userPoolConfig: CognitoUserPoolConfiguration, identityPoolConfig?: CognitoIdentityPoolConfiguration) => { return { userPoolName: userPoolConfig.userPoolName, - usernameAttributes: signinAttributeMap[userPoolConfig.signinMethod], + usernameAttributes: [signinAttributeMap[userPoolConfig.signinMethod]], ...immutableIdentityPoolMap(identityPoolConfig), }; };