-
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.
feat(storage): move forceRefresh logics to storage clients instead of…
… global
- Loading branch information
1 parent
6a938df
commit e5a3226
Showing
12 changed files
with
195 additions
and
138 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
25 changes: 0 additions & 25 deletions
25
packages/core/__tests__/clients/middleware/retry/isCredentialsExpiredError.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
34 changes: 0 additions & 34 deletions
34
packages/core/src/clients/middleware/retry/isCredentialsExpiredError.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
export { | ||
Middleware, | ||
MiddlewareHandler, | ||
MiddlewareContext, | ||
Request, | ||
Response, | ||
TransferHandler, | ||
|
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
103 changes: 103 additions & 0 deletions
103
packages/storage/__tests__/providers/s3/utils/client/S3/utils/retryDecider.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,103 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { | ||
HttpResponse, | ||
getRetryDecider as getDefaultRetryDecider, | ||
} from '@aws-amplify/core/internals/aws-client-utils'; | ||
|
||
import { retryDecider } from '../../../../../../../src/providers/s3/utils/client/utils'; | ||
import { parseXmlError } from '../../../../../../../src/providers/s3/utils/client/utils/parsePayload'; | ||
|
||
jest.mock( | ||
'../../../../../../../src/providers/s3/utils/client/utils/parsePayload', | ||
); | ||
jest.mock('@aws-amplify/core/internals/aws-client-utils'); | ||
|
||
const mockErrorParser = jest.mocked(parseXmlError); | ||
|
||
describe('retryDecider', () => { | ||
const mockHttpResponse: HttpResponse = { | ||
statusCode: 200, | ||
headers: {}, | ||
body: 'body' as any, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.mocked(getDefaultRetryDecider).mockReturnValue(async () => { | ||
return { retryable: false }; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should invoke the default retry decider', async () => { | ||
expect.assertions(3); | ||
const { retryable, isCredentialsExpiredError } = await retryDecider( | ||
mockHttpResponse, | ||
undefined, | ||
{}, | ||
); | ||
expect(getDefaultRetryDecider).toHaveBeenCalledWith(mockErrorParser); | ||
expect(retryable).toBe(false); | ||
expect(isCredentialsExpiredError).toBeFalsy(); | ||
}); | ||
|
||
describe('handling expired token errors', () => { | ||
const mockErrorMessage = 'Token expired'; | ||
it.each(['RequestExpired', 'ExpiredTokenException', 'ExpiredToken'])( | ||
'should retry if expired credentials error name %s', | ||
async errorName => { | ||
expect.assertions(2); | ||
const parsedError = { | ||
name: errorName, | ||
message: mockErrorMessage, | ||
$metadata: {}, | ||
}; | ||
mockErrorParser.mockResolvedValue(parsedError); | ||
const { retryable, isCredentialsExpiredError } = await retryDecider( | ||
{ ...mockHttpResponse, statusCode: 400 }, | ||
undefined, | ||
{}, | ||
); | ||
expect(retryable).toBe(true); | ||
expect(isCredentialsExpiredError).toBe(true); | ||
}, | ||
); | ||
|
||
it('should retry if error message indicates invalid credentials', async () => { | ||
expect.assertions(2); | ||
const parsedError = { | ||
name: 'InvalidSignature', | ||
message: 'Auth token in request is expired.', | ||
$metadata: {}, | ||
}; | ||
mockErrorParser.mockResolvedValue(parsedError); | ||
const { retryable, isCredentialsExpiredError } = await retryDecider( | ||
{ ...mockHttpResponse, statusCode: 400 }, | ||
undefined, | ||
{}, | ||
); | ||
expect(retryable).toBe(true); | ||
expect(isCredentialsExpiredError).toBe(true); | ||
}); | ||
|
||
it('should not retry if invalid credentials error has been retried previously', async () => { | ||
expect.assertions(2); | ||
const parsedError = { | ||
name: 'RequestExpired', | ||
message: mockErrorMessage, | ||
$metadata: {}, | ||
}; | ||
mockErrorParser.mockResolvedValue(parsedError); | ||
const { retryable, isCredentialsExpiredError } = await retryDecider( | ||
{ ...mockHttpResponse, statusCode: 400 }, | ||
undefined, | ||
{ isCredentialsExpired: true }, | ||
); | ||
expect(retryable).toBe(false); | ||
expect(isCredentialsExpiredError).toBe(true); | ||
}); | ||
}); | ||
}); |
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.