Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should be able to set rollingDuration as false (when rolling is false) #623

Merged
merged 1 commit into from
Mar 24, 2022
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
3 changes: 2 additions & 1 deletion src/auth0-session/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/auth0-session/cookie-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is enforced at runtime by Joi

}
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?] {
Expand Down
8 changes: 6 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions tests/auth0-session/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
11 changes: 11 additions & 0 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down