Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions __tests__/cache/cache-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,39 @@ cacheFactories.forEach(cacheFactory => {
});
});

it('should return another cache entry with a refresh token if the requested key returns undefined', async() => {
const data = {
...defaultData,
refresh_token: TEST_REFRESH_TOKEN,
decodedToken: {
claims: {
__raw: TEST_ID_TOKEN,
name: 'Test',
exp: nowSeconds() + dayInSeconds * 2
},
user: { name: 'Test' }
}
};

await manager.set(data);

const keySecondAudience = new CacheKey({
clientId: TEST_CLIENT_ID,
audience: 'my_second_audience',
scope: 'scope_1 scope_2',
});

await cache.set(keySecondAudience.toKey(), undefined);

const result = await manager.get(keySecondAudience, undefined, true);

expect(result).toStrictEqual({
refresh_token: TEST_REFRESH_TOKEN,
audience: data.audience,
scope: data.scope,
});
})

it('strips everything except the refresh token and audience when expiry has been reached', async () => {
const now = Date.now();
const realDateNow = Date.now.bind(global.Date);
Expand Down
2 changes: 1 addition & 1 deletion src/cache/cache-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class CacheManager {
// To refresh using MRRT we need to send a request to the server
// If cacheMode is 'cache-only', this will make us unable to call the server
// so it won't be needed to find a valid refresh token
if (!matchedKey && useMrrt && cacheMode !== 'cache-only') {
if (!wrappedEntry && useMrrt && cacheMode !== 'cache-only') {
return this.getEntryWithRefreshToken(cacheKey, keys);
}
}
Expand Down
Loading