forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into temp-signOut
- Loading branch information
Showing
19 changed files
with
218 additions
and
116 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,22 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// TODO: remove Auth and AuthClass imports/exports | ||
// import { Auth } from './Auth'; | ||
// tslint:disable-next-line no-duplicate-imports | ||
// import type { AuthClass } from './Auth'; | ||
import { | ||
CognitoHostedUIIdentityProvider, | ||
SignUpParams, | ||
GRAPHQL_AUTH_MODE, | ||
} from './types/Auth'; | ||
// import { | ||
// CognitoUser, | ||
// CookieStorage, | ||
// appendToCognitoUserAgent, | ||
// } from 'amazon-cognito-identity-js'; | ||
import { AuthErrorStrings } from './common/AuthErrorStrings'; | ||
|
||
/** | ||
* @deprecated use named import | ||
*/ | ||
// export default Auth; | ||
export { | ||
// Auth, | ||
// CognitoUser, | ||
// CookieStorage, | ||
CognitoHostedUIIdentityProvider, | ||
SignUpParams, | ||
// appendToCognitoUserAgent, | ||
AuthErrorStrings, | ||
GRAPHQL_AUTH_MODE, | ||
}; | ||
// export type { AuthClass }; | ||
|
||
// Provider specific types | ||
// Default provider APIs & types | ||
export * from './providers/cognito'; | ||
|
||
// Category specific types | ||
export * from './types'; | ||
|
||
export { fetchAuthSession } from '@aws-amplify/core'; |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Credentials } from '@aws-sdk/types'; | ||
import { AmplifyV6 } from '@aws-amplify/core'; | ||
import { deleteObject } from '../../../src/AwsClients/S3'; | ||
import { remove } from '../../../src/providers/s3/apis'; | ||
|
||
jest.mock('../../../src/AwsClients/S3'); | ||
jest.mock('@aws-amplify/core', () => { | ||
const core = jest.requireActual('@aws-amplify/core'); | ||
return { | ||
...core, | ||
fetchAuthSession: jest.fn(), | ||
AmplifyV6: { | ||
...core.AmplifyV6, | ||
getConfig: jest.fn(), | ||
Auth: { | ||
...core.AmplifyV6.Auth, | ||
fetchAuthSession: jest.fn(), | ||
}, | ||
}, | ||
}; | ||
}); | ||
const mockDeleteObject = deleteObject as jest.Mock; | ||
const key = 'key'; | ||
const bucket = 'bucket'; | ||
const region = 'region'; | ||
const targetIdentityId = 'targetIdentityId'; | ||
const removeResult = { key }; | ||
const credentials: Credentials = { | ||
accessKeyId: 'accessKeyId', | ||
sessionToken: 'sessionToken', | ||
secretAccessKey: 'secretAccessKey', | ||
}; | ||
const deleteObjectClientConfig = { | ||
credentials, | ||
region, | ||
}; | ||
|
||
describe('remove API', () => { | ||
beforeAll(() => { | ||
(AmplifyV6.Auth.fetchAuthSession as jest.Mock).mockResolvedValue({ | ||
credentials, | ||
identityId: targetIdentityId, | ||
}); | ||
(AmplifyV6.getConfig as jest.Mock).mockReturnValue({ | ||
Storage: { | ||
bucket: 'bucket', | ||
region: 'region', | ||
}, | ||
}); | ||
}); | ||
describe('Happy Path Cases:', () => { | ||
beforeEach(() => { | ||
mockDeleteObject.mockImplementation(() => { | ||
return { | ||
Metadata: { key: 'value' }, | ||
}; | ||
}); | ||
}); | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('Should remove object with default accessLevel', async () => { | ||
expect.assertions(3); | ||
expect(await remove({ key })).toEqual(removeResult); | ||
expect(deleteObject).toBeCalledTimes(1); | ||
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, { | ||
Bucket: bucket, | ||
Key: `public/${key}`, | ||
}); | ||
}); | ||
|
||
it('Should remove object with guest accessLevel', async () => { | ||
expect.assertions(3); | ||
expect(await remove({ key, options: { accessLevel: 'guest' } })).toEqual( | ||
removeResult | ||
); | ||
expect(deleteObject).toBeCalledTimes(1); | ||
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, { | ||
Bucket: bucket, | ||
Key: `public/${key}`, | ||
}); | ||
}); | ||
|
||
it('Should remove object with private accessLevel', async () => { | ||
expect.assertions(3); | ||
const accessLevel = 'private'; | ||
expect(await remove({ key, options: { accessLevel } })).toEqual( | ||
removeResult | ||
); | ||
expect(deleteObject).toBeCalledTimes(1); | ||
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, { | ||
Bucket: bucket, | ||
Key: `${accessLevel}/${targetIdentityId}/${key}`, | ||
}); | ||
}); | ||
|
||
it('Should remove object with protected accessLevel', async () => { | ||
expect.assertions(3); | ||
const accessLevel = 'protected'; | ||
expect( | ||
await remove({ key, options: { accessLevel, targetIdentityId } }) | ||
).toEqual(removeResult); | ||
expect(deleteObject).toBeCalledTimes(1); | ||
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, { | ||
Bucket: bucket, | ||
Key: `${accessLevel}/${targetIdentityId}/${key}`, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Error Path Cases:', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
it('Should return a not found error', async () => { | ||
mockDeleteObject.mockRejectedValueOnce( | ||
Object.assign(new Error(), { | ||
$metadata: { httpStatusCode: 404 }, | ||
name: 'NotFound', | ||
}) | ||
); | ||
expect.assertions(3); | ||
const key = 'wrongKey'; | ||
try { | ||
await remove({ key }); | ||
} catch (error) { | ||
expect(deleteObject).toBeCalledTimes(1); | ||
expect(deleteObject).toHaveBeenCalledWith(deleteObjectClientConfig, { | ||
Bucket: bucket, | ||
Key: `public/${key}`, | ||
}); | ||
expect(error.$metadata.httpStatusCode).toBe(404); | ||
} | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,21 +1,14 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// TODO: (ashwinkumar6) cleanup old exports | ||
import { Storage, StorageInstance } from './Storage'; | ||
export { AWSS3Provider } from './providers/AWSS3Provider'; | ||
export { Storage as StorageClass, StorageInstance as Storage }; | ||
export { | ||
uploadData, | ||
uploadFile, | ||
downloadData, | ||
downloadFile, | ||
remove, | ||
list, | ||
getProperties, | ||
copy, | ||
getUrl, | ||
} from './providers/s3'; | ||
export * from './types'; | ||
|
||
export { isCancelError } from './AwsClients/S3/runtime'; | ||
export * from './types'; |
Oops, something went wrong.