Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
israx committed Sep 13, 2023
1 parent 25ad04c commit e1f2471
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AuthValidationErrorCode } from '../../../src/errors/types/validation';
import { authAPITestParams } from './testUtils/authApiTestParams';
import { signIn } from '../../../src/providers/cognito/apis/signIn';
import * as signInHelpers from '../../../src/providers/cognito/utils/signInHelpers';
import { AuthSignInStep } from '../../../src/types';
import { confirmSignIn } from '../../../src/providers/cognito/apis/confirmSignIn';
import { RespondToAuthChallengeException } from '../../../src/providers/cognito/types/errors';
import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types';
Expand Down Expand Up @@ -54,7 +53,7 @@ describe('confirmSignIn API error path cases:', () => {
});

test(`confirmSignIn API should throw a validation AuthError when sign-in step is
${AuthSignInStep.CONTINUE_SIGN_IN_WITH_MFA_SELECTION} and challengeResponse is not "SMS" or "TOTP" `, async () => {
${'CONTINUE_SIGN_IN_WITH_MFA_SELECTION'} and challengeResponse is not "SMS" or "TOTP" `, async () => {
expect.assertions(2);
try {
await signIn({ username, password });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Amplify } from '@aws-amplify/core';
import { authAPITestParams } from './testUtils/authApiTestParams';
import { signIn } from '../../../src/providers/cognito/apis/signIn';
import * as signInHelpers from '../../../src/providers/cognito/utils/signInHelpers';
import { AuthSignInStep } from '../../../src/types';
import { confirmSignIn } from '../../../src/providers/cognito/apis/confirmSignIn';
import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types';
import { cognitoCredentialsProvider } from '../../../src/providers/cognito/credentialsProvider';
Expand Down Expand Up @@ -84,7 +83,7 @@ describe('confirmSignIn API happy path cases', () => {
expect(signInResult).toEqual({
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_CODE,
signInStep: 'CONFIRM_SIGN_IN_WITH_SMS_CODE',
codeDeliveryDetails: {
deliveryMedium: 'SMS',
destination: '*******9878',
Expand All @@ -94,7 +93,7 @@ describe('confirmSignIn API happy path cases', () => {
expect(confirmSignInResult).toEqual({
isSignedIn: true,
nextStep: {
signInStep: AuthSignInStep.DONE,
signInStep: 'DONE',
},
});

Expand Down Expand Up @@ -128,13 +127,13 @@ describe('confirmSignIn API happy path cases', () => {
expect(signInResult).toEqual({
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONFIRM_SIGN_IN_WITH_TOTP_CODE,
signInStep: 'CONFIRM_SIGN_IN_WITH_TOTP_CODE',
},
});
expect(confirmSignInResult).toEqual({
isSignedIn: true,
nextStep: {
signInStep: AuthSignInStep.DONE,
signInStep: 'DONE',
},
});

Expand Down Expand Up @@ -185,15 +184,15 @@ describe('confirmSignIn API happy path cases', () => {
expect(signInResult).toEqual({
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONTINUE_SIGN_IN_WITH_MFA_SELECTION,
signInStep: 'CONTINUE_SIGN_IN_WITH_MFA_SELECTION',
allowedMFATypes: ['SMS', 'TOTP'],
},
});

expect(confirmSignInResult).toEqual({
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_CODE,
signInStep: 'CONFIRM_SIGN_IN_WITH_SMS_CODE',
codeDeliveryDetails: {
deliveryMedium: 'SMS',
destination: '*******9878',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { AmplifyErrorString } from '@aws-amplify/core/internals/utils';

import { AuthError } from '../../../src/errors/AuthError';
import { AuthValidationErrorCode } from '../../../src/errors/types/validation';
import { authAPITestParams } from './testUtils/authApiTestParams';
Expand All @@ -14,7 +11,6 @@ import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cogn
import { Amplify } from 'aws-amplify';
import { fetchTransferHandler } from '@aws-amplify/core/internals/aws-client-utils';
import { buildMockErrorResponse, mockJsonResponse } from './testUtils/data';
import { cognitoCredentialsProvider } from '../../../src/providers/cognito/credentialsProvider';
import { CognitoUserPoolsTokenProvider } from '../../../src/providers/cognito/tokenProvider';
jest.mock('@aws-amplify/core/lib/clients/handlers/fetch');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { decodeJWT } from '@aws-amplify/core/internals/utils';
import {
AuthResetPasswordStep,
AuthSignInResult,
AuthSignInStep,
} from '../../../../src/types';

export const authAPITestParams = {
Expand Down Expand Up @@ -202,15 +201,15 @@ export const authAPITestParams = {
return {
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE,
signInStep: 'CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE',
},
};
},
signInResult: (): AuthSignInResult => {
return {
isSignedIn: true,
nextStep: {
signInStep: AuthSignInStep.DONE,
signInStep: 'DONE',
},
};
},
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"clean:size": "rimraf dual-publish-tmp tmp*",
"format": "echo \"Not implemented\"",
"lint": "tslint '{src}/**/*.ts' && npm run ts-coverage",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 91.23"
"ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 91.22"
},
"typesVersions": {
">=3.8": {
Expand Down
1 change: 0 additions & 1 deletion packages/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export {
} from './providers/cognito';
export {
AuthResetPasswordStep,
AuthSignInStep,
AuthSignUpStep,
AuthUpdateAttributeStep
} from './types/enums';
Expand Down
3 changes: 1 addition & 2 deletions packages/auth/src/providers/cognito/apis/confirmSignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '../types/errors';
import {
AuthSignInResult,
AuthSignInStep,
ConfirmSignInRequest,
} from '../../../types';
import { CognitoConfirmSignInOptions } from '../types';
Expand Down Expand Up @@ -119,7 +118,7 @@ export async function confirmSignIn(
await cacheCognitoTokens(AuthenticationResult);
return {
isSignedIn: true,
nextStep: { signInStep: AuthSignInStep.DONE },
nextStep: { signInStep: 'DONE' },
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { assertValidationError } from '../../../errors/utils/assertValidationErr
import {
SignInRequest,
AuthSignInResult,
AuthSignInStep,
} from '../../../types';
import { assertServiceError } from '../../../errors/utils/assertServiceError';
import {
Expand Down Expand Up @@ -74,7 +73,7 @@ export async function signInWithCustomAuth(
await cacheCognitoTokens(AuthenticationResult);
return {
isSignedIn: true,
nextStep: { signInStep: AuthSignInStep.DONE },
nextStep: { signInStep: 'DONE' },
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import {
SignInRequest,
AuthSignInResult,
AuthSignInStep,
} from '../../../types';
import { CognitoSignInOptions } from '../types';
import {
Expand Down Expand Up @@ -78,7 +77,7 @@ export async function signInWithCustomSRPAuth(
cleanActiveSignInState();
return {
isSignedIn: true,
nextStep: { signInStep: AuthSignInStep.DONE },
nextStep: { signInStep: 'DONE' },
};
}

Expand Down
3 changes: 1 addition & 2 deletions packages/auth/src/providers/cognito/apis/signInWithSRP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { CognitoSignInOptions } from '../types';
import {
SignInRequest,
AuthSignInResult,
AuthSignInStep,
} from '../../../types';
import {
setActiveSignInState,
Expand Down Expand Up @@ -83,7 +82,7 @@ export async function signInWithSRP(
await cacheCognitoTokens(AuthenticationResult);
return {
isSignedIn: true,
nextStep: { signInStep: AuthSignInStep.DONE },
nextStep: { signInStep: 'DONE' },
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import { AuthValidationErrorCode } from '../../../errors/types/validation';
import { assertServiceError } from '../../../errors/utils/assertServiceError';
import { assertValidationError } from '../../../errors/utils/assertValidationError';
import {
AuthSignInResult,
AuthSignInStep,
SignInRequest,
} from '../../../types';
import { AuthSignInResult, SignInRequest } from '../../../types';
import {
ChallengeName,
ChallengeParameters,
Expand Down Expand Up @@ -79,7 +75,7 @@ export async function signInWithUserPassword(
cleanActiveSignInState();
return {
isSignedIn: true,
nextStep: { signInStep: AuthSignInStep.DONE },
nextStep: { signInStep: 'DONE' },
};
}

Expand Down
17 changes: 8 additions & 9 deletions packages/auth/src/providers/cognito/utils/signInHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ClientMetadata, CognitoConfirmSignInOptions } from '../types';
import {
AdditionalInfo,
AuthSignInResult,
AuthSignInStep,
DeliveryMedium,
} from '../../../types';
import { AuthError } from '../../../errors/AuthError';
Expand Down Expand Up @@ -385,7 +384,7 @@ export async function getSignInResult(params: {
return {
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE,
signInStep: 'CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE',
additionalInfo: challengeParameters as AdditionalInfo,
},
};
Expand Down Expand Up @@ -413,15 +412,15 @@ export async function getSignInResult(params: {
return {
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONTINUE_SIGN_IN_WITH_TOTP_SETUP,
signInStep: 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP',
totpSetupDetails: getTOTPSetupDetails(secretCode!, username),
},
};
case 'NEW_PASSWORD_REQUIRED':
return {
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED,
signInStep: 'CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED',
missingAttributes: parseAttributes(
challengeParameters.requiredAttributes
),
Expand All @@ -431,7 +430,7 @@ export async function getSignInResult(params: {
return {
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONTINUE_SIGN_IN_WITH_MFA_SELECTION,
signInStep: 'CONTINUE_SIGN_IN_WITH_MFA_SELECTION',
allowedMFATypes: getMFATypes(
parseMFATypes(challengeParameters.MFAS_CAN_CHOOSE)
),
Expand All @@ -441,7 +440,7 @@ export async function getSignInResult(params: {
return {
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_CODE,
signInStep: 'CONFIRM_SIGN_IN_WITH_SMS_CODE',
codeDeliveryDetails: {
deliveryMedium:
challengeParameters.CODE_DELIVERY_DELIVERY_MEDIUM as DeliveryMedium,
Expand All @@ -453,7 +452,7 @@ export async function getSignInResult(params: {
return {
isSignedIn: false,
nextStep: {
signInStep: AuthSignInStep.CONFIRM_SIGN_IN_WITH_TOTP_CODE,
signInStep: 'CONFIRM_SIGN_IN_WITH_TOTP_CODE',
},
};
case 'ADMIN_NO_SRP_AUTH':
Expand Down Expand Up @@ -496,12 +495,12 @@ export function getSignInResultFromError(
if (errorName === InitiateAuthException.PasswordResetRequiredException) {
return {
isSignedIn: false,
nextStep: { signInStep: AuthSignInStep.RESET_PASSWORD },
nextStep: { signInStep: 'RESET_PASSWORD' },
};
} else if (errorName === InitiateAuthException.UserNotConfirmedException) {
return {
isSignedIn: false,
nextStep: { signInStep: AuthSignInStep.CONFIRM_SIGN_UP },
nextStep: { signInStep: 'CONFIRM_SIGN_UP' },
};
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/auth/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export * from './Auth';
export {
AuthSignUpStep,
AuthResetPasswordStep,
AuthSignInStep,
AuthUpdateAttributeStep,
} from './enums';

Expand Down

0 comments on commit e1f2471

Please sign in to comment.