-
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.
fix: Recreate Analytics clients when credentials change (#12789)
- Loading branch information
Showing
8 changed files
with
154 additions
and
34 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 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
42 changes: 42 additions & 0 deletions
42
packages/core/__tests__/utils/haveCredentialsChanged.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,42 @@ | ||
import { haveCredentialsChanged } from '../../src/utils/haveCredentialsChanged'; | ||
|
||
const MOCK_AWS_CREDS = { | ||
accessKeyId: 'mock-access-key', | ||
secretAccessKey: 'mock-secret-key', | ||
sessionToken: 'mock-session-token' | ||
}; | ||
|
||
describe('haveCredentialsChanged', () => { | ||
it('returns true if access key has changed', () => { | ||
const credentialsHaveChanged = haveCredentialsChanged(MOCK_AWS_CREDS, { | ||
...MOCK_AWS_CREDS, | ||
secretAccessKey: 'mock-secret-key-alt', | ||
}); | ||
|
||
expect(credentialsHaveChanged).toBe(true); | ||
}); | ||
|
||
it('returns true if access key has changed', () => { | ||
const credentialsHaveChanged = haveCredentialsChanged(MOCK_AWS_CREDS, { | ||
...MOCK_AWS_CREDS, | ||
accessKeyId: 'mock-access-key-alt', | ||
}); | ||
|
||
expect(credentialsHaveChanged).toBe(true); | ||
}); | ||
|
||
it('returns true if session token has changed', () => { | ||
const credentialsHaveChanged = haveCredentialsChanged(MOCK_AWS_CREDS, { | ||
...MOCK_AWS_CREDS, | ||
sessionToken: 'mock-session-token-alt', | ||
}); | ||
|
||
expect(credentialsHaveChanged).toBe(true); | ||
}); | ||
|
||
it('returns false if credentials have not changed', () => { | ||
const credentialsHaveChanged = haveCredentialsChanged(MOCK_AWS_CREDS, MOCK_AWS_CREDS); | ||
|
||
expect(credentialsHaveChanged).toBe(false); | ||
}); | ||
}) |
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,17 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { AWSCredentials } from '../libraryUtils'; | ||
|
||
/** | ||
* Utility for determining if credentials have changed. | ||
* | ||
* @internal | ||
*/ | ||
export const haveCredentialsChanged = (cachedCredentials: AWSCredentials, credentials: AWSCredentials) => { | ||
return ( | ||
cachedCredentials.accessKeyId !== credentials.accessKeyId || | ||
cachedCredentials.sessionToken !== credentials.sessionToken || | ||
cachedCredentials.secretAccessKey !== credentials.secretAccessKey | ||
); | ||
}; |