Skip to content

Commit

Permalink
fix: address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
akshbhu committed May 16, 2022
1 parent b34dc5f commit 60276d1
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 228 deletions.
18 changes: 15 additions & 3 deletions packages/amplify-category-auth/amplify-plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "auth",
"type": "category",
"commands": ["add", "console", "enable", "import", "push", "remove", "update", "help", "override"],
"eventHandlers": []
}
"commands": [
"add",
"console",
"enable",
"import",
"push",
"remove",
"update",
"help",
"override"
],
"eventHandlers": [
"PrePush"
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { executeAmplifyHeadlessCommand } from '../../../src';
import { ImportAuthRequest } from 'amplify-headless-interface';
import { messages } from '../../provider-utils/awscloudformation/assets/string-maps';
import { printer } from 'amplify-prompts';
import { stateManager } from 'amplify-cli-core';
import { messages } from '../../provider-utils/awscloudformation/assets/string-maps';
import { executeAmplifyHeadlessCommand } from '../..';

jest.mock('amplify-prompts', () => ({
printer: {
Expand Down Expand Up @@ -137,9 +137,9 @@ describe('import auth headless', () => {
input: {
command: 'import',
},
usageData : {
pushHeadlessFlow : jest.fn()
}
usageData: {
pushHeadlessFlow: jest.fn(),
},
};
});

Expand Down Expand Up @@ -189,7 +189,7 @@ describe('import auth headless', () => {
await executeAmplifyHeadlessCommand(mockContext, headlessPayloadString);

expect(printer.warn).toBeCalledWith(
"Auth has already been imported to this project and cannot be modified from the CLI. To modify, run \"amplify remove auth\" to un-link the imported auth resource. Then run \"amplify import auth\".",
'Auth has already been imported to this project and cannot be modified from the CLI. To modify, run "amplify remove auth" to un-link the imported auth resource. Then run "amplify import auth".',
);
});

Expand All @@ -209,11 +209,11 @@ describe('import auth headless', () => {

fail('should throw error');
} catch (e) {
expect(e.message).toBe(`The previously configured Cognito User Pool: '' (user-pool-123) cannot be found.`);
expect(e.message).toBe('The previously configured Cognito User Pool: \'\' (user-pool-123) cannot be found.');
}
});

it('should throw web clients not found exception ', async () => {
it('should throw web clients not found exception', async () => {
stateManager_mock.getMeta = jest.fn().mockReturnValue({
providers: {
awscloudformation: {},
Expand All @@ -239,7 +239,7 @@ describe('import auth headless', () => {
awscloudformation: {},
},
});
const INVALID_USER_POOL_ID = USER_POOL_ID + '-invalid';
const INVALID_USER_POOL_ID = `${USER_POOL_ID}-invalid`;
const invalidHeadlessPayload = {
...headlessPayload,
userPoolId: INVALID_USER_POOL_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ const updateIdentityProvider = async (providerName, userPoolId, hostedUIProvider
"HostedUIProvidersCustomResourceInputs": Object {
"DeletionPolicy": "Delete",
"DependsOn": Array [
"HostedUIProvidersCustomResourceLogPolicy",
"hostedUIProvidersCustomResourceSecretPolicy",
],
"Properties": Object {
"ServiceToken": Object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { $TSContext, spinner, stateManager } from 'amplify-cli-core';
import { $TSContext, stateManager } from 'amplify-cli-core';
import aws from 'aws-sdk';
import { getFullyQualifiedSecretName, oauthObjSecretKey } from './secret-name';
import { getFullyQualifiedSecretName, oAuthObjSecretKey } from './secret-name';

/**
* Manages the state of OAuth secrets in AWS ParameterStore
Expand All @@ -24,7 +24,7 @@ export class OAuthSecretsStateManager {
*/
setOAuthSecrets = async (hostedUISecretObj: string, resourceName: string): Promise<void> => {
const { envName } = stateManager.getLocalEnvInfo();
const secretName = getFullyQualifiedSecretName(oauthObjSecretKey, resourceName, envName);
const secretName = getFullyQualifiedSecretName(oAuthObjSecretKey, resourceName, envName);
const secretValue = hostedUISecretObj;
await this.ssmClient
.putParameter({
Expand All @@ -40,7 +40,7 @@ export class OAuthSecretsStateManager {
*/
getOAuthSecrets = async (resourceName: string): Promise<string | undefined> => {
const { envName } = stateManager.getLocalEnvInfo();
const secretName = getFullyQualifiedSecretName(oauthObjSecretKey, resourceName, envName);
const secretName = getFullyQualifiedSecretName(oAuthObjSecretKey, resourceName, envName);
let secretValue;
try {
const parameter = await this.ssmClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';
import { getAppId } from '../utils/get-app-id';

export const oAuthSecretsPathAmplifyAppIdKey = 'oAuthSecretsPathAmplifyAppId';
export const oauthObjSecretKey = 'hostedUIProviderCreds';
export const oAuthObjSecretKey = 'hostedUIProviderCreds';

/**
* Returns the full name of the SSM parameter for secretName in resourceName in envName.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const syncOAuthSecretsToCloud = async (context: $TSContext, authResourceN
const authCliInputs = cliState.getCLIInputPayload();
const oAuthSecretsStateManager = await OAuthSecretsStateManager.getInstance(context);
const authProviders = authCliInputs.cognitoConfig.authProvidersUserPool;
const { hostedUI } = authCliInputs.cognitoConfig;
const { hostedUI, userPoolName } = authCliInputs.cognitoConfig;
if (!_.isEmpty(authProviders) && hostedUI) {
if (!_.isEmpty(secrets)) {
oAuthSecrets = secrets?.hostedUIProviderCreds;
Expand All @@ -34,7 +34,7 @@ export const syncOAuthSecretsToCloud = async (context: $TSContext, authResourceN
// eslint-disable-next-line max-depth
if (_.isEmpty(oAuthSecrets)) {
// data is present in deployent secrets , which can be fetched from cognito
oAuthSecrets = await getOAuthObjectFromCognito(context, authResourceName);
oAuthSecrets = await getOAuthObjectFromCognito(context, userPoolName!);
await oAuthSecretsStateManager.setOAuthSecrets(oAuthSecrets, authResourceName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const setAppIdForFunctionInTeamProvider = (authResourceName: string): voi
};

/**
* remove app id in tea provider info
* remove app id in team provider info
*/
export const removeAppIdForFunctionInTeamProvider = (authResourceName: string): void => {
const tpi = stateManager.getTeamProviderInfo(undefined, { throwIfNotExist: false, default: {} });
Expand Down
Loading

0 comments on commit 60276d1

Please sign in to comment.