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

[SDK-1649] Fix issue where cache was missed when scope parameter was provided #461

Merged
merged 2 commits into from
May 18, 2020

Conversation

adamjmcgrath
Copy link
Contributor

@adamjmcgrath adamjmcgrath commented May 13, 2020

Description

Multiple calls to getTokenSilently with the scope argument (eg getTokenSilently({ audience: 'https://api/tv-shows', scope: 'read:shows' })) will miss the cache because the scope argument is not being applied to the SDKs default scopes correctly

Testing

Subsequent calls to getTokenSilently with audience and scope should not use the network

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

@adamjmcgrath adamjmcgrath requested a review from a team May 13, 2020 08:09
@adamjmcgrath adamjmcgrath added CH: Fixed PR is fixing a bug tiny labels May 13, 2020
@adamjmcgrath adamjmcgrath added this to the vNext milestone May 13, 2020
Comment on lines 537 to 542
access_token = await auth0.getTokenSilently({
audience: 'foo',
scope: 'bar'
});
expect(access_token).toEqual('my_access_token');
expect(utils.runIframe).toHaveBeenCalledTimes(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it would better here to reset the utils.runIframe mock for this second call, then use .not.toHaveBeenCalled for the assertion.

The way the test reads right now at first glance is that we're expecting runIframe to be called once after each call, whereas we're actually only expecting it to be called once in total.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah 👍 good idea

@@ -512,4 +512,33 @@ describe('Auth0Client', () => {
value: originalUserAgent
});
});

it('uses the cache for multiple token requests with audience and scope', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a general question; do we want to migrate tests out of index.test.ts into this file? I'm conscious that we're starting to develop a set of tests across two places for the same functions.

Perhaps we should dedicate some effort to unifying the tests somewhere to make them more discoverable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed

Copy link
Contributor

@stevehobbsdev stevehobbsdev left a comment

Choose a reason for hiding this comment

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

Looks good, just had a couple of questions.

@adamjmcgrath adamjmcgrath merged commit c3a1d98 into master May 18, 2020
@stevehobbsdev stevehobbsdev deleted the fix/cache-miss-on-get-token branch May 18, 2020 12:28
@stevehobbsdev stevehobbsdev added review:tiny Tiny review and removed tiny labels Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CH: Fixed PR is fixing a bug review:tiny Tiny review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants