From ef8df1948c9ffb5b69ec5113f3ff6c6def44d5f9 Mon Sep 17 00:00:00 2001 From: Andy Caruso Date: Mon, 21 Mar 2022 09:20:36 -0700 Subject: [PATCH] Remove cooldown parameter option Signed-off-by: Andy Caruso --- plugins/auth-node/src/IdentityClient.test.ts | 11 +++++--- plugins/auth-node/src/IdentityClient.ts | 28 +++++++------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/plugins/auth-node/src/IdentityClient.test.ts b/plugins/auth-node/src/IdentityClient.test.ts index cbc030dd1f..3386d4e414 100644 --- a/plugins/auth-node/src/IdentityClient.test.ts +++ b/plugins/auth-node/src/IdentityClient.test.ts @@ -185,7 +185,7 @@ describe('IdentityClient', () => { it('should accept token from new key', async () => { const fixedTime = Date.now(); - const spy = jest + jest .spyOn(Date, 'now') .mockImplementation(() => fixedTime - keyDurationSeconds * 1000 * 2); const token1 = await factory.issueToken({ claims: { sub: 'foo1' } }); @@ -195,8 +195,13 @@ describe('IdentityClient', () => { } catch (_err) { // Ignore thrown error } - // Move forward in time where the signing key has been rotated - spy.mockRestore(); + // Move forward in time where the signing key has been rotated and the + // cooldown period to look up a new public key has elapsed. + jest + .spyOn(Date, 'now') + .mockImplementation( + () => fixedTime + 30 * keyDurationSeconds * 1000 + 2, + ); const token = await factory.issueToken({ claims: { sub: 'foo' } }); const response = await client.authenticate(token); expect(response).toEqual({ diff --git a/plugins/auth-node/src/IdentityClient.ts b/plugins/auth-node/src/IdentityClient.ts index a98330fc71..2fdb876dd6 100644 --- a/plugins/auth-node/src/IdentityClient.ts +++ b/plugins/auth-node/src/IdentityClient.ts @@ -41,30 +41,22 @@ export class IdentityClient { /** * Create a new {@link IdentityClient} instance. */ - static create( - options: { - discovery: PluginEndpointDiscovery; - issuer: string; - }, - cooldownMs = 30000, - ): IdentityClient { - return new IdentityClient(options, cooldownMs); + static create(options: { + discovery: PluginEndpointDiscovery; + issuer: string; + }): IdentityClient { + return new IdentityClient(options); } - private constructor( - options: { - discovery: PluginEndpointDiscovery; - issuer: string; - }, - cooldownMs: number, - ) { + private constructor(options: { + discovery: PluginEndpointDiscovery; + issuer: string; + }) { this.discovery = options.discovery; this.issuer = options.issuer; this.discovery.getBaseUrl('auth').then(url => { this.endpoint = new URL(`${url}/.well-known/jwks.json`); - this.keyStore = createRemoteJWKSet(this.endpoint, { - cooldownDuration: cooldownMs, - }); + this.keyStore = createRemoteJWKSet(this.endpoint); }); }