Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Save deserialized credential object to Authentication member #436

Merged
merged 4 commits into from
Aug 23, 2023

Conversation

adebayor123
Copy link
Member

@adebayor123 adebayor123 commented Aug 18, 2023

Details

Currently in our Authentication and EnhancedAuthentication, we save credential object as serialized string values. Then, as we read the serialized string from Storage, we parse the string into a Credential object.

However, in AnonymousStorageCredentialsProvider, we overwrite the local member variable credential with the serialized string instead of the parsed object. As a result, any situation that requires reading of the credential from storage leads to: TypeError: this.credentials.expiration.getTime is not a function.

This PR removes the unnecessary step to overwrite the local member this.credential with the serialized string.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@adebayor123 adebayor123 requested a review from ps863 August 18, 2023 22:36
Comment on lines +90 to +93
this.credentials = {
...credentials,
expiration: new Date(credentials.expiration as Date)
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: We need unit tests to cover the new behavior (here and in Authentication.ts).

I think this change introduces a bug. Cover the following cases:

  1. When credentials are read from storage.
  2. When credentials are read from storage, and then read from the member variable.

@qhanam
Copy link
Member

qhanam commented Aug 21, 2023

I've pushed a patch for EnhancedAuthentication.ts:

  1. Add type to credentials local variable
  2. Add return statement when rejecting
  3. Fix expiration (to be date object) in resolved value
  4. Added unit tests

);
});

test('when credentials are read from storage then the member variable stores the expiration as a date object', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This test will pass under certain conditions when it should fail (i.e., false negative).

Specifically, when this.credentials.expiration is undefined, and the expiration property of the value returned by AnonymousStorageCredentialsProvider is a Date object. When this happens, control flow will reach AnonymousCognitoCredentialsProvider, and the test needs a way to distinguish the value returned here from the expected value.

You can fix this by mocking the response of getCredentials, like was done in EnhancedAuthentication.test.ts here.

@adebayor123 adebayor123 merged commit 6120c61 into aws-observability:main Aug 23, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants