From ff89a375e2533e2d51f14d510dcd34f7b6f1bc8c Mon Sep 17 00:00:00 2001 From: Jim Blanchard Date: Wed, 5 Jun 2024 17:02:19 -0500 Subject: [PATCH 1/7] chore: Fix broken README links (#13468) --- README.md | 1 - packages/aws-amplify/README.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index ada48b62a75..b6a74ad5339 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ Our default implementation works with Amazon Web Services (AWS), but AWS Amplify #### Visit our [documentation site](https://docs.amplify.aws/) to learn more about AWS Amplify. Please see the [Amplify JavaScript](https://docs.amplify.aws/lib/q/platform/js/) page for information around the full list of features we support. -- [Demo Applications](https://github.com/aws-amplify/amplify-js-samples) - [Contributing](https://github.com/aws-amplify/amplify-js/blob/main/CONTRIBUTING.md) ### Features diff --git a/packages/aws-amplify/README.md b/packages/aws-amplify/README.md index a024a31c2d5..818afe8d95c 100644 --- a/packages/aws-amplify/README.md +++ b/packages/aws-amplify/README.md @@ -2,4 +2,4 @@ AWS Amplify is a JavaScript library for frontend and mobile developers building cloud-enabled applications. The library is a declarative interface across different categories of operations in order to make common tasks easier to add into your application. The default implementation works with Amazon Web Services (AWS) resources but is designed to be open and pluggable for usage with other cloud services that wish to provide an implementation or custom backends. -Documentation is available [here](https://docs.amplify.aws/lib/q/platform/js/). +Documentation is available [here](https://docs.amplify.aws/javascript/). From 322cc4841954aa7ad1b58ee6d6e223ab17ec41d0 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Thu, 6 Jun 2024 13:39:34 -0700 Subject: [PATCH 2/7] chore(actions): run codeql on PRs to release (#13460) Co-authored-by: Ashwin Kumar --- .github/workflows/codeql.yml | 2 +- .github/workflows/push-integ-test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 1bbdab5239a..5b5b8865166 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -5,7 +5,7 @@ on: push: branches: ['*'] pull_request: - branches: ['main', 'next/main', 'next/release'] + branches: ['main', 'release', 'next/main', 'next/release'] schedule: # Run every Tuesday at midnight GMT - cron: '0 0 * * 2' diff --git a/.github/workflows/push-integ-test.yml b/.github/workflows/push-integ-test.yml index a56ca5db116..03e43dd2865 100644 --- a/.github/workflows/push-integ-test.yml +++ b/.github/workflows/push-integ-test.yml @@ -8,7 +8,7 @@ concurrency: on: push: branches: - - next/main + - replace-with-your-branch jobs: e2e: From abebe1fe29273c04803bcb8235736312ae72bed6 Mon Sep 17 00:00:00 2001 From: Hui Zhao <10602282+HuiSF@users.noreply.github.com> Date: Tue, 11 Jun 2024 10:20:05 -0700 Subject: [PATCH 3/7] chore(auth): enable lint on __tests__ (#13429) * chore(auth): enable lint on __tests__ * chore(auth): run yarn lint:fix * chore(auth): manual fix linter errors * Resolve comments --- .eslintrc.js | 4 +- packages/auth/__tests__/mockData.ts | 3 - .../cognito/assertServiceError.test.ts | 59 ++++++---- .../providers/cognito/autoSignIn.test.ts | 6 +- .../cognito/confirmResetPassword.test.ts | 12 +- .../cognito/confirmSignInErrorCases.test.ts | 8 +- .../cognito/confirmSignInHappyCases.test.ts | 78 ++++++------- .../providers/cognito/confirmSignUp.test.ts | 8 +- .../cognito/confirmUserAttribute.test.ts | 5 +- .../cognito/credentialsProvider.test.ts | 77 ++++++------- .../providers/cognito/deleteUser.test.ts | 4 +- .../cognito/deleteUserAttributes.test.ts | 2 + .../cognito/fetchAuthSession.test.ts | 15 ++- .../providers/cognito/fetchDevices.test.ts | 3 + .../cognito/fetchMFAPreference.test.ts | 2 + .../cognito/fetchUserAttributes.test.ts | 2 + .../providers/cognito/forgetDevice.test.ts | 2 + .../providers/cognito/getCurrentUser.test.ts | 2 + .../cognito/getNewDeviceMetadata.test.ts | 3 +- .../cognito/identityIdProvider.test.ts | 32 +++--- .../providers/cognito/identityIdStore.test.ts | 3 +- .../providers/cognito/refreshToken.test.ts | 12 +- .../providers/cognito/rememberDevice.test.ts | 2 + .../cognito/resendSignUpCode.test.ts | 8 +- .../providers/cognito/resetPassword.test.ts | 8 +- .../sendUserAttributeVerificationCode.test.ts | 4 +- .../providers/cognito/setUpTOTP.test.ts | 4 +- .../cognito/signInErrorCases.test.ts | 6 +- .../cognito/signInStateManagement.test.ts | 13 ++- .../cognito/signInWithCustomAuth.test.ts | 16 +-- .../cognito/signInWithCustomSRPAuth.test.ts | 18 +-- .../cognito/signInWithRedirect.test.ts | 26 ++--- .../providers/cognito/signInWithSRP.test.ts | 106 ++++++++++-------- .../cognito/signInWithUserPassword.test.ts | 18 +-- .../providers/cognito/signOut.test.ts | 6 +- .../providers/cognito/signUp.test.ts | 4 +- .../cognito/testUtils/authApiTestParams.ts | 1 + .../providers/cognito/testUtils/data.ts | 2 + .../cognito/tokenOrchestrator.test.ts | 32 ++---- .../providers/cognito/tokenProvider.test.ts | 6 +- .../tokenProvider/tokenOrchestrator.test.ts | 24 ++-- .../cognito/updateMFAPreference.test.ts | 5 +- .../providers/cognito/updatePassword.test.ts | 2 + .../cognito/updateUserAttribute.test.ts | 2 + .../cognito/updateUserAttributes.test.ts | 2 + .../utils/dispatchSignedInHubEvent.test.ts | 3 +- .../oauth/attemptCompleteOAuthFlow.test.ts | 7 +- .../utils/oauth/completeOAuthFlow.test.ts | 5 +- .../utils/oauth/completeOAuthSignOut.test.ts | 3 +- .../cognito/utils/oauth/index.test.ts | 3 +- .../utils/oauth/oAuthSignOutRedirect.test.ts | 2 +- .../cognito/utils/oauth/validateState.test.ts | 2 +- .../utils/srp/AuthenticationHelper.test.ts | 1 - .../utils/srp/getAuthenticationHelper.test.ts | 4 +- .../cognito/utils/srp/getHashFromHex.test.ts | 1 + .../providers/cognito/verifyTOTPSetup.test.ts | 2 + .../utils/getAuthUserAgentDetails.test.ts | 1 + .../utils/getAuthUserAgentValue.test.ts | 1 + .../credentialsProvider/IdentityIdProvider.ts | 3 +- .../cognito/credentialsProvider/index.ts | 2 +- packages/auth/src/types/inputs.ts | 3 +- 61 files changed, 387 insertions(+), 313 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9b01b93154a..955eb6c96e2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -40,7 +40,7 @@ module.exports = { 'packages/api/__tests__', 'packages/api-graphql/__tests__', // 'packages/api-rest/__tests__', - 'packages/auth/__tests__', + // 'packages/auth/__tests__', // 'packages/aws-amplify/__tests__', // 'packages/core/__tests__', 'packages/datastore/__tests__', @@ -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 873801dfec0..11d3b91ead7 100644 --- a/packages/auth/__tests__/providers/cognito/assertServiceError.test.ts +++ b/packages/auth/__tests__/providers/cognito/assertServiceError.test.ts @@ -1,39 +1,54 @@ import { AmplifyErrorCode } from '@aws-amplify/core/internals/utils'; + import { assertServiceError } from '../../../src/errors/utils/assertServiceError'; import { AuthError } from '../../../src/errors/AuthError'; import { InitiateAuthException } from '../../../src/providers/cognito/types/errors'; describe('asserts service errors', () => { test('it should throw an unknown error when error is null', () => { - try { - const error = null; - expect(assertServiceError(error)).toThrow(); - } catch (error: any) { - expect(error).toBeInstanceOf(AuthError); - expect(error.name).toBe(AmplifyErrorCode.Unknown); - } + const error = null; + expect(() => { + assertServiceError(error); + }).toThrow( + new AuthError({ + name: AmplifyErrorCode.Unknown, + message: 'An unknown error has occurred.', + underlyingError: error, + }), + ); }); + test('it should throw an unknown error when error is a TypeError', () => { - try { - const error = new TypeError('TypeError'); - expect(assertServiceError(error)).toThrow(); - } catch (error: any) { - expect(error).toBeInstanceOf(AuthError); - expect(error.name).toBe(AmplifyErrorCode.Unknown); - } + const error = new TypeError('TypeError'); + expect(() => { + assertServiceError(error); + }).toThrow( + new AuthError({ + name: AmplifyErrorCode.Unknown, + message: 'An unknown error has occurred.', + underlyingError: error, + }), + ); }); + test('it should throw an unknown error when error does not have a name', () => { - try { - const error = new Error('Error'); - expect(assertServiceError(error)).toThrow(); - } catch (error: any) { - expect(error).toBeInstanceOf(AuthError); - expect(error.name).toBe(AmplifyErrorCode.Unknown); - } + const error = new Error('Error'); + expect(() => { + assertServiceError(error); + }).toThrow( + new AuthError({ + name: AmplifyErrorCode.Unknown, + message: 'An unknown error has occurred.', + underlyingError: error, + }), + ); }); + 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/autoSignIn.test.ts b/packages/auth/__tests__/providers/cognito/autoSignIn.test.ts index 3f05bbe336a..783fc2e9699 100644 --- a/packages/auth/__tests__/providers/cognito/autoSignIn.test.ts +++ b/packages/auth/__tests__/providers/cognito/autoSignIn.test.ts @@ -1,21 +1,23 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import { Amplify } from 'aws-amplify'; + import { cognitoUserPoolsTokenProvider, signUp, } from '../../../src/providers/cognito'; import { autoSignIn } from '../../../src/providers/cognito/apis/autoSignIn'; import * as signUpClient from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; -import { authAPITestParams } from './testUtils/authApiTestParams'; import { RespondToAuthChallengeCommandOutput, SignUpCommandOutput, } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; -import { Amplify } from 'aws-amplify'; import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers'; import { AuthError } from '../../../src/errors/AuthError'; +import { authAPITestParams } from './testUtils/authApiTestParams'; + jest.mock('../../../src/providers/cognito/utils/dispatchSignedInHubEvent'); jest.mock('@aws-amplify/core/internals/utils', () => ({ ...jest.requireActual('@aws-amplify/core/internals/utils'), diff --git a/packages/auth/__tests__/providers/cognito/confirmResetPassword.test.ts b/packages/auth/__tests__/providers/cognito/confirmResetPassword.test.ts index 8b6ad268552..df8167e5030 100644 --- a/packages/auth/__tests__/providers/cognito/confirmResetPassword.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmResetPassword.test.ts @@ -2,11 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; + import { AuthError } from '../../../src/errors/AuthError'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; import { confirmResetPassword } from '../../../src/providers/cognito'; import { ConfirmForgotPasswordException } from '../../../src/providers/cognito/types/errors'; import { confirmForgotPassword } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; + import { authAPITestParams } from './testUtils/authApiTestParams'; import { getMockError } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; @@ -42,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(); }); @@ -135,7 +137,7 @@ describe('confirmResetPassword', () => { }); it('should add UserContextData', async () => { - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -162,6 +164,6 @@ describe('confirmResetPassword', () => { }, }), ); - window['AmazonCognitoAdvancedSecurityData'] = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); }); diff --git a/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts b/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts index 2f399ebc87a..0f20b1703f3 100644 --- a/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmSignInErrorCases.test.ts @@ -1,13 +1,15 @@ import { Amplify } from '@aws-amplify/core'; + import { AuthError } from '../../../src/errors/AuthError'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; -import { authAPITestParams } from './testUtils/authApiTestParams'; import { confirmSignIn } from '../../../src/providers/cognito/apis/confirmSignIn'; import { RespondToAuthChallengeException } from '../../../src/providers/cognito/types/errors'; import { respondToAuthChallenge } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; +import { signInStore } from '../../../src/providers/cognito/utils/signInStore'; + import { getMockError } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; -import { signInStore } from '../../../src/providers/cognito/utils/signInStore'; +import { authAPITestParams } from './testUtils/authApiTestParams'; jest.mock('@aws-amplify/core', () => ({ ...(jest.createMockFromModule('@aws-amplify/core') as object), @@ -21,7 +23,7 @@ jest.mock('../../../src/providers/cognito/utils/signInStore'); describe('confirmSignIn API error path cases:', () => { const challengeName = 'SELECT_MFA_TYPE'; const signInSession = '1234234232'; - const username = authAPITestParams.user1.username; + const { username } = authAPITestParams.user1; // assert mocks const mockStoreGetState = signInStore.getState as jest.Mock; const mockRespondToAuthChallenge = respondToAuthChallenge as jest.Mock; diff --git a/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts b/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts index b59a66dd017..ddeb3c368fd 100644 --- a/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; -import { authAPITestParams } from './testUtils/authApiTestParams'; + import { - signIn, confirmSignIn, getCurrentUser, + signIn, } from '../../../src/providers/cognito/'; import * as signInHelpers from '../../../src/providers/cognito/utils/signInHelpers'; import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; @@ -15,6 +15,9 @@ import { tokenOrchestrator, } from '../../../src/providers/cognito/tokenProvider'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; + jest.mock('../../../src/providers/cognito/apis/getCurrentUser'); const authConfig = { @@ -29,9 +32,8 @@ const authConfig = { const mockedGetCurrentUser = getCurrentUser as jest.Mock; describe('confirmSignIn API happy path cases', () => { - let handleChallengeNameSpy; - const username = authAPITestParams.user1.username; - const password = authAPITestParams.user1.password; + let handleChallengeNameSpy: jest.SpyInstance; + const { username, password } = authAPITestParams.user1; beforeEach(async () => { cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); @@ -273,18 +275,18 @@ 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.username; - const password = authAPITestParams.user1.password; + const { username } = authAPITestParams.user1; + const { password } = authAPITestParams.user1; beforeEach(() => { Amplify.configure({ Auth: authConfig, }); // load Cognito ASF polyfill - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -315,7 +317,7 @@ describe('Cognito ASF', () => { afterEach(() => { respondToAuthChallengeSpy.mockClear(); handleUserSRPAuthFlowSpy.mockClear(); - window['AmazonCognitoAdvancedSecurityData'] = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); afterAll(() => { @@ -412,16 +414,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 }); @@ -457,16 +457,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 }); @@ -503,16 +501,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 9e4678b246d..e6528e4b1ed 100644 --- a/packages/auth/__tests__/providers/cognito/confirmSignUp.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmSignUp.test.ts @@ -2,13 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; + import { confirmSignUp } from '../../../src/providers/cognito'; import { confirmSignUp as providerConfirmSignUp } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; -import { authAPITestParams } from './testUtils/authApiTestParams'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; import { AuthError } from '../../../src/errors/AuthError'; import { ConfirmSignUpException } from '../../../src/providers/cognito/types/errors'; import { ConfirmSignUpCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; import { getMockError } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; @@ -142,7 +144,7 @@ describe('confirmSignUp', () => { }); it('should send UserContextData', async () => { - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -169,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/confirmUserAttribute.test.ts b/packages/auth/__tests__/providers/cognito/confirmUserAttribute.test.ts index 2ba5577e503..3c7961d125a 100644 --- a/packages/auth/__tests__/providers/cognito/confirmUserAttribute.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmUserAttribute.test.ts @@ -1,14 +1,15 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { Amplify } from '@aws-amplify/core'; +import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; -import { fetchAuthSession } from '@aws-amplify/core'; + import { AuthError } from '../../../src/errors/AuthError'; import { confirmUserAttribute } from '../../../src/providers/cognito'; import { VerifyUserAttributeException } from '../../../src/providers/cognito/types/errors'; import { verifyUserAttribute } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/credentialsProvider.test.ts b/packages/auth/__tests__/providers/cognito/credentialsProvider.test.ts index b119c84ca28..3390e14a052 100644 --- a/packages/auth/__tests__/providers/cognito/credentialsProvider.test.ts +++ b/packages/auth/__tests__/providers/cognito/credentialsProvider.test.ts @@ -2,19 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 import { - CognitoAWSCredentialsAndIdentityIdProvider, - DefaultIdentityIdStore, -} from '../../../src/providers/cognito'; -import { authAPITestParams } from './testUtils/authApiTestParams'; -import { AuthError } from '../../../src/errors/AuthError'; -import { - GetCredentialsForIdentityInput, GetCredentialsForIdentityOutput, ResourcesConfig, getCredentialsForIdentity, sharedInMemoryStorage, } from '@aws-amplify/core'; +import { + CognitoAWSCredentialsAndIdentityIdProvider, + DefaultIdentityIdStore, +} from '../../../src/providers/cognito'; +import { AuthError } from '../../../src/errors/AuthError'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; + jest.mock('@aws-amplify/core', () => ({ ...jest.requireActual('@aws-amplify/core'), getCredentialsForIdentity: jest.fn(), @@ -73,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(); @@ -99,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, @@ -120,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(); }); @@ -159,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(); @@ -182,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, ); @@ -208,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, ); @@ -229,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, @@ -257,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, @@ -270,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, @@ -283,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/deleteUser.test.ts b/packages/auth/__tests__/providers/cognito/deleteUser.test.ts index 813629911b2..ec1cf3a90d9 100644 --- a/packages/auth/__tests__/providers/cognito/deleteUser.test.ts +++ b/packages/auth/__tests__/providers/cognito/deleteUser.test.ts @@ -2,13 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify, fetchAuthSession } from '@aws-amplify/core'; +import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; import { deleteUser } from '../../../src/providers/cognito'; import { tokenOrchestrator } from '../../../src/providers/cognito/tokenProvider'; import { deleteUser as providerDeleteUser } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; -import { decodeJWT } from '@aws-amplify/core/internals/utils'; import { DeleteUserException } from '../../../src/providers/cognito/types/errors'; import { signOut } from '../../../src/providers/cognito/apis/signOut'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/deleteUserAttributes.test.ts b/packages/auth/__tests__/providers/cognito/deleteUserAttributes.test.ts index 840ca287620..959592a5b87 100644 --- a/packages/auth/__tests__/providers/cognito/deleteUserAttributes.test.ts +++ b/packages/auth/__tests__/providers/cognito/deleteUserAttributes.test.ts @@ -3,10 +3,12 @@ import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; import { deleteUserAttributes } from '../../../src/providers/cognito'; import { DeleteUserAttributesException } from '../../../src/providers/cognito/types/errors'; import { deleteUserAttributes as providerDeleteUserAttributes } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts b/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts index 6980175e736..a04c6ccdce3 100644 --- a/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts +++ b/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts @@ -1,14 +1,14 @@ -import { Amplify } from '@aws-amplify/core'; -import { fetchAuthSession } from '@aws-amplify/core'; +import { Amplify, fetchAuthSession } from '@aws-amplify/core'; +import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { CognitoAWSCredentialsAndIdentityIdProvider, - cognitoUserPoolsTokenProvider, cognitoCredentialsProvider, + cognitoUserPoolsTokenProvider, } from '../../../src/providers/cognito'; -import { decodeJWT } from '@aws-amplify/core/internals/utils'; 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 + beforeAll(() => { + 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 c7b09e53d8a..1e8a48ab84e 100644 --- a/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts +++ b/packages/auth/__tests__/providers/cognito/fetchDevices.test.ts @@ -3,10 +3,12 @@ import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; import { fetchDevices } from '../../../src/providers/cognito'; import { listDevices } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { ListDevicesException } from '../../../src/providers/cognito/types/errors'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; @@ -40,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/fetchMFAPreference.test.ts b/packages/auth/__tests__/providers/cognito/fetchMFAPreference.test.ts index e52de635585..ed2517a358e 100644 --- a/packages/auth/__tests__/providers/cognito/fetchMFAPreference.test.ts +++ b/packages/auth/__tests__/providers/cognito/fetchMFAPreference.test.ts @@ -3,10 +3,12 @@ import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { getUser } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { AuthError } from '../../../src/errors/AuthError'; import { fetchMFAPreference } from '../../../src/providers/cognito/apis/fetchMFAPreference'; import { GetUserException } from '../../../src/providers/cognito/types/errors'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/fetchUserAttributes.test.ts b/packages/auth/__tests__/providers/cognito/fetchUserAttributes.test.ts index e53a749c843..cff5ff01b64 100644 --- a/packages/auth/__tests__/providers/cognito/fetchUserAttributes.test.ts +++ b/packages/auth/__tests__/providers/cognito/fetchUserAttributes.test.ts @@ -3,10 +3,12 @@ import { Amplify } from '@aws-amplify/core'; import { decodeJWT, fetchAuthSession } from '@aws-amplify/core/internals/utils'; + import { getUser } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { AuthError } from '../../../src/errors/AuthError'; import { GetUserException } from '../../../src/providers/cognito/types/errors'; import { fetchUserAttributes } from '../../../src/providers/cognito/apis/fetchUserAttributes'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/forgetDevice.test.ts b/packages/auth/__tests__/providers/cognito/forgetDevice.test.ts index f62f1eb39ab..6371e2b41a8 100644 --- a/packages/auth/__tests__/providers/cognito/forgetDevice.test.ts +++ b/packages/auth/__tests__/providers/cognito/forgetDevice.test.ts @@ -3,12 +3,14 @@ import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; import { DEVICE_METADATA_NOT_FOUND_EXCEPTION } from '../../../src/errors/constants'; import { forgetDevice } from '../../../src/providers/cognito'; import { ForgetDeviceException } from '../../../src/providers/cognito/types/errors'; import { forgetDevice as providerForgetDevice } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { tokenOrchestrator } from '../../../src/providers/cognito/tokenProvider'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/getCurrentUser.test.ts b/packages/auth/__tests__/providers/cognito/getCurrentUser.test.ts index d7ee5c9d31e..1860c2dccd2 100644 --- a/packages/auth/__tests__/providers/cognito/getCurrentUser.test.ts +++ b/packages/auth/__tests__/providers/cognito/getCurrentUser.test.ts @@ -3,9 +3,11 @@ import { Amplify } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; import { getCurrentUser } from '../../../src/providers/cognito'; import { USER_UNAUTHENTICATED_EXCEPTION } from '../../../src/errors/constants'; + import { mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/getNewDeviceMetadata.test.ts b/packages/auth/__tests__/providers/cognito/getNewDeviceMetadata.test.ts index d275e8cec2f..cb600ce133e 100644 --- a/packages/auth/__tests__/providers/cognito/getNewDeviceMetadata.test.ts +++ b/packages/auth/__tests__/providers/cognito/getNewDeviceMetadata.test.ts @@ -1,11 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import { Amplify } from '@aws-amplify/core'; + import { AuthError } from '../../../src/errors/AuthError'; import { ConfirmDeviceException } from '../../../src/providers/cognito/types/errors'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { ConfirmDeviceCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; -import { Amplify } from '@aws-amplify/core'; import { getNewDeviceMetatada } from '../../../src/providers/cognito/utils/signInHelpers'; const userPoolId = 'us-west-2_zzzzz'; diff --git a/packages/auth/__tests__/providers/cognito/identityIdProvider.test.ts b/packages/auth/__tests__/providers/cognito/identityIdProvider.test.ts index 5468e631187..2b8620c680d 100644 --- a/packages/auth/__tests__/providers/cognito/identityIdProvider.test.ts +++ b/packages/auth/__tests__/providers/cognito/identityIdProvider.test.ts @@ -1,16 +1,18 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { authAPITestParams } from './testUtils/authApiTestParams'; import { Amplify, Identity, ResourcesConfig, getId } from '@aws-amplify/core'; -import { DefaultIdentityIdStore } from '../../../src/providers/cognito/credentialsProvider/IdentityIdStore'; import { GetIdInput, GetIdOutput, } from '@aws-amplify/core/internals/aws-clients/cognitoIdentity'; -import { cognitoIdentityIdProvider } from '../../../src/providers/cognito/credentialsProvider/IdentityIdProvider'; import { CognitoIdentityPoolConfig } from '@aws-amplify/core/internals/utils'; +import { DefaultIdentityIdStore } from '../../../src/providers/cognito/credentialsProvider/IdentityIdStore'; +import { cognitoIdentityIdProvider } from '../../../src/providers/cognito/credentialsProvider/IdentityIdProvider'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; + jest.mock('@aws-amplify/core', () => ({ ...jest.requireActual('@aws-amplify/core'), getId: jest.fn(), @@ -45,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/identityIdStore.test.ts b/packages/auth/__tests__/providers/cognito/identityIdStore.test.ts index f73e4a20c69..8eeb1fef5e3 100644 --- a/packages/auth/__tests__/providers/cognito/identityIdStore.test.ts +++ b/packages/auth/__tests__/providers/cognito/identityIdStore.test.ts @@ -1,9 +1,10 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { DefaultIdentityIdStore } from '../../../src/providers/cognito'; import { Identity, ResourcesConfig } from '@aws-amplify/core'; +import { DefaultIdentityIdStore } from '../../../src/providers/cognito'; + const mockKeyValueStorage = { setItem: jest.fn(), getItem: jest.fn(), diff --git a/packages/auth/__tests__/providers/cognito/refreshToken.test.ts b/packages/auth/__tests__/providers/cognito/refreshToken.test.ts index 0f17c07da3d..86ac80a1fee 100644 --- a/packages/auth/__tests__/providers/cognito/refreshToken.test.ts +++ b/packages/auth/__tests__/providers/cognito/refreshToken.test.ts @@ -1,12 +1,15 @@ import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { refreshAuthTokens } from '../../../src/providers/cognito/utils/refreshAuthTokens'; import { CognitoAuthTokens } from '../../../src/providers/cognito/tokenProvider/types'; import { initiateAuth } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; -import { mockAccessToken, mockRequestId } from './testUtils/data'; import { oAuthTokenRefreshException, tokenRefreshException, } from '../../../src/providers/cognito/utils/types'; + +import { mockAccessToken, mockRequestId } from './testUtils/data'; + jest.mock( '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider', ); @@ -80,7 +83,7 @@ describe('refreshToken', () => { }); it('should send UserContextData', async () => { - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -114,7 +117,7 @@ describe('refreshToken', () => { UserContextData: { EncodedData: 'abcd' }, }), ); - window['AmazonCognitoAdvancedSecurityData'] = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); }); @@ -153,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/rememberDevice.test.ts b/packages/auth/__tests__/providers/cognito/rememberDevice.test.ts index f8d228d27cf..820b2a1ef5f 100644 --- a/packages/auth/__tests__/providers/cognito/rememberDevice.test.ts +++ b/packages/auth/__tests__/providers/cognito/rememberDevice.test.ts @@ -3,12 +3,14 @@ import { decodeJWT } from '@aws-amplify/core/internals/utils'; import { Amplify, fetchAuthSession } from '@aws-amplify/core'; + import { AuthError } from '../../../src/errors/AuthError'; import { rememberDevice } from '../../../src/providers/cognito'; import { UpdateDeviceStatusException } from '../../../src/providers/cognito/types/errors'; import { updateDeviceStatus } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { tokenOrchestrator } from '../../../src/providers/cognito/tokenProvider'; import { DeviceMetadata } from '../../../src/providers/cognito/tokenProvider/types'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/resendSignUpCode.test.ts b/packages/auth/__tests__/providers/cognito/resendSignUpCode.test.ts index f1c7fcd96bb..d723a69eda8 100644 --- a/packages/auth/__tests__/providers/cognito/resendSignUpCode.test.ts +++ b/packages/auth/__tests__/providers/cognito/resendSignUpCode.test.ts @@ -2,12 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; + import { resendSignUpCode } from '../../../src/providers/cognito'; -import { authAPITestParams } from './testUtils/authApiTestParams'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; import { AuthError } from '../../../src/errors/AuthError'; import { ResendConfirmationException } from '../../../src/providers/cognito/types/errors'; import { resendConfirmationCode } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; import { getMockError } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; @@ -87,7 +89,7 @@ describe('resendSignUpCode', () => { }); it('should send UserContextData', async () => { - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -109,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 2def52d2b1a..3432ae17c0a 100644 --- a/packages/auth/__tests__/providers/cognito/resetPassword.test.ts +++ b/packages/auth/__tests__/providers/cognito/resetPassword.test.ts @@ -1,12 +1,14 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; + import { AuthError } from '../../../src/errors/AuthError'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; import { resetPassword } from '../../../src/providers/cognito'; import { ForgotPasswordException } from '../../../src/providers/cognito/types/errors'; -import { authAPITestParams } from './testUtils/authApiTestParams'; import { forgotPassword } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; import { getMockError } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; @@ -90,7 +92,7 @@ describe('resetPassword', () => { }); it('should send UserContextData', async () => { - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -110,6 +112,6 @@ describe('resetPassword', () => { UserContextData: { EncodedData: 'abcd' }, }), ); - window['AmazonCognitoAdvancedSecurityData'] = undefined; + (window as any).AmazonCognitoAdvancedSecurityData = undefined; }); }); diff --git a/packages/auth/__tests__/providers/cognito/sendUserAttributeVerificationCode.test.ts b/packages/auth/__tests__/providers/cognito/sendUserAttributeVerificationCode.test.ts index 992afa5d606..2b236d1db5a 100644 --- a/packages/auth/__tests__/providers/cognito/sendUserAttributeVerificationCode.test.ts +++ b/packages/auth/__tests__/providers/cognito/sendUserAttributeVerificationCode.test.ts @@ -3,11 +3,13 @@ import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; -import { authAPITestParams } from './testUtils/authApiTestParams'; import { sendUserAttributeVerificationCode } from '../../../src/providers/cognito'; import { GetUserAttributeVerificationException } from '../../../src/providers/cognito/types/errors'; import { getUserAttributeVerificationCode } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/setUpTOTP.test.ts b/packages/auth/__tests__/providers/cognito/setUpTOTP.test.ts index 06d350e1930..1f7399093cc 100644 --- a/packages/auth/__tests__/providers/cognito/setUpTOTP.test.ts +++ b/packages/auth/__tests__/providers/cognito/setUpTOTP.test.ts @@ -2,11 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify, fetchAuthSession } from '@aws-amplify/core'; +import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; import { AssociateSoftwareTokenException } from '../../../src/providers/cognito/types/errors'; import { associateSoftwareToken } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { setUpTOTP } from '../../../src/providers/cognito'; -import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/signInErrorCases.test.ts b/packages/auth/__tests__/providers/cognito/signInErrorCases.test.ts index f406f53e195..b4e8453b17d 100644 --- a/packages/auth/__tests__/providers/cognito/signInErrorCases.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInErrorCases.test.ts @@ -2,13 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; + import { AuthError } from '../../../src/errors/AuthError'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; -import { authAPITestParams } from './testUtils/authApiTestParams'; -import { signIn, getCurrentUser } from '../../../src/providers/cognito'; +import { getCurrentUser, signIn } from '../../../src/providers/cognito'; import { initiateAuth } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { InitiateAuthException } from '../../../src/providers/cognito/types/errors'; import { USER_ALREADY_AUTHENTICATED_EXCEPTION } from '../../../src/errors/constants'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; import { getMockError } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts b/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts index 5728b39c55b..dcefb80a121 100644 --- a/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts @@ -1,13 +1,16 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { authAPITestParams } from './testUtils/authApiTestParams'; -import { signIn, getCurrentUser } from '../../../src/providers/cognito'; +import { Amplify } from '@aws-amplify/core'; + +import { getCurrentUser, signIn } from '../../../src/providers/cognito'; import * as signInHelpers from '../../../src/providers/cognito/utils/signInHelpers'; import { signInStore } from '../../../src/providers/cognito/utils/signInStore'; -import { Amplify } from '@aws-amplify/core'; import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; import { cognitoUserPoolsTokenProvider } from '../../../src/providers/cognito/tokenProvider'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; + jest.mock('../../../src/providers/cognito/apis/getCurrentUser'); // getCurrentUser is mocked so Hub is able to dispatch a mocked AuthUser @@ -16,8 +19,8 @@ const mockedGetCurrentUser = getCurrentUser as jest.Mock; describe('local sign-in state management tests', () => { const session = '1234234232'; const challengeName = 'SMS_MFA'; - const username = authAPITestParams.user1.username; - const password = authAPITestParams.user1.password; + const { username } = authAPITestParams.user1; + const { password } = authAPITestParams.user1; const authConfig = { Cognito: { userPoolClientId: '111111-aaaaa-42d8-891d-ee81a1549398', diff --git a/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts b/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts index b2c15cc389a..87828e427f8 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from 'aws-amplify'; -import { authAPITestParams } from './testUtils/authApiTestParams'; + import { signIn } from '../../../src/providers/cognito'; import { signInWithCustomAuth } from '../../../src/providers/cognito/apis/signInWithCustomAuth'; import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers'; @@ -13,6 +13,8 @@ import { } from '../../../src/providers/cognito/tokenProvider'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; +import { authAPITestParams } from './testUtils/authApiTestParams'; + jest.mock('@aws-amplify/core/internals/utils', () => ({ ...jest.requireActual('@aws-amplify/core/internals/utils'), isBrowser: jest.fn(() => false), @@ -30,7 +32,7 @@ Amplify.configure({ }); cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); describe('signIn API happy path cases', () => { - let handleCustomAuthFlowWithoutSRPSpy; + let handleCustomAuthFlowWithoutSRPSpy: jest.SpyInstance; afterAll(() => { jest.restoreAllMocks(); @@ -67,7 +69,7 @@ describe('signIn API happy path cases', () => { expect(handleCustomAuthFlowWithoutSRPSpy).toHaveBeenCalledTimes(1); }); test('handleCustomAuthFlowWithoutSRP should be called with clientMetada from request', async () => { - const username = authAPITestParams.user1.username; + const { username } = authAPITestParams.user1; await signInWithCustomAuth({ username, @@ -83,7 +85,7 @@ describe('signIn API happy path cases', () => { }); describe('Cognito ASF', () => { - let initiateAuthSpy; + let initiateAuthSpy: jest.SpyInstance; afterAll(() => { jest.restoreAllMocks(); @@ -103,7 +105,7 @@ describe('Cognito ASF', () => { }), ); // load Cognito ASF polyfill - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -112,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 84a09260ee8..108e928d683 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts @@ -1,18 +1,20 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { authAPITestParams } from './testUtils/authApiTestParams'; +import { Amplify } from 'aws-amplify'; + import { signIn } from '../../../src/providers/cognito'; import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers'; import { signInWithCustomSRPAuth } from '../../../src/providers/cognito/apis/signInWithCustomSRPAuth'; import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; -import { Amplify } from 'aws-amplify'; import { cognitoUserPoolsTokenProvider, tokenOrchestrator, } from '../../../src/providers/cognito/tokenProvider'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; +import { authAPITestParams } from './testUtils/authApiTestParams'; + jest.mock('@aws-amplify/core/internals/utils', () => ({ ...jest.requireActual('@aws-amplify/core/internals/utils'), isBrowser: jest.fn(() => false), @@ -30,7 +32,7 @@ Amplify.configure({ }); describe('signIn API happy path cases', () => { - let handleCustomSRPAuthFlowSpy; + let handleCustomSRPAuthFlowSpy: jest.SpyInstance; beforeEach(() => { handleCustomSRPAuthFlowSpy = jest @@ -72,8 +74,8 @@ describe('signIn API happy path cases', () => { }); test('handleCustomSRPAuthFlow should be called with clientMetada from request', async () => { - const username = authAPITestParams.user1.username; - const password = authAPITestParams.user1.password; + const { username } = authAPITestParams.user1; + const { password } = authAPITestParams.user1; await signInWithCustomSRPAuth({ username, password, @@ -90,7 +92,7 @@ describe('signIn API happy path cases', () => { }); describe('Cognito ASF', () => { - let initiateAuthSpy; + let initiateAuthSpy: jest.SpyInstance; afterAll(() => { jest.restoreAllMocks(); @@ -107,7 +109,7 @@ describe('Cognito ASF', () => { }, })); // load Cognito ASF polyfill - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -116,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 26fff83b1ea..8f91323319f 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithRedirect.test.ts @@ -3,28 +3,25 @@ import { Amplify } from '@aws-amplify/core'; import { + ADD_OAUTH_LISTENER, assertOAuthConfig, assertTokenProviderConfig, - urlSafeEncode, isBrowser, - ADD_OAUTH_LISTENER, + urlSafeEncode, } from '@aws-amplify/core/internals/utils'; + import { assertUserNotAuthenticated } from '../../../src/providers/cognito/utils/signInHelpers'; import { + completeOAuthFlow, generateCodeVerifier, generateState, -} from '../../../src/providers/cognito/utils/oauth'; -import { getAuthUserAgentValue, openAuthSession } from '../../../src/utils'; -import { handleFailure, oAuthStore, - completeOAuthFlow, } from '../../../src/providers/cognito/utils/oauth'; +import { getAuthUserAgentValue, openAuthSession } from '../../../src/utils'; import { attemptCompleteOAuthFlow } from '../../../src/providers/cognito/utils/oauth/attemptCompleteOAuthFlow'; import { createOAuthError } from '../../../src/providers/cognito/utils/oauth/createOAuthError'; - import { signInWithRedirect } from '../../../src/providers/cognito/apis/signInWithRedirect'; - import type { OAuthStore } from '../../../src/providers/cognito/utils/types'; import { mockAuthConfigWithOAuth } from '../../mockData'; @@ -36,13 +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(), }; @@ -192,7 +190,7 @@ describe('signInWithRedirect', () => { }); it('invokes handleFailure when user cancels the oauth flow', async () => { - const error = new Error('OAuth flow was cancelled.') + const error = new Error('OAuth flow was cancelled.'); const mockOpenAuthSessionResult = { type: undefined, }; @@ -207,9 +205,9 @@ describe('signInWithRedirect', () => { await signInWithRedirect({ provider: 'Google' }); expect(mockCreateOAuthError).toHaveBeenCalledTimes(1); expect(mockHandleFailure).toHaveBeenCalledWith(error); - + window.addEventListener = currentAddEventlistener; - }) + }); }); describe('specifications on react-native', () => { @@ -297,7 +295,6 @@ describe('signInWithRedirect', () => { expect(oAuthStore.storeOAuthInFlight).toHaveBeenCalledTimes(0); }); - }); describe('errors', () => { @@ -327,6 +324,5 @@ describe('signInWithRedirect', () => { await expect(signInWithRedirect()).rejects.toThrow(mockError); }); - }); }); diff --git a/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts b/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts index 628ea1cb3eb..c43e773f1d7 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts @@ -1,12 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { authAPITestParams } from './testUtils/authApiTestParams'; +import { Amplify } from 'aws-amplify'; + import { signIn } from '../../../src/providers/cognito'; import { signInWithSRP } from '../../../src/providers/cognito/apis/signInWithSRP'; import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers'; import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; -import { Amplify } from 'aws-amplify'; import { cognitoUserPoolsTokenProvider, tokenOrchestrator, @@ -14,6 +14,9 @@ import { import { AuthError } from '../../../src'; import { createKeysForAuthStorage } from '../../../src/providers/cognito/tokenProvider/TokenStore'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; + jest.mock('../../../src/providers/cognito/utils/dispatchSignedInHubEvent'); jest.mock('../../../src/providers/cognito/utils/srp', () => { @@ -24,8 +27,8 @@ jest.mock('../../../src/providers/cognito/utils/srp', () => { getPasswordAuthenticationKey: jest.fn(), })), getSignatureString: jest.fn(), - } -}) + }; +}); jest.mock('@aws-amplify/core/internals/utils', () => ({ ...jest.requireActual('@aws-amplify/core/internals/utils'), isBrowser: jest.fn(() => false), @@ -71,26 +74,27 @@ function deleteDeviceKey(key: DeviceKey) { switch (key) { case 'deviceKey': localStorage.removeItem(authKeys.deviceKey); - break + break; case 'deviceGroupKey': localStorage.removeItem(authKeys.deviceGroupKey); - break + break; case 'randomPasswordKey': localStorage.removeItem(authKeys.randomPasswordKey); - break + break; } } describe('signIn API happy path cases', () => { - let handleUserSRPAuthflowSpy = jest - .spyOn(initiateAuthHelpers, 'handleUserSRPAuthFlow') + const handleUserSRPAuthflowSpy = jest.spyOn( + initiateAuthHelpers, + 'handleUserSRPAuthFlow', + ); beforeEach(() => { - handleUserSRPAuthflowSpy - .mockImplementation( - async (): Promise => - authAPITestParams.RespondToAuthChallengeCommandOutput, - ); + handleUserSRPAuthflowSpy.mockImplementation( + async (): Promise => + authAPITestParams.RespondToAuthChallengeCommandOutput, + ); }); afterEach(() => { @@ -172,8 +176,8 @@ describe('signIn API happy path cases', () => { }); test('handleUserSRPFlow should be called with clientMetada from request', async () => { - const username = authAPITestParams.user1.username; - const password = authAPITestParams.user1.password; + const { username } = authAPITestParams.user1; + const { password } = authAPITestParams.user1; await signInWithSRP({ username, password, @@ -189,10 +193,11 @@ describe('signIn API happy path cases', () => { }); describe('sign in with device keys', () => { - const initiateAuthSpy = jest - .spyOn(clients, 'initiateAuth') - const respondToAuthChallengeAuthSpy = jest - .spyOn(clients, 'respondToAuthChallenge') + const initiateAuthSpy = jest.spyOn(clients, 'initiateAuth'); + const respondToAuthChallengeAuthSpy = jest.spyOn( + clients, + 'respondToAuthChallenge', + ); beforeEach(() => { setDeviceKeys(); handleUserSRPAuthflowSpy.mockRestore(); @@ -202,47 +207,56 @@ describe('signIn API happy path cases', () => { $metadata: {}, ChallengeParameters: { USER_ID_FOR_SRP: lastAuthUser, - } + }, }); - respondToAuthChallengeAuthSpy.mockResolvedValueOnce(authAPITestParams.RespondToAuthChallengeCommandOutput); - }) + respondToAuthChallengeAuthSpy.mockResolvedValueOnce( + authAPITestParams.RespondToAuthChallengeCommandOutput, + ); + }); afterEach(() => { initiateAuthSpy.mockClear(); respondToAuthChallengeAuthSpy.mockClear(); - }) + }); test('respondToAuthChallenge should include device key in the request', async () => { - - await signIn({ - username: lastAuthUser, - password: 'XXXXXXXX', - }); - - expect(respondToAuthChallengeAuthSpy).toHaveBeenCalledTimes(1); - const deviceKeyFromRequest = respondToAuthChallengeAuthSpy.mock.calls[0][1].ChallengeResponses?.DEVICE_KEY - expect(deviceKeyFromRequest).toBe('mockedKey') - - }) - const deviceKeys: DeviceKey[] = ['deviceKey', 'deviceGroupKey', 'randomPasswordKey'] - test.each(deviceKeys)('respondToAuthChallenge should not include device key in the request if any device key in storage is deleted', async deviceKey => { - deleteDeviceKey(deviceKey); await signIn({ username: lastAuthUser, password: 'XXXXXXXX', }); expect(respondToAuthChallengeAuthSpy).toHaveBeenCalledTimes(1); - const deviceKeyFromRequest = respondToAuthChallengeAuthSpy.mock.calls[0][1].ChallengeResponses?.DEVICE_KEY - expect(deviceKeyFromRequest).toBe(undefined) - - }) - }) + const deviceKeyFromRequest = + respondToAuthChallengeAuthSpy.mock.calls[0][1].ChallengeResponses + ?.DEVICE_KEY; + expect(deviceKeyFromRequest).toBe('mockedKey'); + }); + const deviceKeys: DeviceKey[] = [ + 'deviceKey', + 'deviceGroupKey', + 'randomPasswordKey', + ]; + test.each(deviceKeys)( + 'respondToAuthChallenge should not include device key in the request if any device key in storage is deleted', + async deviceKey => { + deleteDeviceKey(deviceKey); + await signIn({ + username: lastAuthUser, + password: 'XXXXXXXX', + }); + expect(respondToAuthChallengeAuthSpy).toHaveBeenCalledTimes(1); + const deviceKeyFromRequest = + respondToAuthChallengeAuthSpy.mock.calls[0][1].ChallengeResponses + ?.DEVICE_KEY; + expect(deviceKeyFromRequest).toBe(undefined); + }, + ); + }); }); describe('Cognito ASF', () => { - let initiateAuthSpy; + let initiateAuthSpy: jest.SpyInstance; beforeAll(() => { jest.restoreAllMocks(); @@ -259,7 +273,7 @@ describe('Cognito ASF', () => { }, })); // load Cognito ASF polyfill - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -268,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 494fded4f80..83f3a7d2813 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts @@ -1,18 +1,20 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { authAPITestParams } from './testUtils/authApiTestParams'; +import { Amplify } from 'aws-amplify'; + import { signIn } from '../../../src/providers/cognito'; import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers'; import { signInWithUserPassword } from '../../../src/providers/cognito/apis/signInWithUserPassword'; import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; -import { Amplify } from 'aws-amplify'; import { cognitoUserPoolsTokenProvider, tokenOrchestrator, } from '../../../src/providers/cognito/tokenProvider'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; +import { authAPITestParams } from './testUtils/authApiTestParams'; + jest.mock('../../../src/providers/cognito/utils/dispatchSignedInHubEvent'); jest.mock('@aws-amplify/core/internals/utils', () => ({ ...jest.requireActual('@aws-amplify/core/internals/utils'), @@ -31,7 +33,7 @@ Amplify.configure({ Auth: authConfig, }); describe('signIn API happy path cases', () => { - let handleUserPasswordFlowSpy; + let handleUserPasswordFlowSpy: jest.SpyInstance; beforeEach(() => { handleUserPasswordFlowSpy = jest @@ -59,8 +61,8 @@ describe('signIn API happy path cases', () => { }); test('handleUserPasswordAuthFlow should be called with clientMetada from request', async () => { - const username = authAPITestParams.user1.username; - const password = authAPITestParams.user1.password; + const { username } = authAPITestParams.user1; + const { password } = authAPITestParams.user1; await signInWithUserPassword({ username, password, @@ -77,7 +79,7 @@ describe('signIn API happy path cases', () => { }); describe('Cognito ASF', () => { - let initiateAuthSpy; + let initiateAuthSpy: jest.SpyInstance; afterAll(() => { jest.restoreAllMocks(); @@ -94,7 +96,7 @@ describe('Cognito ASF', () => { }, })); // load Cognito ASF polyfill - window['AmazonCognitoAdvancedSecurityData'] = { + (window as any).AmazonCognitoAdvancedSecurityData = { getData() { return 'abcd'; }, @@ -103,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 6a6f27106b7..adae8c494cc 100644 --- a/packages/auth/__tests__/providers/cognito/signOut.test.ts +++ b/packages/auth/__tests__/providers/cognito/signOut.test.ts @@ -3,11 +3,12 @@ import { Amplify, - clearCredentials, ConsoleLogger, Hub, + clearCredentials, } from '@aws-amplify/core'; import { AMPLIFY_SYMBOL } from '@aws-amplify/core/internals/utils'; + import { signOut } from '../../../src/providers/cognito/apis/signOut'; import { tokenOrchestrator } from '../../../src/providers/cognito/tokenProvider'; import { @@ -32,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 = { @@ -190,7 +192,7 @@ describe('signOut', () => { domain: 'hosted-ui.test', redirectSignIn: ['https://myapp.test/completeSignIn/'], redirectSignOut: ['https://myapp.test/completeSignOut/'], - responseType: 'code' as 'code', // assert string union instead of string type + responseType: 'code' as const, // assert string union instead of string type scopes: [], }, }, diff --git a/packages/auth/__tests__/providers/cognito/signUp.test.ts b/packages/auth/__tests__/providers/cognito/signUp.test.ts index afcdfccb580..6777fc2894b 100644 --- a/packages/auth/__tests__/providers/cognito/signUp.test.ts +++ b/packages/auth/__tests__/providers/cognito/signUp.test.ts @@ -2,12 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify } from '@aws-amplify/core'; + import { signUp } from '../../../src/providers/cognito'; import { signUp as providerSignUp } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; -import { authAPITestParams } from './testUtils/authApiTestParams'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; import { AuthError } from '../../../src/errors/AuthError'; import { SignUpException } from '../../../src/providers/cognito/types/errors'; + +import { authAPITestParams } from './testUtils/authApiTestParams'; import { getMockError } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/testUtils/authApiTestParams.ts b/packages/auth/__tests__/providers/cognito/testUtils/authApiTestParams.ts index aaf11d8ee08..9d5cde07f27 100644 --- a/packages/auth/__tests__/providers/cognito/testUtils/authApiTestParams.ts +++ b/packages/auth/__tests__/providers/cognito/testUtils/authApiTestParams.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthSignInOutput } from '../../../../src/types'; export const authAPITestParams = { diff --git a/packages/auth/__tests__/providers/cognito/testUtils/data.ts b/packages/auth/__tests__/providers/cognito/testUtils/data.ts index 63b5d2a51bb..69c22983ab0 100644 --- a/packages/auth/__tests__/providers/cognito/testUtils/data.ts +++ b/packages/auth/__tests__/providers/cognito/testUtils/data.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { HttpResponse } from '@aws-amplify/core/src/clients/types'; + import { AuthError } from '../../../../src/errors/AuthError'; // Common @@ -26,6 +27,7 @@ export const mockJsonResponse = ({ blob: async () => fail('blob() should not be called'), text: async () => fail('text() should not be called'), } as HttpResponse['body']; + return { statusCode: status, headers, diff --git a/packages/auth/__tests__/providers/cognito/tokenOrchestrator.test.ts b/packages/auth/__tests__/providers/cognito/tokenOrchestrator.test.ts index 7397ba1e826..5a31dbf0c74 100644 --- a/packages/auth/__tests__/providers/cognito/tokenOrchestrator.test.ts +++ b/packages/auth/__tests__/providers/cognito/tokenOrchestrator.test.ts @@ -1,9 +1,10 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { TokenOrchestrator } from '../../../src/providers/cognito/tokenProvider'; import { Hub, ResourcesConfig } from '@aws-amplify/core'; import { AMPLIFY_SYMBOL } from '@aws-amplify/core/internals/utils'; + +import { TokenOrchestrator } from '../../../src/providers/cognito/tokenProvider'; import { addInflightPromise } from '../../../src/providers/cognito/utils/oauth/inflightPromise'; import { oAuthStore } from '../../../src/providers/cognito/utils/oauth'; @@ -37,13 +38,9 @@ const validAuthConfig: ResourcesConfig = { }, }; -jest.mock( - '../../../src/providers/cognito/utils/oauth/inflightPromise', - () => ({ - addInflightPromise: jest.fn(), - }), -); - +jest.mock('../../../src/providers/cognito/utils/oauth/inflightPromise', () => ({ + addInflightPromise: jest.fn(), +})); const currentDate = new Date(); @@ -107,9 +104,9 @@ describe('TokenOrchestrator', () => { const tokenOrchestrator = new TokenOrchestrator(); describe('Happy Path Cases:', () => { beforeAll(() => { - mockAddInflightPromise.mockImplementation((resolver) => { + mockAddInflightPromise.mockImplementation(resolver => { resolver(); - }) + }); tokenOrchestrator.setAuthConfig(validAuthConfig.Auth!); tokenOrchestrator.setAuthTokenStore(mockAuthTokenStore); tokenOrchestrator.setTokenRefresher(mockTokenRefresher); @@ -143,20 +140,13 @@ describe('TokenOrchestrator', () => { }); it('Should call addInflightPromise when OAuth is inflight', async () => { - mockAuthTokenStore.loadTokens.mockResolvedValue(validAuthTokens); + mockAuthTokenStore.loadTokens.mockResolvedValue(validAuthTokens); (oAuthStore.loadOAuthInFlight as jest.Mock).mockResolvedValue(true); - - expect(await tokenOrchestrator.getTokens()).resolves; - - expect(addInflightPromise).toHaveBeenCalledWith(expect.any(Function)); - expect(mockAddInflightPromise).toHaveBeenCalledTimes(1); - - const inflightPromiseResolver = mockAddInflightPromise.mock.calls[0][0]; - inflightPromiseResolver(); - const tokens = await tokenOrchestrator.getTokens(); + + expect(addInflightPromise).toHaveBeenCalledWith(expect.any(Function)); expect(tokens?.accessToken).toEqual(validAuthTokens.accessToken); - }) + }); }); }); diff --git a/packages/auth/__tests__/providers/cognito/tokenProvider.test.ts b/packages/auth/__tests__/providers/cognito/tokenProvider.test.ts index 73ad533a2aa..d12fddb9b0d 100644 --- a/packages/auth/__tests__/providers/cognito/tokenProvider.test.ts +++ b/packages/auth/__tests__/providers/cognito/tokenProvider.test.ts @@ -1,18 +1,22 @@ import { KeyValueStorageInterface } from '@aws-amplify/core'; -import { DefaultTokenStore } from '../../../src/providers/cognito'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; +import { DefaultTokenStore } from '../../../src/providers/cognito'; + class MemoryStorage implements KeyValueStorageInterface { store: Record = {}; async setItem(key: string, value: string): Promise { this.store[key] = value; } + async getItem(key: string): Promise { return this.store[key]; } + async removeItem(key: string): Promise { delete this.store[key]; } + async clear(): Promise { this.store = {}; } diff --git a/packages/auth/__tests__/providers/cognito/tokenProvider/tokenOrchestrator.test.ts b/packages/auth/__tests__/providers/cognito/tokenProvider/tokenOrchestrator.test.ts index 5959b16109a..e1c25ec86f7 100644 --- a/packages/auth/__tests__/providers/cognito/tokenProvider/tokenOrchestrator.test.ts +++ b/packages/auth/__tests__/providers/cognito/tokenProvider/tokenOrchestrator.test.ts @@ -33,19 +33,21 @@ describe('tokenOrchestrator', () => { }); beforeEach(() => { - (oAuthStore.loadOAuthInFlight as jest.Mock).mockResolvedValue(Promise.resolve(false)); - }) + (oAuthStore.loadOAuthInFlight as jest.Mock).mockResolvedValue( + Promise.resolve(false), + ); + }); afterEach(() => { (oAuthStore.loadOAuthInFlight as jest.Mock).mockClear(); - }) + }); describe('refreshTokens method', () => { it('calls the set tokenRefresher, tokenStore and Hub while refreshing tokens', async () => { const testUsername = 'username'; - const testSignInDetails= { - authFlowType:'CUSTOM_WITHOUT_SRP', - loginId: testUsername + const testSignInDetails = { + authFlowType: 'CUSTOM_WITHOUT_SRP', + loginId: testUsername, } as const; const testInputTokens = { accessToken: { @@ -53,7 +55,7 @@ describe('tokenOrchestrator', () => { }, clockDrift: 400000, username: testUsername, - signInDetails:testSignInDetails + signInDetails: testSignInDetails, }; // mock tokens should not include signInDetails const mockTokens: CognitoAuthTokens = { @@ -61,11 +63,11 @@ describe('tokenOrchestrator', () => { payload: {}, }, clockDrift: 300, - username: testUsername + 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, }); @@ -83,7 +85,7 @@ describe('tokenOrchestrator', () => { // ensure the result is correct expect(newTokens).toEqual(mockTokens); - expect(newTokens?.signInDetails).toEqual(testSignInDetails) + expect(newTokens?.signInDetails).toEqual(testSignInDetails); }); }); }); diff --git a/packages/auth/__tests__/providers/cognito/updateMFAPreference.test.ts b/packages/auth/__tests__/providers/cognito/updateMFAPreference.test.ts index 699158449e6..dbaeca398f6 100644 --- a/packages/auth/__tests__/providers/cognito/updateMFAPreference.test.ts +++ b/packages/auth/__tests__/providers/cognito/updateMFAPreference.test.ts @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { Amplify, fetchAuthSession } from '@aws-amplify/core'; +import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { UpdateMFAPreferenceInput, updateMFAPreference, @@ -10,8 +12,7 @@ import { setUserMFAPreference } from '../../../src/providers/cognito/utils/clien import { AuthError } from '../../../src/errors/AuthError'; import { SetUserMFAPreferenceException } from '../../../src/providers/cognito/types/errors'; import { getMFASettings } from '../../../src/providers/cognito/apis/updateMFAPreference'; -import { SetUserMFAPreferenceCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; -import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/updatePassword.test.ts b/packages/auth/__tests__/providers/cognito/updatePassword.test.ts index 978377eca52..42c0869a9a3 100644 --- a/packages/auth/__tests__/providers/cognito/updatePassword.test.ts +++ b/packages/auth/__tests__/providers/cognito/updatePassword.test.ts @@ -3,11 +3,13 @@ import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; import { updatePassword } from '../../../src/providers/cognito'; import { ChangePasswordException } from '../../../src/providers/cognito/types/errors'; import { changePassword } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/updateUserAttribute.test.ts b/packages/auth/__tests__/providers/cognito/updateUserAttribute.test.ts index 8826b4c7c55..4fa6ac086d7 100644 --- a/packages/auth/__tests__/providers/cognito/updateUserAttribute.test.ts +++ b/packages/auth/__tests__/providers/cognito/updateUserAttribute.test.ts @@ -3,8 +3,10 @@ import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { updateUserAttribute } from '../../../src/providers/cognito'; import { updateUserAttributes } from '../../../src/providers/cognito/apis/updateUserAttributes'; + import { mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/updateUserAttributes.test.ts b/packages/auth/__tests__/providers/cognito/updateUserAttributes.test.ts index 3128767bd5c..3b1ca0f9d99 100644 --- a/packages/auth/__tests__/providers/cognito/updateUserAttributes.test.ts +++ b/packages/auth/__tests__/providers/cognito/updateUserAttributes.test.ts @@ -3,11 +3,13 @@ import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; import { updateUserAttributes } from '../../../src/providers/cognito'; import { UpdateUserAttributesException } from '../../../src/providers/cognito/types/errors'; import { updateUserAttributes as providerUpdateUserAttributes } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; import { toAttributeType } from '../../../src/providers/cognito/utils/apiHelpers'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/providers/cognito/utils/dispatchSignedInHubEvent.test.ts b/packages/auth/__tests__/providers/cognito/utils/dispatchSignedInHubEvent.test.ts index 80ae0253cd9..cda090b166b 100644 --- a/packages/auth/__tests__/providers/cognito/utils/dispatchSignedInHubEvent.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/dispatchSignedInHubEvent.test.ts @@ -3,9 +3,10 @@ import { Hub } from '@aws-amplify/core'; import { AMPLIFY_SYMBOL } from '@aws-amplify/core/internals/utils'; + import { - dispatchSignedInHubEvent, ERROR_MESSAGE, + dispatchSignedInHubEvent, } from '../../../../src/providers/cognito/utils/dispatchSignedInHubEvent'; import { getCurrentUser } from '../../../../src/providers/cognito/apis/getCurrentUser'; import { assertAuthTokens } from '../../../../src/providers/cognito/utils/types'; diff --git a/packages/auth/__tests__/providers/cognito/utils/oauth/attemptCompleteOAuthFlow.test.ts b/packages/auth/__tests__/providers/cognito/utils/oauth/attemptCompleteOAuthFlow.test.ts index 63433060260..589396dc848 100644 --- a/packages/auth/__tests__/providers/cognito/utils/oauth/attemptCompleteOAuthFlow.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/oauth/attemptCompleteOAuthFlow.test.ts @@ -11,10 +11,7 @@ import { completeOAuthFlow } from '../../../../../src/providers/cognito/utils/oa import { getRedirectUrl } from '../../../../../src/providers/cognito/utils/oauth/getRedirectUrl'; import { oAuthStore } from '../../../../../src/providers/cognito/utils/oauth/oAuthStore'; import { mockAuthConfigWithOAuth } from '../../../../mockData'; -import { tokenOrchestrator } from '../../../../../src/providers/cognito/tokenProvider/tokenProvider'; - import type { OAuthStore } from '../../../../../src/providers/cognito/utils/types'; -import { addInflightPromise } from '../../../../../src/providers/cognito/utils/oauth/inflightPromise'; jest.mock('@aws-amplify/core/internals/utils'); jest.mock('../../../../../src/providers/cognito/utils/oauth/completeOAuthFlow'); @@ -51,7 +48,7 @@ const mockCompleteOAuthFlow = completeOAuthFlow as jest.Mock; const mockGetRedirectUrl = getRedirectUrl as jest.Mock; describe('attemptCompleteOAuthFlow', () => { - let windowSpy = jest.spyOn(window, 'window', 'get'); + const windowSpy = jest.spyOn(window, 'window', 'get'); const mockRedirectUrl = 'http://localhost:3000/'; beforeAll(() => { @@ -110,10 +107,8 @@ describe('attemptCompleteOAuthFlow', () => { redirectUri: 'http://localhost:3000/', }), ); - }); - test.each([ ['assertTokenProviderConfig', mockAssertTokenProviderConfig], ['assertOAuthConfig', mockAssertOAuthConfig], diff --git a/packages/auth/__tests__/providers/cognito/utils/oauth/completeOAuthFlow.test.ts b/packages/auth/__tests__/providers/cognito/utils/oauth/completeOAuthFlow.test.ts index e7e5680e2ea..78e95120977 100644 --- a/packages/auth/__tests__/providers/cognito/utils/oauth/completeOAuthFlow.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/oauth/completeOAuthFlow.test.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { Hub, decodeJWT } from '@aws-amplify/core'; + import { handleFailure } from '../../../../../src/providers/cognito/utils/oauth/handleFailure'; import { validateState } from '../../../../../src/providers/cognito/utils/oauth/validateState'; import { resolveAndClearInflightPromises } from '../../../../../src/providers/cognito/utils/oauth/inflightPromise'; @@ -10,7 +11,6 @@ import { cacheCognitoTokens } from '../../../../../src/providers/cognito/tokenPr import { AuthError } from '../../../../../src/errors/AuthError'; import { AuthErrorTypes } from '../../../../../src/types/Auth'; import { OAuthStore } from '../../../../../src/providers/cognito/utils/types'; - import { completeOAuthFlow } from '../../../../../src/providers/cognito/utils/oauth/completeOAuthFlow'; jest.mock('@aws-amplify/core', () => ({ @@ -44,7 +44,6 @@ jest.mock( }), ); - const mockHandleFailure = handleFailure as jest.Mock; const mockValidateState = validateState as jest.Mock; const mockResolveAndClearInflightPromises = @@ -54,7 +53,7 @@ const mockHubDispatch = Hub.dispatch as jest.Mock; const mockDecodeJWT = decodeJWT as jest.Mock; describe('completeOAuthFlow', () => { - let windowSpy = jest.spyOn(window, 'window', 'get'); + const windowSpy = jest.spyOn(window, 'window', 'get'); const mockFetch = jest.fn(); const mockReplaceState = jest.fn(); diff --git a/packages/auth/__tests__/providers/cognito/utils/oauth/completeOAuthSignOut.test.ts b/packages/auth/__tests__/providers/cognito/utils/oauth/completeOAuthSignOut.test.ts index 5fb50c8285e..1fa56a926ca 100644 --- a/packages/auth/__tests__/providers/cognito/utils/oauth/completeOAuthSignOut.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/oauth/completeOAuthSignOut.test.ts @@ -1,8 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { clearCredentials, Hub } from '@aws-amplify/core'; +import { Hub, clearCredentials } from '@aws-amplify/core'; import { AMPLIFY_SYMBOL } from '@aws-amplify/core/internals/utils'; + import { tokenOrchestrator } from '../../../../../src/providers/cognito/tokenProvider/tokenProvider'; import { completeOAuthSignOut } from '../../../../../src/providers/cognito/utils/oauth/completeOAuthSignOut'; import { DefaultOAuthStore } from '../../../../../src/providers/cognito/utils/signInWithRedirectStore'; diff --git a/packages/auth/__tests__/providers/cognito/utils/oauth/index.test.ts b/packages/auth/__tests__/providers/cognito/utils/oauth/index.test.ts index 510d5ad211a..20d41571a03 100644 --- a/packages/auth/__tests__/providers/cognito/utils/oauth/index.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/oauth/index.test.ts @@ -3,10 +3,11 @@ import { Sha256 } from '@aws-crypto/sha256-js'; import { + base64Encoder, generateRandomString, getCrypto, - base64Encoder, } from '@aws-amplify/core/internals/utils'; + import { generateCodeVerifier, generateState, diff --git a/packages/auth/__tests__/providers/cognito/utils/oauth/oAuthSignOutRedirect.test.ts b/packages/auth/__tests__/providers/cognito/utils/oauth/oAuthSignOutRedirect.test.ts index 18cedfa47a7..a16bbb54eb1 100644 --- a/packages/auth/__tests__/providers/cognito/utils/oauth/oAuthSignOutRedirect.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/oauth/oAuthSignOutRedirect.test.ts @@ -24,7 +24,7 @@ describe('oAuthSignOutRedirect', () => { domain, redirectSignIn: ['https://myapp.test/completeSignIn/'], redirectSignOut: [signOutRedirectUrl], - responseType: 'code' as 'code', // assert string union instead of string type + responseType: 'code' as const, // assert string union instead of string type scopes: [], }, }, diff --git a/packages/auth/__tests__/providers/cognito/utils/oauth/validateState.test.ts b/packages/auth/__tests__/providers/cognito/utils/oauth/validateState.test.ts index c0d357b53a0..48a9e6ee66e 100644 --- a/packages/auth/__tests__/providers/cognito/utils/oauth/validateState.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/oauth/validateState.test.ts @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { - validateState, flowCancelledMessage, + validateState, validationFailedMessage, validationRecoverySuggestion, } from '../../../../../src/providers/cognito/utils/oauth/validateState'; 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/__tests__/providers/cognito/utils/srp/getHashFromHex.test.ts b/packages/auth/__tests__/providers/cognito/utils/srp/getHashFromHex.test.ts index c8a8a61d1ea..631458d493c 100644 --- a/packages/auth/__tests__/providers/cognito/utils/srp/getHashFromHex.test.ts +++ b/packages/auth/__tests__/providers/cognito/utils/srp/getHashFromHex.test.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { Sha256 } from '@aws-crypto/sha256-js'; + import { getHashFromHex } from '../../../../../src/providers/cognito/utils/srp/getHashFromHex'; describe('getHashFromHex', () => { diff --git a/packages/auth/__tests__/providers/cognito/verifyTOTPSetup.test.ts b/packages/auth/__tests__/providers/cognito/verifyTOTPSetup.test.ts index 78741c0b214..aceb6ed480a 100644 --- a/packages/auth/__tests__/providers/cognito/verifyTOTPSetup.test.ts +++ b/packages/auth/__tests__/providers/cognito/verifyTOTPSetup.test.ts @@ -3,11 +3,13 @@ import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; + import { AuthError } from '../../../src/errors/AuthError'; import { AuthValidationErrorCode } from '../../../src/errors/types/validation'; import { VerifySoftwareTokenException } from '../../../src/providers/cognito/types/errors'; import { verifyTOTPSetup } from '../../../src/providers/cognito'; import { verifySoftwareToken } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; + import { getMockError, mockAccessToken } from './testUtils/data'; import { setUpGetConfig } from './testUtils/setUpGetConfig'; diff --git a/packages/auth/__tests__/utils/getAuthUserAgentDetails.test.ts b/packages/auth/__tests__/utils/getAuthUserAgentDetails.test.ts index 014f6b03a86..f6503175cf3 100644 --- a/packages/auth/__tests__/utils/getAuthUserAgentDetails.test.ts +++ b/packages/auth/__tests__/utils/getAuthUserAgentDetails.test.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { AuthAction, Category } from '@aws-amplify/core/internals/utils'; + import { getAuthUserAgentDetails } from '../../src/utils'; describe('getAuthUserAgentDetails', () => { diff --git a/packages/auth/__tests__/utils/getAuthUserAgentValue.test.ts b/packages/auth/__tests__/utils/getAuthUserAgentValue.test.ts index e3a8248a9ed..a2b832f220c 100644 --- a/packages/auth/__tests__/utils/getAuthUserAgentValue.test.ts +++ b/packages/auth/__tests__/utils/getAuthUserAgentValue.test.ts @@ -6,6 +6,7 @@ import { Category, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils'; + import { getAuthUserAgentValue } from '../../src/utils'; jest.mock('@aws-amplify/core/internals/utils', () => ({ 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 */ From d7354f86daa823a41dcd30d3d953254ff7f60bde Mon Sep 17 00:00:00 2001 From: Hui Zhao <10602282+HuiSF@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:29:51 -0700 Subject: [PATCH 4/7] chore: add additional codeowners (#13491) --- .github/CODEOWNERS | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 55d38d2e20d..079ac7f2997 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -10,3 +10,16 @@ /packages/aws-amplify/package.json @aws-amplify/amplify-js-admins /.circleci/ @aws-amplify/amplify-js @aws-amplify/amplify-devops /.github/ @aws-amplify/amplify-js-admins +/packages/auth @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/aws-amplify/src/adapter-core @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/adapterCore @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/singleton @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/utils/convert @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/utils/WordArray.ts @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/storage @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/utils/generateRandomString.ts @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/utils/globalHelpers @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/utils/urlSafeDecode.ts @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/awsClients/cognitoIdentity @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/clients/internal @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF +/packages/core/src/Hub @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF From 85a826ee6a68a831b70f093b6ad686eacac2ff1e Mon Sep 17 00:00:00 2001 From: Ivan Artemiev <29709626+iartemiev@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:51:57 -0400 Subject: [PATCH 5/7] ci: disable websocket disruption e2e (#13496) --- .github/canary-config/canary-all.yml | 7 ------- .github/integ-config/integ-all.yml | 7 ------- 2 files changed, 14 deletions(-) diff --git a/.github/canary-config/canary-all.yml b/.github/canary-config/canary-all.yml index f527f4371e6..8cb61f4353a 100644 --- a/.github/canary-config/canary-all.yml +++ b/.github/canary-config/canary-all.yml @@ -91,13 +91,6 @@ tests: browser: [chrome, firefox] timeout_minutes: 45 retry_count: 10 - - test_name: integ_react_datastore_websocket_disruption - desc: 'DataStore - WebSocket Disruption' - framework: react - category: datastore - sample_name: [websocket-disruption] - spec: websocket-disruption - browser: [chrome, firefox] # can un comment when ever fixed # - test_name: integ_next_datastore_owner_auth # desc: 'next owner auth' diff --git a/.github/integ-config/integ-all.yml b/.github/integ-config/integ-all.yml index 76976c98f42..8a438391cc0 100644 --- a/.github/integ-config/integ-all.yml +++ b/.github/integ-config/integ-all.yml @@ -366,13 +366,6 @@ tests: sample_name: [v2/amplify-docs-examples] spec: amplify-docs-examples browser: [chrome] - - test_name: integ_react_datastore_websocket_disruption - desc: 'DataStore - WebSocket Disruption' - framework: react - category: datastore - sample_name: [websocket-disruption] - spec: websocket-disruption - browser: *minimal_browser_list - test_name: integ_vanilla_js_datastore_basic_crud desc: 'Vanilla JS + Webpack 4 + DataStore - Basic CRUD' framework: javascript From 5d97010f2ed7344eb2e9633d8564ffa489703691 Mon Sep 17 00:00:00 2001 From: Hui Zhao <10602282+HuiSF@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:13:59 -0700 Subject: [PATCH 6/7] chore(repo): add ssr two clients E2E (#13482) * chore(repo): add ssr two clients E2E * Remove unused the env vars * Run the new E2E test in the existing workflow --- .github/integ-config/integ-all.yml | 10 ++++ .github/workflows/callable-e2e-test.yml | 60 +++++++++++++++--------- .github/workflows/callable-e2e-tests.yml | 1 + scripts/test-github-actions.js | 2 +- 4 files changed, 49 insertions(+), 24 deletions(-) diff --git a/.github/integ-config/integ-all.yml b/.github/integ-config/integ-all.yml index 8a438391cc0..cdbef83b25d 100644 --- a/.github/integ-config/integ-all.yml +++ b/.github/integ-config/integ-all.yml @@ -839,3 +839,13 @@ tests: # sample_name: duplicate-packages # spec: duplicate-packages # browser: *minimal_browser_list + + # SSR context isolation + - test_name: integ_ssr_context_isolation + desc: 'SSR Context Isolation' + framework: next + category: ssr-adapter + sample_name: ssr-context-isolation + spec: ssr-context-isolation + yarn_script: ci:ssr-context-isolation + browser: [chrome] diff --git a/.github/workflows/callable-e2e-test.yml b/.github/workflows/callable-e2e-test.yml index 67b35106458..18697cf5dc5 100644 --- a/.github/workflows/callable-e2e-test.yml +++ b/.github/workflows/callable-e2e-test.yml @@ -34,6 +34,9 @@ on: retry_count: required: true type: number + yarn_script: + required: false + type: string env: AMPLIFY_DIR: /home/runner/work/amplify-js/amplify-js/amplify-js @@ -80,19 +83,24 @@ jobs: E2E_AMPLIFY_JS_DIR: ${{ inputs.amplifyjs_dir == true && env.AMPLIFY_DIR || ''}} E2E_RETRY_COUNT: ${{ inputs.retry_count }} E2E_TEST_NAME: ${{ inputs.test_name }} + E2E_YARN_SCRIPT: ${{ inputs.yarn_script }} run: | - ../amplify-js/scripts/retry-yarn-script.sh -s \ - "ci:test \ - $E2E_FRAMEWORK \ - $E2E_CATEGORY \ - $E2E_SAMPLE_NAME \ - $E2E_SPEC \ - $E2E_BROWSER \ - dev \ - $E2E_BACKEND \ - $E2E_AMPLIFY_JS_DIR" \ - -n $E2E_RETRY_COUNT - + if [ -z "$E2E_YARN_SCRIPT" ]; then + ../amplify-js/scripts/retry-yarn-script.sh -s \ + "ci:test \ + $E2E_FRAMEWORK \ + $E2E_CATEGORY \ + $E2E_SAMPLE_NAME \ + $E2E_SPEC \ + $E2E_BROWSER \ + dev \ + $E2E_BACKEND \ + $E2E_AMPLIFY_JS_DIR" \ + $E2E_YARN_SCRIPT \ + -n $E2E_RETRY_COUNT + else + echo "Skipping specialized yarn script execution in the dev environment." + fi - name: Run cypress tests for ${{ inputs.test_name }} prod shell: bash working-directory: amplify-js-samples-staging @@ -106,18 +114,24 @@ jobs: E2E_AMPLIFY_JS_DIR: ${{ inputs.amplifyjs_dir == true && env.AMPLIFY_DIR || ''}} E2E_RETRY_COUNT: ${{ inputs.retry_count }} E2E_TEST_NAME: ${{ inputs.test_name }} + E2E_YARN_SCRIPT: ${{ inputs.yarn_script }} run: | - ../amplify-js/scripts/retry-yarn-script.sh -s \ - "ci:test \ - $E2E_FRAMEWORK \ - $E2E_CATEGORY \ - $E2E_SAMPLE_NAME \ - $E2E_SPEC \ - $E2E_BROWSER \ - prod \ - $E2E_BACKEND \ - $E2E_AMPLIFY_JS_DIR" \ - -n $E2E_RETRY_COUNT + if [ -z "$E2E_YARN_SCRIPT" ]; then + ../amplify-js/scripts/retry-yarn-script.sh -s \ + "ci:test \ + $E2E_FRAMEWORK \ + $E2E_CATEGORY \ + $E2E_SAMPLE_NAME \ + $E2E_SPEC \ + $E2E_BROWSER \ + prod \ + $E2E_BACKEND \ + $E2E_AMPLIFY_JS_DIR" \ + $E2E_YARN_SCRIPT \ + -n $E2E_RETRY_COUNT + else + yarn "$E2E_YARN_SCRIPT" + fi - name: Upload artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 https://github.com/actions/upload-artifact/commit/0b7f8abb1508181956e8e162db84b466c27e18ce if: failure() diff --git a/.github/workflows/callable-e2e-tests.yml b/.github/workflows/callable-e2e-tests.yml index 2bfc5161ec3..c27c51ce57f 100644 --- a/.github/workflows/callable-e2e-tests.yml +++ b/.github/workflows/callable-e2e-tests.yml @@ -43,6 +43,7 @@ jobs: backend: ${{ matrix.integ-config.backend }} timeout_minutes: ${{ matrix.integ-config.timeout_minutes || 35 }} retry_count: ${{ matrix.integ-config.retry_count || 3 }} + yarn_script: ${{ matrix.integ-config.yarn_script || '' }} # e2e-test-runner-headless: # name: E2E test runnner_headless diff --git a/scripts/test-github-actions.js b/scripts/test-github-actions.js index 8b6bbea9400..f819ec30b64 100755 --- a/scripts/test-github-actions.js +++ b/scripts/test-github-actions.js @@ -43,7 +43,7 @@ for (const file of [...workflowYmlFiles, ...actionYmlFiles]) { const runCommandValues = getKeyValuesFor('run', ymlContents); for (const val of runCommandValues) { if (val.match(variableTemplatePattern)) { - console.log(`There is an inline variabled used in ${file}`); + console.log(`There is an inline variable used in ${file}`); exitCode = 1; } } From de6b06db80b02687e597aceaa2c33f65171a6389 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:38:58 -0500 Subject: [PATCH 7/7] chore(deps): bump braces from 3.0.2 to 3.0.3 (#13497) Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3. - [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3) --- updated-dependencies: - dependency-name: braces dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/yarn.lock b/yarn.lock index 37bbbe790e3..d25fa858452 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6065,11 +6065,11 @@ brace-expansion@^2.0.1: balanced-match "^1.0.0" braces@^3.0.2, braces@~3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" - integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== + version "3.0.3" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== dependencies: - fill-range "^7.0.1" + fill-range "^7.1.1" browserslist@^4.21.10, browserslist@^4.22.2, browserslist@^4.22.3: version "4.23.0" @@ -7991,10 +7991,10 @@ filelist@^1.0.4: dependencies: minimatch "^5.0.1" -fill-range@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" - integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== dependencies: to-regex-range "^5.0.1" @@ -14354,7 +14354,16 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -14431,7 +14440,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -14445,6 +14454,13 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" +strip-ansi@^6.0.0, strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + strip-ansi@^7.0.1, strip-ansi@^7.1.0: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -15570,7 +15586,7 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -15597,6 +15613,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"