Skip to content

Commit 948b7bb

Browse files
committed
test: fix unit tests
1 parent e4cb2c2 commit 948b7bb

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/cmap/auth/mongodb_oidc/cache.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export abstract class ExpiringCacheEntry {
1111
* Create a new expiring token entry.
1212
*/
1313
constructor(expiration: number) {
14-
this.expiration = expiration;
14+
this.expiration = this.expirationTime(expiration);
1515
}
1616
/**
1717
* The entry is still valid if the expiration is more than
@@ -20,6 +20,13 @@ export abstract class ExpiringCacheEntry {
2020
isValid() {
2121
return this.expiration - Date.now() > EXPIRATION_BUFFER_MS;
2222
}
23+
24+
/**
25+
* Get an expiration time in milliseconds past epoch. Defaults to immediate.
26+
*/
27+
private expirationTime(expiresInSeconds: number): number {
28+
return Date.now() + expiresInSeconds * 1000;
29+
}
2330
}
2431

2532
/**

src/cmap/auth/mongodb_oidc/token_entry_cache.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class TokenEntryCache extends AbstractCache<TokenEntry> {
3737
const entry = new TokenEntry(
3838
tokenResult,
3939
serverInfo,
40-
expirationTime(tokenResult.expiresInSeconds)
40+
tokenResult.expiresInSeconds ?? DEFAULT_EXPIRATION_SECS
4141
);
4242
this.entries.set(this.cacheKey(address, username, callbackHash), entry);
4343
return entry;
@@ -75,10 +75,3 @@ export class TokenEntryCache extends AbstractCache<TokenEntry> {
7575
return this.hashedCacheKey(address, username, callbackHash);
7676
}
7777
}
78-
79-
/**
80-
* Get an expiration time in milliseconds past epoch. Defaults to immediate.
81-
*/
82-
function expirationTime(expiresInSeconds?: number): number {
83-
return Date.now() + (expiresInSeconds ?? DEFAULT_EXPIRATION_SECS) * 1000;
84-
}

test/unit/cmap/auth/mongodb_oidc/azure_token_cache.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('AzureTokenCache', function () {
1919
});
2020

2121
it('adds the token result', function () {
22-
expect(entry.tokenResult).to.deep.equal(tokenResultWithExpiration);
22+
expect(entry.token).to.equal('test');
2323
});
2424

2525
it('creates an expiration', function () {
@@ -64,7 +64,7 @@ describe('AzureTokenCache', function () {
6464

6565
context('when there is a matching entry', function () {
6666
it('returns the entry', function () {
67-
expect(cache.getEntry('audience1')).to.equal(tokenResultWithExpiration);
67+
expect(cache.getEntry('audience1')?.token).to.equal('test');
6868
});
6969
});
7070

0 commit comments

Comments
 (0)