Skip to content

fix: Save deserialized credential object to Authentication member - #436

Merged
adebayor123 merged 4 commits into
aws-observability:mainfrom
adebayor123:main
Aug 23, 2023
Merged

fix: Save deserialized credential object to Authentication member#436
adebayor123 merged 4 commits into
aws-observability:mainfrom
adebayor123:main

Conversation

@adebayor123

@adebayor123 adebayor123 commented Aug 18, 2023

Copy link
Copy Markdown
Member

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 qhanam August 18, 2023 22:09
@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
Copy Markdown
Contributor

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

qhanam commented Aug 21, 2023

Copy link
Copy Markdown
Contributor

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

@adebayor123
adebayor123 requested a review from qhanam August 21, 2023 19:08
);
});

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

Copy link
Copy Markdown
Contributor

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.

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