-
Notifications
You must be signed in to change notification settings - Fork 66
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
Conversation
this.credentials = { | ||
...credentials, | ||
expiration: new Date(credentials.expiration as Date) | ||
}; |
There was a problem hiding this comment.
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:
- When credentials are read from storage.
- When credentials are read from storage, and then read from the member variable.
I've pushed a patch for EnhancedAuthentication.ts:
|
); | ||
}); | ||
|
||
test('when credentials are read from storage then the member variable stores the expiration as a date object', async () => { |
There was a problem hiding this comment.
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.
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.