diff --git a/.eslintrc.js b/.eslintrc.js index e478d069592..96319456870 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -82,9 +82,11 @@ module.exports = { 'logout_uri', 'id_token', 'access_token', + 'refresh_token', 'token_type', 'expires_in', 'error_description', + 'error_message', // exceptions for the notifications package 'campaign_id', 'delivery_type', diff --git a/packages/auth/__tests__/mockData.ts b/packages/auth/__tests__/mockData.ts index eacbf143eb6..9edfd45a197 100644 --- a/packages/auth/__tests__/mockData.ts +++ b/packages/auth/__tests__/mockData.ts @@ -1,6 +1,3 @@ -// keeping this so that jest does not complain -test('should do nothing', () => {}); - // device tracking mock device data export const mockDeviceArray = [ { diff --git a/packages/auth/__tests__/providers/cognito/assertServiceError.test.ts b/packages/auth/__tests__/providers/cognito/assertServiceError.test.ts index 84ddeae7006..d17f8234b12 100644 --- a/packages/auth/__tests__/providers/cognito/assertServiceError.test.ts +++ b/packages/auth/__tests__/providers/cognito/assertServiceError.test.ts @@ -8,7 +8,9 @@ describe('asserts service errors', () => { test('it should throw an unknown error when error is null', () => { try { const error = null; - expect(assertServiceError(error)).toThrow(); + expect(() => { + assertServiceError(error); + }).toThrow(); } catch (error: any) { expect(error).toBeInstanceOf(AuthError); expect(error.name).toBe(AmplifyErrorCode.Unknown); @@ -17,7 +19,9 @@ describe('asserts service errors', () => { test('it should throw an unknown error when error is a TypeError', () => { try { const error = new TypeError('TypeError'); - expect(assertServiceError(error)).toThrow(); + expect(() => { + assertServiceError(error); + }).toThrow(); } catch (error: any) { expect(error).toBeInstanceOf(AuthError); expect(error.name).toBe(AmplifyErrorCode.Unknown); @@ -26,7 +30,9 @@ describe('asserts service errors', () => { test('it should throw an unknown error when error does not have a name', () => { try { const error = new Error('Error'); - expect(assertServiceError(error)).toThrow(); + expect(() => { + assertServiceError(error); + }).toThrow(); } catch (error: any) { expect(error).toBeInstanceOf(AuthError); expect(error.name).toBe(AmplifyErrorCode.Unknown); @@ -35,6 +41,8 @@ describe('asserts service errors', () => { test('it should not throw if the error is coming from the service', () => { const error = new Error('Service Error'); error.name = InitiateAuthException.InternalErrorException; - expect(assertServiceError(error)).toBeUndefined(); + expect(() => { + assertServiceError(error); + }).not.toThrow(); }); }); diff --git a/packages/auth/__tests__/providers/cognito/confirmResetPassword.test.ts b/packages/auth/__tests__/providers/cognito/confirmResetPassword.test.ts index e786546edf9..df8167e5030 100644 --- a/packages/auth/__tests__/providers/cognito/confirmResetPassword.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmResetPassword.test.ts @@ -44,9 +44,9 @@ describe('confirmResetPassword', () => { }); it('should call the confirmForgotPassword and return void', async () => { - expect( - await confirmResetPassword(authAPITestParams.confirmResetPasswordRequest), - ).toBeUndefined(); + await expect( + confirmResetPassword(authAPITestParams.confirmResetPasswordRequest), + ).resolves.toBeUndefined(); expect(mockConfirmForgotPassword).toHaveBeenCalled(); }); @@ -137,7 +137,7 @@ describe('confirmResetPassword', () => { }); it('should add UserContextData', async () => { - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -164,6 +164,6 @@ describe('confirmResetPassword', () => { }, }), ); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); }); diff --git a/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts b/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts index d5e84e09339..c716ee76df8 100644 --- a/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts @@ -32,7 +32,7 @@ const authConfig = { const mockedGetCurrentUser = getCurrentUser as jest.Mock; describe('confirmSignIn API happy path cases', () => { - let handleChallengeNameSpy; + let handleChallengeNameSpy: jest.SpyInstance; const { username } = authAPITestParams.user1; const { password } = authAPITestParams.user1; @@ -276,8 +276,8 @@ describe('confirmSignIn API happy path cases', () => { }); describe('Cognito ASF', () => { - let respondToAuthChallengeSpy; - let handleUserSRPAuthFlowSpy; + let respondToAuthChallengeSpy: jest.SpyInstance; + let handleUserSRPAuthFlowSpy: jest.SpyInstance; const { username } = authAPITestParams.user1; const { password } = authAPITestParams.user1; @@ -287,7 +287,7 @@ describe('Cognito ASF', () => { }); // load Cognito ASF polyfill - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -318,7 +318,7 @@ describe('Cognito ASF', () => { afterEach(() => { respondToAuthChallengeSpy.mockClear(); handleUserSRPAuthFlowSpy.mockClear(); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); afterAll(() => { @@ -415,16 +415,14 @@ describe('Cognito ASF', () => { Amplify.configure({ Auth: authConfig, }); - const handleUserSRPAuthflowSpy = jest - .spyOn(signInHelpers, 'handleUserSRPAuthFlow') - .mockImplementationOnce( - async (): Promise => ({ - ChallengeName: 'SOFTWARE_TOKEN_MFA', - Session: '1234234232', - $metadata: {}, - ChallengeParameters: {}, - }), - ); + jest.spyOn(signInHelpers, 'handleUserSRPAuthFlow').mockImplementationOnce( + async (): Promise => ({ + ChallengeName: 'SOFTWARE_TOKEN_MFA', + Session: '1234234232', + $metadata: {}, + ChallengeParameters: {}, + }), + ); const result = await signIn({ username, password }); @@ -460,16 +458,14 @@ describe('Cognito ASF', () => { Amplify.configure({ Auth: authConfig, }); - const handleUserSRPAuthflowSpy = jest - .spyOn(signInHelpers, 'handleUserSRPAuthFlow') - .mockImplementationOnce( - async (): Promise => ({ - ChallengeName: 'NEW_PASSWORD_REQUIRED', - Session: '1234234232', - $metadata: {}, - ChallengeParameters: {}, - }), - ); + jest.spyOn(signInHelpers, 'handleUserSRPAuthFlow').mockImplementationOnce( + async (): Promise => ({ + ChallengeName: 'NEW_PASSWORD_REQUIRED', + Session: '1234234232', + $metadata: {}, + ChallengeParameters: {}, + }), + ); const result = await signIn({ username, password }); @@ -506,16 +502,14 @@ describe('Cognito ASF', () => { Amplify.configure({ Auth: authConfig, }); - const handleUserSRPAuthflowSpy = jest - .spyOn(signInHelpers, 'handleUserSRPAuthFlow') - .mockImplementationOnce( - async (): Promise => ({ - ChallengeName: 'CUSTOM_CHALLENGE', - Session: '1234234232', - $metadata: {}, - ChallengeParameters: {}, - }), - ); + jest.spyOn(signInHelpers, 'handleUserSRPAuthFlow').mockImplementationOnce( + async (): Promise => ({ + ChallengeName: 'CUSTOM_CHALLENGE', + Session: '1234234232', + $metadata: {}, + ChallengeParameters: {}, + }), + ); const result = await signIn({ username, password }); diff --git a/packages/auth/__tests__/providers/cognito/confirmSignUp.test.ts b/packages/auth/__tests__/providers/cognito/confirmSignUp.test.ts index 68bd5b27031..e6528e4b1ed 100644 --- a/packages/auth/__tests__/providers/cognito/confirmSignUp.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmSignUp.test.ts @@ -144,7 +144,7 @@ describe('confirmSignUp', () => { }); it('should send UserContextData', async () => { - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -171,6 +171,6 @@ describe('confirmSignUp', () => { }, ); expect(mockConfirmSignUp).toHaveBeenCalledTimes(1); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); }); diff --git a/packages/auth/__tests__/providers/cognito/credentialsProvider.test.ts b/packages/auth/__tests__/providers/cognito/credentialsProvider.test.ts index e2ed6141927..3390e14a052 100644 --- a/packages/auth/__tests__/providers/cognito/credentialsProvider.test.ts +++ b/packages/auth/__tests__/providers/cognito/credentialsProvider.test.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 import { - GetCredentialsForIdentityInput, GetCredentialsForIdentityOutput, ResourcesConfig, getCredentialsForIdentity, @@ -75,11 +74,9 @@ describe('Guest Credentials', () => { new CognitoAWSCredentialsAndIdentityIdProvider( new DefaultIdentityIdStore(sharedInMemoryStorage), ); - credentialsForIdentityIdSpy.mockImplementationOnce( - async ({}, params: GetCredentialsForIdentityInput) => { - return authAPITestParams.CredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; - }, - ); + credentialsForIdentityIdSpy.mockImplementationOnce(async () => { + return authAPITestParams.CredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; + }); }); afterEach(() => { cognitoCredentialsProvider.clearCredentials(); @@ -101,9 +98,10 @@ describe('Guest Credentials', () => { { IdentityId: 'identity-id-test' }, ); expect( - cognitoCredentialsProvider._nextCredentialsRefresh, + (cognitoCredentialsProvider as any)._nextCredentialsRefresh, ).toBeGreaterThan(0); }); + test('in-memory guest creds are returned if not expired and not past TTL', async () => { await cognitoCredentialsProvider.getCredentialsAndIdentityId({ authenticated: false, @@ -122,19 +120,18 @@ describe('Guest Credentials', () => { expect(credentialsForIdentityIdSpy).toHaveBeenCalledTimes(1); }); }); + describe('Error Path Cases:', () => { - let cognitoCredentialsProvider; beforeEach(() => { cognitoCredentialsProvider = new CognitoAWSCredentialsAndIdentityIdProvider( new DefaultIdentityIdStore(sharedInMemoryStorage), ); - credentialsForIdentityIdSpy.mockImplementationOnce( - async ({}, params: GetCredentialsForIdentityInput) => { - return authAPITestParams.NoAccessKeyCredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; - }, - ); + credentialsForIdentityIdSpy.mockImplementationOnce(async () => { + return authAPITestParams.NoAccessKeyCredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; + }); }); + afterEach(() => { cognitoCredentialsProvider.clearCredentials(); }); @@ -161,18 +158,16 @@ describe('Guest Credentials', () => { }); describe('Primary Credentials', () => { - let cognitoCredentialsProvider; + let cognitoCredentialsProvider: CognitoAWSCredentialsAndIdentityIdProvider; describe('Happy Path Cases:', () => { beforeEach(() => { cognitoCredentialsProvider = new CognitoAWSCredentialsAndIdentityIdProvider( new DefaultIdentityIdStore(sharedInMemoryStorage), ); - credentialsForIdentityIdSpy.mockImplementation( - async ({}, params: GetCredentialsForIdentityInput) => { - return authAPITestParams.CredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; - }, - ); + credentialsForIdentityIdSpy.mockImplementation(async () => { + return authAPITestParams.CredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; + }); }); afterEach(() => { cognitoCredentialsProvider.clearCredentials(); @@ -184,7 +179,7 @@ describe('Primary Credentials', () => { authConfig: validAuthConfig.Auth!, tokens: authAPITestParams.ValidAuthTokens, }); - expect(res.credentials.accessKeyId).toEqual( + expect(res?.credentials.accessKeyId).toEqual( authAPITestParams.CredentialsForIdentityIdResult.Credentials .AccessKeyId, ); @@ -210,7 +205,7 @@ describe('Primary Credentials', () => { authConfig: validAuthConfig.Auth!, tokens: authAPITestParams.ValidAuthTokens, }); - expect(res.credentials.accessKeyId).toEqual( + expect(res?.credentials.accessKeyId).toEqual( authAPITestParams.CredentialsForIdentityIdResult.Credentials .AccessKeyId, ); @@ -231,7 +226,7 @@ describe('Primary Credentials', () => { ); expect(credentialsForIdentityIdSpy).toHaveBeenCalledTimes(1); - const res = await cognitoCredentialsProvider.getCredentialsAndIdentityId({ + await cognitoCredentialsProvider.getCredentialsAndIdentityId({ authenticated: true, authConfig: validAuthConfig.Auth!, tokens: authAPITestParams.NewValidAuthTokens, @@ -259,11 +254,9 @@ describe('Primary Credentials', () => { credentialsForIdentityIdSpy?.mockReset(); }); test('Should throw AuthError if either Credentials, accessKeyId or secretKey is absent in the response', async () => { - credentialsForIdentityIdSpy.mockImplementationOnce( - async ({}, params: GetCredentialsForIdentityInput) => { - return authAPITestParams.NoAccessKeyCredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; - }, - ); + credentialsForIdentityIdSpy.mockImplementationOnce(async () => { + return authAPITestParams.NoAccessKeyCredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; + }); expect( cognitoCredentialsProvider.getCredentialsAndIdentityId({ authenticated: true, @@ -272,11 +265,9 @@ describe('Primary Credentials', () => { }), ).rejects.toThrow(AuthError); credentialsForIdentityIdSpy.mockClear(); - credentialsForIdentityIdSpy.mockImplementationOnce( - async ({}, params: GetCredentialsForIdentityInput) => { - return authAPITestParams.NoCredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; - }, - ); + credentialsForIdentityIdSpy.mockImplementationOnce(async () => { + return authAPITestParams.NoCredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; + }); expect( cognitoCredentialsProvider.getCredentialsAndIdentityId({ authenticated: true, @@ -285,11 +276,9 @@ describe('Primary Credentials', () => { }), ).rejects.toThrow(AuthError); credentialsForIdentityIdSpy.mockClear(); - credentialsForIdentityIdSpy.mockImplementationOnce( - async ({}, params: GetCredentialsForIdentityInput) => { - return authAPITestParams.NoSecretKeyInCredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; - }, - ); + credentialsForIdentityIdSpy.mockImplementationOnce(async () => { + return authAPITestParams.NoSecretKeyInCredentialsForIdentityIdResult as GetCredentialsForIdentityOutput; + }); expect( cognitoCredentialsProvider.getCredentialsAndIdentityId({ authenticated: true, diff --git a/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts b/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts index 5a1c3c0efed..84a28ffa420 100644 --- a/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts +++ b/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts @@ -8,7 +8,7 @@ import { } from '../../../src/providers/cognito'; describe('fetchAuthSession behavior for IdentityPools only', () => { - let credentialsProviderSpy; + let credentialsProviderSpy: jest.SpyInstance; afterEach(() => { jest.resetAllMocks(); jest.clearAllMocks(); @@ -75,9 +75,8 @@ describe('fetchAuthSession behavior for IdentityPools only', () => { }); describe('fetchAuthSession behavior for UserPools only', () => { - let tokenProviderSpy; beforeEach(() => { - tokenProviderSpy = jest + jest .spyOn(cognitoUserPoolsTokenProvider, 'getTokens') .mockImplementation(async () => { return { diff --git a/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts b/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts index 1d8b8e76b0b..1e8a48ab84e 100644 --- a/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts +++ b/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts @@ -42,6 +42,7 @@ describe('fetchDevices', () => { name: 'deviceNameValue', attributes: { attributeName: 'attributeValue', + // eslint-disable-next-line camelcase device_name: 'deviceNameValue', }, createDate: date, diff --git a/packages/auth/__tests__/providers/cognito/identityIdProvider.test.ts b/packages/auth/__tests__/providers/cognito/identityIdProvider.test.ts index a17dbb7a8b1..2b8620c680d 100644 --- a/packages/auth/__tests__/providers/cognito/identityIdProvider.test.ts +++ b/packages/auth/__tests__/providers/cognito/identityIdProvider.test.ts @@ -47,17 +47,19 @@ describe('Cognito IdentityId Provider Happy Path Cases:', () => { beforeAll(() => { jest.spyOn(Amplify, 'getConfig').mockImplementationOnce(() => ampConfig); - mockGetId.mockImplementation(async (config: {}, params: GetIdInput) => { - if (params.Logins && Object.keys(params.Logins).length === 0) { - return { - IdentityId: authAPITestParams.GuestIdentityId.id, - } as GetIdOutput; - } else { - return { - IdentityId: authAPITestParams.PrimaryIdentityId.id, - } as GetIdOutput; - } - }); + mockGetId.mockImplementation( + async (_config: object, params: GetIdInput) => { + if (params.Logins && Object.keys(params.Logins).length === 0) { + return { + IdentityId: authAPITestParams.GuestIdentityId.id, + } as GetIdOutput; + } else { + return { + IdentityId: authAPITestParams.PrimaryIdentityId.id, + } as GetIdOutput; + } + }, + ); }); afterEach(() => { diff --git a/packages/auth/__tests__/providers/cognito/refreshToken.test.ts b/packages/auth/__tests__/providers/cognito/refreshToken.test.ts index b2e77a37559..86ac80a1fee 100644 --- a/packages/auth/__tests__/providers/cognito/refreshToken.test.ts +++ b/packages/auth/__tests__/providers/cognito/refreshToken.test.ts @@ -83,7 +83,7 @@ describe('refreshToken', () => { }); it('should send UserContextData', async () => { - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -117,7 +117,7 @@ describe('refreshToken', () => { UserContextData: { EncodedData: 'abcd' }, }), ); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); }); @@ -156,8 +156,7 @@ describe('refreshToken', () => { it('should throw an exception when cognito tokens are not available', async () => { await expect( refreshAuthTokens({ - // @ts-ignore - tokens: {}, + tokens: {} as any, authConfig: { Cognito: { userPoolId: 'us-east-1_aaaaaaa', diff --git a/packages/auth/__tests__/providers/cognito/resendSignUpCode.test.ts b/packages/auth/__tests__/providers/cognito/resendSignUpCode.test.ts index 6dd5354157b..d723a69eda8 100644 --- a/packages/auth/__tests__/providers/cognito/resendSignUpCode.test.ts +++ b/packages/auth/__tests__/providers/cognito/resendSignUpCode.test.ts @@ -89,7 +89,7 @@ describe('resendSignUpCode', () => { }); it('should send UserContextData', async () => { - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -111,6 +111,6 @@ describe('resendSignUpCode', () => { }, ); expect(mockResendConfirmationCode).toHaveBeenCalledTimes(1); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); }); diff --git a/packages/auth/__tests__/providers/cognito/resetPassword.test.ts b/packages/auth/__tests__/providers/cognito/resetPassword.test.ts index 2da7cd7141f..3432ae17c0a 100644 --- a/packages/auth/__tests__/providers/cognito/resetPassword.test.ts +++ b/packages/auth/__tests__/providers/cognito/resetPassword.test.ts @@ -92,7 +92,7 @@ describe('resetPassword', () => { }); it('should send UserContextData', async () => { - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -112,6 +112,6 @@ describe('resetPassword', () => { UserContextData: { EncodedData: 'abcd' }, }), ); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); }); diff --git a/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts b/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts index f93854dc087..87828e427f8 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts @@ -32,7 +32,7 @@ Amplify.configure({ }); cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); describe('signIn API happy path cases', () => { - let handleCustomAuthFlowWithoutSRPSpy; + let handleCustomAuthFlowWithoutSRPSpy: jest.SpyInstance; afterAll(() => { jest.restoreAllMocks(); @@ -85,7 +85,7 @@ describe('signIn API happy path cases', () => { }); describe('Cognito ASF', () => { - let initiateAuthSpy; + let initiateAuthSpy: jest.SpyInstance; afterAll(() => { jest.restoreAllMocks(); @@ -105,7 +105,7 @@ describe('Cognito ASF', () => { }), ); // load Cognito ASF polyfill - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -114,11 +114,11 @@ describe('Cognito ASF', () => { afterEach(() => { initiateAuthSpy.mockClear(); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); test('signIn API should send UserContextData', async () => { - const result = await signIn({ + await signIn({ username: authAPITestParams.user1.username, options: { authFlowType: 'CUSTOM_WITHOUT_SRP', diff --git a/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts b/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts index 2ab9d833dc8..108e928d683 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts @@ -32,7 +32,7 @@ Amplify.configure({ }); describe('signIn API happy path cases', () => { - let handleCustomSRPAuthFlowSpy; + let handleCustomSRPAuthFlowSpy: jest.SpyInstance; beforeEach(() => { handleCustomSRPAuthFlowSpy = jest @@ -92,7 +92,7 @@ describe('signIn API happy path cases', () => { }); describe('Cognito ASF', () => { - let initiateAuthSpy; + let initiateAuthSpy: jest.SpyInstance; afterAll(() => { jest.restoreAllMocks(); @@ -109,7 +109,7 @@ describe('Cognito ASF', () => { }, })); // load Cognito ASF polyfill - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -118,7 +118,7 @@ describe('Cognito ASF', () => { afterEach(() => { initiateAuthSpy.mockClear(); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); test('signIn API invoked with CUSTOM_WITH_SRP should send UserContextData', async () => { diff --git a/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts b/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts index 7ed3b3df197..8f91323319f 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts @@ -33,14 +33,14 @@ jest.mock('@aws-amplify/core/internals/utils', () => ({ isBrowser: jest.fn(() => true), })); jest.mock('@aws-amplify/core', () => { - const { ADD_OAUTH_LISTENER } = jest.requireActual( + const { ADD_OAUTH_LISTENER: ACTUAL_ADD_OAUTH_LISTENER } = jest.requireActual( '@aws-amplify/core/internals/utils', ); return { Amplify: { getConfig: jest.fn(() => mockAuthConfigWithOAuth), - [ADD_OAUTH_LISTENER]: jest.fn(), + [ACTUAL_ADD_OAUTH_LISTENER]: jest.fn(), }, ConsoleLogger: jest.fn(), }; diff --git a/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts b/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts index 43b5fe49aa3..c43e773f1d7 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts @@ -256,7 +256,7 @@ describe('signIn API happy path cases', () => { }); describe('Cognito ASF', () => { - let initiateAuthSpy; + let initiateAuthSpy: jest.SpyInstance; beforeAll(() => { jest.restoreAllMocks(); @@ -273,7 +273,7 @@ describe('Cognito ASF', () => { }, })); // load Cognito ASF polyfill - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -282,7 +282,7 @@ describe('Cognito ASF', () => { afterEach(() => { initiateAuthSpy.mockClear(); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); test('signIn SRP should send UserContextData', async () => { diff --git a/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts b/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts index dc2e8daf77a..83f3a7d2813 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts @@ -33,7 +33,7 @@ Amplify.configure({ Auth: authConfig, }); describe('signIn API happy path cases', () => { - let handleUserPasswordFlowSpy; + let handleUserPasswordFlowSpy: jest.SpyInstance; beforeEach(() => { handleUserPasswordFlowSpy = jest @@ -79,7 +79,7 @@ describe('signIn API happy path cases', () => { }); describe('Cognito ASF', () => { - let initiateAuthSpy; + let initiateAuthSpy: jest.SpyInstance; afterAll(() => { jest.restoreAllMocks(); @@ -96,7 +96,7 @@ describe('Cognito ASF', () => { }, })); // load Cognito ASF polyfill - window.AmazonCognitoAdvancedSecurityData = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -105,7 +105,7 @@ describe('Cognito ASF', () => { afterEach(() => { initiateAuthSpy.mockClear(); - window.AmazonCognitoAdvancedSecurityData = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); test('signIn API should send UserContextData', async () => { diff --git a/packages/auth/__tests__/providers/cognito/signOut.test.ts b/packages/auth/__tests__/providers/cognito/signOut.test.ts index b211b273831..adae8c494cc 100644 --- a/packages/auth/__tests__/providers/cognito/signOut.test.ts +++ b/packages/auth/__tests__/providers/cognito/signOut.test.ts @@ -33,6 +33,7 @@ jest.mock('../../../src/providers/cognito/utils/signInWithRedirectStore'); jest.mock('../../../src/utils'); describe('signOut', () => { + // eslint-disable-next-line camelcase const accessToken = { payload: { origin_jti: 'revocation-id' } }; const region = 'us-west-2'; const cognitoConfig = { diff --git a/packages/auth/__tests__/providers/cognito/tokenOrchestrator.test.ts b/packages/auth/__tests__/providers/cognito/tokenOrchestrator.test.ts index 323aaa59bbd..ad15fc2a540 100644 --- a/packages/auth/__tests__/providers/cognito/tokenOrchestrator.test.ts +++ b/packages/auth/__tests__/providers/cognito/tokenOrchestrator.test.ts @@ -143,7 +143,7 @@ describe('TokenOrchestrator', () => { mockAuthTokenStore.loadTokens.mockResolvedValue(validAuthTokens); (oAuthStore.loadOAuthInFlight as jest.Mock).mockResolvedValue(true); - expect(await tokenOrchestrator.getTokens()).resolves; + await tokenOrchestrator.getTokens(); expect(addInflightPromise).toHaveBeenCalledWith(expect.any(Function)); expect(mockAddInflightPromise).toHaveBeenCalledTimes(1); diff --git a/packages/auth/__tests__/providers/cognito/tokenProvider/tokenOrchestrator.test.ts b/packages/auth/__tests__/providers/cognito/tokenProvider/tokenOrchestrator.test.ts index 5e1e944b0b5..e1c25ec86f7 100644 --- a/packages/auth/__tests__/providers/cognito/tokenProvider/tokenOrchestrator.test.ts +++ b/packages/auth/__tests__/providers/cognito/tokenProvider/tokenOrchestrator.test.ts @@ -66,8 +66,8 @@ describe('tokenOrchestrator', () => { username: testUsername, }; mockTokenRefresher.mockResolvedValueOnce(mockTokens); - mockTokenStore.storeTokens.mockResolvedValue(void 0); - const newTokens = await tokenOrchestrator.refreshTokens({ + mockTokenStore.storeTokens.mockResolvedValue(undefined); + const newTokens = await (tokenOrchestrator as any).refreshTokens({ tokens: testInputTokens, username: testUsername, }); diff --git a/packages/auth/__tests__/providers/cognito/utils/srp/AuthenticationHelper.test.ts b/packages/auth/__tests__/providers/cognito/utils/srp/AuthenticationHelper.test.ts index 0c8c9a847e5..1ed0e0d229c 100644 --- a/packages/auth/__tests__/providers/cognito/utils/srp/AuthenticationHelper.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/srp/AuthenticationHelper.test.ts @@ -82,7 +82,6 @@ describe('AuthenticationHelper', () => { describe('generateHashDevice', () => { const deviceGroupKey = 'device-group-key'; const username = 'user-name'; - const randomString = 'random-string'; // create spies const modPowSpy = jest.spyOn(BigInteger.prototype, 'modPow'); diff --git a/packages/auth/__tests__/providers/cognito/utils/srp/getAuthenticationHelper.test.ts b/packages/auth/__tests__/providers/cognito/utils/srp/getAuthenticationHelper.test.ts index 506a52f5af6..458e9856a15 100644 --- a/packages/auth/__tests__/providers/cognito/utils/srp/getAuthenticationHelper.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/srp/getAuthenticationHelper.test.ts @@ -28,8 +28,8 @@ describe('getAuthenticationHelper', () => { it('should generate with non-deterministic seeding', async () => { const arr: string[] = []; for (let i = 0; i < 20; i++) { - const helper = await getAuthenticationHelper('TestPoolName'); - arr.push(helper.a.toString(16)); + const newHelper = await getAuthenticationHelper('TestPoolName'); + arr.push(newHelper.a.toString(16)); } expect(arr.length).toBe(new Set(arr).size); }); diff --git a/packages/auth/src/providers/cognito/credentialsProvider/IdentityIdProvider.ts b/packages/auth/src/providers/cognito/credentialsProvider/IdentityIdProvider.ts index 32fbaeb1369..4a8614a3db0 100644 --- a/packages/auth/src/providers/cognito/credentialsProvider/IdentityIdProvider.ts +++ b/packages/auth/src/providers/cognito/credentialsProvider/IdentityIdProvider.ts @@ -12,13 +12,12 @@ import { IdentityIdStore } from './types'; import { formLoginsMap } from './utils'; const logger = new ConsoleLogger('CognitoIdentityIdProvider'); - /** * Provides a Cognito identityId * * @param tokens - The AuthTokens received after SignIn * @returns string - * @throws configuration exceptions: {@link InvalidIdentityPoolIdException } + * @throws configuration exceptions: `InvalidIdentityPoolIdException` * - Auth errors that may arise from misconfiguration. * @throws service exceptions: {@link GetIdException } */ diff --git a/packages/auth/src/providers/cognito/credentialsProvider/index.ts b/packages/auth/src/providers/cognito/credentialsProvider/index.ts index 389c08bcf4d..02acda4d3a3 100644 --- a/packages/auth/src/providers/cognito/credentialsProvider/index.ts +++ b/packages/auth/src/providers/cognito/credentialsProvider/index.ts @@ -15,7 +15,7 @@ import { CognitoAWSCredentialsAndIdentityIdProvider } from './credentialsProvide * Cognito specific implmentation of the CredentialsProvider interface * that manages setting and getting of AWS Credentials. * - * @throws configuration expections: {@link InvalidIdentityPoolIdException } + * @throws configuration expections: `InvalidIdentityPoolIdException` * - Auth errors that may arise from misconfiguration. * @throws service expections: {@link GetCredentialsForIdentityException}, {@link GetIdException} * diff --git a/packages/auth/src/types/inputs.ts b/packages/auth/src/types/inputs.ts index 2ea988e227d..437f5e398f4 100644 --- a/packages/auth/src/types/inputs.ts +++ b/packages/auth/src/types/inputs.ts @@ -98,10 +98,11 @@ export interface AuthConfirmSignUpInput< confirmationCode: string; options?: ServiceOptions; } + /** * Constructs a `confirmSignIn` input. * - * @param challengeResponse - required parameter for responding to {@link AuthSignInStep } returned during + * @param challengeResponse - required parameter for responding to `AuthSignInStep` returned during * the sign in process. * @param options - optional parameters for the Confirm Sign In process such as the service options */