Skip to content

Commit aaa1fff

Browse files
committed
add tests to refactored refresh token eviction logic
1 parent 3d1cc18 commit aaa1fff

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

__tests__/Auth0Client/onlineAccess.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,33 @@ describe('Auth0Client', () => {
594594
expect(rt).toBe(NEW_ORT);
595595
});
596596

597+
it('uses options.refresh_token directly for refresh_token grant without hitting the cache', async () => {
598+
// The refactored ?? path: options.refresh_token is set on the refresh_token grant,
599+
// so the cache lookup branch must NOT run — the token on options is used as-is.
600+
const auth0 = setup(onlineConfig as any);
601+
await loginWithRedirect(auth0);
602+
mockFetch.mockReset();
603+
604+
// Force-refresh: server returns no refresh_token (non-rotating ORT behaviour)
605+
mockFetch.mockResolvedValueOnce(
606+
fetchResponse(true, {
607+
id_token: TEST_ID_TOKEN,
608+
access_token: 'new-access-token',
609+
token_type: 'Bearer',
610+
expires_in: 86400,
611+
scope: 'openid profile email online_access',
612+
// no refresh_token — server does not echo ORT back
613+
})
614+
);
615+
616+
await auth0.getTokenSilently({ cacheMode: 'off' });
617+
618+
// ORT from the original login (TEST_REFRESH_TOKEN) must survive in cache —
619+
// it was on options.refresh_token and ?? short-circuits before the cache lookup.
620+
const rt = getCacheEntries().map(e => e?.body?.refresh_token).find(Boolean);
621+
expect(rt).toBe(TEST_REFRESH_TOKEN);
622+
});
623+
597624
it('does NOT carry the ORT forward on MFA grants in offline mode', async () => {
598625
const auth0 = setup({
599626
useRefreshTokens: true,

0 commit comments

Comments
 (0)