-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release(required): Amplify JS release (#13862)
- Loading branch information
Showing
16 changed files
with
424 additions
and
374 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
packages/auth/__tests__/providers/cognito/credentialsProvider/IdentityIdStore.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Identity, ResourcesConfig } from '@aws-amplify/core'; | ||
|
||
import { DefaultIdentityIdStore } from '../../../../src/providers/cognito/credentialsProvider/IdentityIdStore'; | ||
|
||
const mockKeyValueStorage = { | ||
setItem: jest.fn(), | ||
getItem: jest.fn(), | ||
removeItem: jest.fn(), | ||
clear: jest.fn(), | ||
}; | ||
|
||
const validAuthConfig: ResourcesConfig = { | ||
Auth: { | ||
Cognito: { | ||
userPoolId: 'us-east-1_test-id', | ||
identityPoolId: 'us-east-1:test-id', | ||
userPoolClientId: 'test-id', | ||
allowGuestAccess: true, | ||
}, | ||
}, | ||
}; | ||
const validAuthKey = { | ||
identityId: `com.amplify.Cognito.${ | ||
validAuthConfig.Auth!.Cognito!.identityPoolId | ||
}.identityId`, | ||
}; | ||
const validGuestIdentityId: Identity = { type: 'guest', id: 'guest-id' }; | ||
const validPrimaryIdentityId: Identity = { type: 'primary', id: 'primary-id' }; | ||
|
||
const noIdentityPoolIdAuthConfig: ResourcesConfig = { | ||
Auth: { | ||
Cognito: { | ||
userPoolId: 'us-east-1_test-id', | ||
userPoolClientId: 'test-id', | ||
}, | ||
}, | ||
}; | ||
|
||
describe('DefaultIdentityIdStore', () => { | ||
const defaultIdStore = new DefaultIdentityIdStore(mockKeyValueStorage); | ||
beforeAll(() => { | ||
defaultIdStore.setAuthConfig(validAuthConfig.Auth!); | ||
}); | ||
|
||
afterEach(() => { | ||
mockKeyValueStorage.setItem.mockClear(); | ||
mockKeyValueStorage.getItem.mockClear(); | ||
mockKeyValueStorage.removeItem.mockClear(); | ||
mockKeyValueStorage.clear.mockClear(); | ||
}); | ||
|
||
it('should set the Auth config required to form the storage keys', async () => { | ||
expect(defaultIdStore._authKeys).toEqual(validAuthKey); | ||
}); | ||
|
||
it('should store guest identityId in keyValueStorage', async () => { | ||
defaultIdStore.storeIdentityId(validGuestIdentityId); | ||
expect(mockKeyValueStorage.setItem).toHaveBeenCalledWith( | ||
validAuthKey.identityId, | ||
validGuestIdentityId.id, | ||
); | ||
expect(defaultIdStore._primaryIdentityId).toBeUndefined(); | ||
expect(defaultIdStore._hasGuestIdentityId).toBe(true); | ||
}); | ||
|
||
it('should load guest identityId from keyValueStorage', async () => { | ||
mockKeyValueStorage.getItem.mockReturnValue(validGuestIdentityId.id); | ||
|
||
expect(await defaultIdStore.loadIdentityId()).toEqual(validGuestIdentityId); | ||
}); | ||
|
||
it('should store primary identityId in keyValueStorage', async () => { | ||
defaultIdStore.storeIdentityId(validPrimaryIdentityId); | ||
expect(mockKeyValueStorage.removeItem).toHaveBeenCalledWith( | ||
validAuthKey.identityId, | ||
); | ||
expect(defaultIdStore._primaryIdentityId).toEqual( | ||
validPrimaryIdentityId.id, | ||
); | ||
expect(defaultIdStore._hasGuestIdentityId).toBe(false); | ||
}); | ||
|
||
it('should load primary identityId from keyValueStorage', async () => { | ||
expect(await defaultIdStore.loadIdentityId()).toEqual( | ||
validPrimaryIdentityId, | ||
); | ||
}); | ||
|
||
it('should clear the cached identityId', async () => { | ||
defaultIdStore.clearIdentityId(); | ||
expect(mockKeyValueStorage.removeItem).toHaveBeenCalledWith( | ||
validAuthKey.identityId, | ||
); | ||
expect(defaultIdStore._primaryIdentityId).toBeUndefined(); | ||
}); | ||
|
||
it('should throw when identityPoolId is not present while setting the auth config', async () => { | ||
expect(() => { | ||
defaultIdStore.setAuthConfig(noIdentityPoolIdAuthConfig.Auth!); | ||
}).toThrow('Invalid identity pool id provided.'); | ||
}); | ||
|
||
it('should return null when the underlying keyValueStorage method returns null', async () => { | ||
mockKeyValueStorage.getItem.mockReturnValue(null); | ||
expect(await defaultIdStore.loadIdentityId()).toBeNull(); | ||
}); | ||
|
||
it('should return null when the underlying keyValueStorage method throws', async () => { | ||
mockKeyValueStorage.getItem.mockRejectedValue(new Error('Error')); | ||
expect(await defaultIdStore.loadIdentityId()).toBeNull(); | ||
}); | ||
|
||
it('should not call keyValueStorage.removeItem when there is no guest identityId to clear', async () => { | ||
const refreshIdentityIdStore = new DefaultIdentityIdStore( | ||
mockKeyValueStorage, | ||
); | ||
refreshIdentityIdStore.setAuthConfig(validAuthConfig.Auth!); | ||
|
||
refreshIdentityIdStore.storeIdentityId(validPrimaryIdentityId); | ||
expect(mockKeyValueStorage.removeItem).not.toHaveBeenCalled(); | ||
}); | ||
}); |
97 changes: 0 additions & 97 deletions
97
packages/auth/__tests__/providers/cognito/identityIdStore.test.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/storage/__tests__/providers/s3/apis/uploadData/byteLength.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { byteLength } from '../../../../../src/providers/s3/apis/uploadData/byteLength'; | ||
|
||
describe('byteLength', () => { | ||
it('returns 0 for null or undefined', () => { | ||
expect(byteLength(undefined)).toBe(0); | ||
expect(byteLength(null)).toBe(0); | ||
}); | ||
|
||
it('calculates byte length correctly for ASCII strings', () => { | ||
expect(byteLength('hello')).toBe(5); | ||
}); | ||
|
||
it('calculates byte length correctly for multi-byte characters', () => { | ||
expect(byteLength('èちは')).toBe(8); | ||
}); | ||
|
||
it('handles Uint8Array correctly', () => { | ||
const input = new Uint8Array([1, 2, 3]); | ||
expect(byteLength(input)).toBe(3); | ||
}); | ||
|
||
it('handles ArrayBuffer correctly', () => { | ||
const buffer = new ArrayBuffer(8); | ||
expect(byteLength(buffer)).toBe(8); | ||
}); | ||
|
||
it('handles File object correctly', () => { | ||
const file = new Blob(['hello']); | ||
expect(byteLength(file)).toBe(5); | ||
}); | ||
|
||
it('returns undefined for unsupported types', () => { | ||
const input = { unsupportedType: true }; | ||
expect(byteLength(input)).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.