Skip to content

Commit 380a0fd

Browse files
committed
removes unused import
1 parent aaa1fff commit 380a0fd

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

__tests__/Auth0Client/onlineAccess.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
TEST_ID_TOKEN
1919
} from '../constants';
2020
import { DEFAULT_AUDIENCE } from '../../src/constants';
21-
import { InvalidConfigurationError, MfaRequiredError } from '../../src/errors';
21+
import { InvalidConfigurationError } from '../../src/errors';
2222
import { fetchResponse } from './helpers';
2323

2424
jest.mock('es-cookie');
@@ -596,12 +596,18 @@ describe('Auth0Client', () => {
596596

597597
it('uses options.refresh_token directly for refresh_token grant without hitting the cache', async () => {
598598
// 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.
599+
// so the cache lookup inside _requestToken must NOT fire — options.refresh_token
600+
// short-circuits the ?? before the cache is read.
601+
//
602+
// Verifiable because _getTokenUsingRefreshToken calls cacheManager.get exactly once
603+
// (to retrieve the cached RT before the exchange). A second call would mean the
604+
// ?? fallback ran — which must NOT happen when options.refresh_token is present.
600605
const auth0 = setup(onlineConfig as any);
601606
await loginWithRedirect(auth0);
602607
mockFetch.mockReset();
603608

604-
// Force-refresh: server returns no refresh_token (non-rotating ORT behaviour)
609+
const cacheGetSpy = jest.spyOn((auth0 as any).cacheManager, 'get');
610+
605611
mockFetch.mockResolvedValueOnce(
606612
fetchResponse(true, {
607613
id_token: TEST_ID_TOKEN,
@@ -615,8 +621,12 @@ describe('Auth0Client', () => {
615621

616622
await auth0.getTokenSilently({ cacheMode: 'off' });
617623

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.
624+
// _getTokenUsingRefreshToken calls get() once. The ORT carry-forward in
625+
// _requestToken must NOT add a second call — options.refresh_token is set
626+
// so ?? resolves without reaching the cache.
627+
expect(cacheGetSpy).toHaveBeenCalledTimes(1);
628+
629+
// And the ORT must still be in the cache after the refresh.
620630
const rt = getCacheEntries().map(e => e?.body?.refresh_token).find(Boolean);
621631
expect(rt).toBe(TEST_REFRESH_TOKEN);
622632
});

src/worker/token.worker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ const messageHandler = async ({
189189
setRefreshToken(json.refresh_token, audience, scope);
190190
delete json.refresh_token;
191191
} else if (!preserveRefreshToken) {
192+
// Offline rotating tokens: evict the stored RT so it can't be reused.
193+
// Online (preserveRefreshToken=true) skips this — the ORT is non-rotating
194+
// and the server never returns a replacement.
192195
deleteRefreshToken(audience, scope);
193196
}
194197

0 commit comments

Comments
 (0)