From 97d9213345134ccb2e1ff4a08984f07cfdcaa642 Mon Sep 17 00:00:00 2001 From: adamjmcgrath Date: Thu, 24 Mar 2022 10:53:10 +0000 Subject: [PATCH] Should be able to set rollingDuration as false (when rolling is false) --- src/auth0-session/config.ts | 3 ++- src/auth0-session/cookie-store.ts | 4 ++-- src/config.ts | 8 ++++++-- tests/auth0-session/config.test.ts | 13 +++++++++++++ tests/config.test.ts | 11 +++++++++++ 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/auth0-session/config.ts b/src/auth0-session/config.ts index 28a45ba49..a6d49c109 100644 --- a/src/auth0-session/config.ts +++ b/src/auth0-session/config.ts @@ -186,9 +186,10 @@ export interface SessionConfig { /** * Integer value, in seconds, for application session rolling duration. * The amount of time for which the user must be idle for then to be logged out. + * Should be false when rolling is false. * Default is 86400 seconds (1 day). */ - rollingDuration: number; + rollingDuration: number | false; /** * Integer value, in seconds, for application absolute rolling duration. diff --git a/src/auth0-session/cookie-store.ts b/src/auth0-session/cookie-store.ts index b09cd8010..802b42e27 100644 --- a/src/auth0-session/cookie-store.ts +++ b/src/auth0-session/cookie-store.ts @@ -70,12 +70,12 @@ export default class CookieStore { const { rolling, rollingDuration } = this.config.session; if (typeof absoluteDuration !== 'number') { - return uat + rollingDuration; + return uat + (rollingDuration as number); } if (!rolling) { return iat + absoluteDuration; } - return Math.min(uat + rollingDuration, iat + absoluteDuration); + return Math.min(uat + (rollingDuration as number), iat + absoluteDuration); } public read(req: IncomingMessage): [{ [key: string]: any }?, number?] { diff --git a/src/config.ts b/src/config.ts index 511ad186d..9a9cded60 100644 --- a/src/config.ts +++ b/src/config.ts @@ -196,10 +196,11 @@ export interface SessionConfig { /** * Integer value, in seconds, for application session rolling duration. * The amount of time for which the user must be idle for then to be logged out. + * Should be false when rolling is false. * Default is 86400 seconds (1 day). * You can also use the AUTH0_SESSION_ROLLING_DURATION environment variable. */ - rollingDuration: number; + rollingDuration: number | false; /** * Integer value, in seconds, for application absolute rolling duration. @@ -463,7 +464,10 @@ export const getConfig = (params: ConfigParameters = {}): { baseConfig: BaseConf session: { name: AUTH0_SESSION_NAME, rolling: bool(AUTH0_SESSION_ROLLING), - rollingDuration: num(AUTH0_SESSION_ROLLING_DURATION), + rollingDuration: + AUTH0_SESSION_ROLLING_DURATION && isNaN(Number(AUTH0_SESSION_ROLLING_DURATION)) + ? (bool(AUTH0_SESSION_ROLLING_DURATION) as false) + : num(AUTH0_SESSION_ROLLING_DURATION), absoluteDuration: AUTH0_SESSION_ABSOLUTE_DURATION && isNaN(Number(AUTH0_SESSION_ABSOLUTE_DURATION)) ? bool(AUTH0_SESSION_ABSOLUTE_DURATION) diff --git a/tests/auth0-session/config.test.ts b/tests/auth0-session/config.test.ts index d21f49d79..710dc57f0 100644 --- a/tests/auth0-session/config.test.ts +++ b/tests/auth0-session/config.test.ts @@ -210,6 +210,19 @@ describe('Config', () => { ).toThrow('"session.rollingDuration" must be false when "session.rolling" is disabled'); }); + it('should succeed when rollingDuration is defined as false and rolling is false', function () { + expect(() => + getConfig({ + ...defaultConfig, + session: { + rolling: false, + rollingDuration: false, + absoluteDuration: 10 + } + }) + ).not.toThrow(); + }); + it('should fail when rollingDuration is not defined and rolling is true', function () { expect(() => getConfig({ diff --git a/tests/config.test.ts b/tests/config.test.ts index 1b2331a94..a9a58f17c 100644 --- a/tests/config.test.ts +++ b/tests/config.test.ts @@ -124,6 +124,17 @@ describe('config params', () => { } } }); + expect( + getConfigWithEnv({ + AUTH0_SESSION_ROLLING_DURATION: 'no', + AUTH0_SESSION_ROLLING: 'no' + }).baseConfig + ).toMatchObject({ + session: { + rolling: false, + rollingDuration: false + } + }); }); test('should populate numbers', () => {