diff --git a/x-pack/plugins/security/server/config.test.ts b/x-pack/plugins/security/server/config.test.ts index 4593d9a7ad682..75dfcb6151ea7 100644 --- a/x-pack/plugins/security/server/config.test.ts +++ b/x-pack/plugins/security/server/config.test.ts @@ -1689,41 +1689,39 @@ describe('createConfig()', () => { `); }); - it('falls back to the global settings if provider is not known', async () => { - expect( - createMockConfig({ session: { idleTimeout: 123 } }).session.getExpirationTimeouts({ - type: 'some type', - name: 'some name', - }) - ).toMatchInlineSnapshot(` - Object { - "idleTimeout": "PT0.123S", - "lifespan": "P30D", - } - `); + it('falls back to the global settings if provider is not known or is undefined', async () => { + [{ type: 'some type', name: 'some name' }, undefined].forEach((provider) => { + expect( + createMockConfig({ session: { idleTimeout: 123 } }).session.getExpirationTimeouts( + provider + ) + ).toMatchInlineSnapshot(` + Object { + "idleTimeout": "PT0.123S", + "lifespan": "P30D", + } + `); - expect( - createMockConfig({ session: { lifespan: 456 } }).session.getExpirationTimeouts({ - type: 'some type', - name: 'some name', - }) - ).toMatchInlineSnapshot(` - Object { - "idleTimeout": "PT1H", - "lifespan": "PT0.456S", - } - `); + expect( + createMockConfig({ session: { lifespan: 456 } }).session.getExpirationTimeouts(provider) + ).toMatchInlineSnapshot(` + Object { + "idleTimeout": "PT1H", + "lifespan": "PT0.456S", + } + `); - expect( - createMockConfig({ - session: { idleTimeout: 123, lifespan: 456 }, - }).session.getExpirationTimeouts({ type: 'some type', name: 'some name' }) - ).toMatchInlineSnapshot(` - Object { - "idleTimeout": "PT0.123S", - "lifespan": "PT0.456S", - } - `); + expect( + createMockConfig({ + session: { idleTimeout: 123, lifespan: 456 }, + }).session.getExpirationTimeouts(provider) + ).toMatchInlineSnapshot(` + Object { + "idleTimeout": "PT0.123S", + "lifespan": "PT0.456S", + } + `); + }); }); it('uses provider overrides if specified (only idle timeout)', async () => { diff --git a/x-pack/plugins/security/server/config.ts b/x-pack/plugins/security/server/config.ts index 40b1b9d10b801..9daf0aff4c6cb 100644 --- a/x-pack/plugins/security/server/config.ts +++ b/x-pack/plugins/security/server/config.ts @@ -391,7 +391,7 @@ export function createConfig( function getSessionConfig(session: RawConfigType['session'], providers: ProvidersConfigType) { return { cleanupInterval: session.cleanupInterval, - getExpirationTimeouts(provider?: AuthenticationProvider) { + getExpirationTimeouts(provider: AuthenticationProvider | undefined) { // Both idle timeout and lifespan from the provider specific session config can have three // possible types of values: `Duration`, `null` and `undefined`. The `undefined` type means that // provider doesn't override session config and we should fall back to the global one instead. diff --git a/x-pack/plugins/security/server/usage_collector/security_usage_collector.ts b/x-pack/plugins/security/server/usage_collector/security_usage_collector.ts index b09866ee47d2e..15177132e0fb1 100644 --- a/x-pack/plugins/security/server/usage_collector/security_usage_collector.ts +++ b/x-pack/plugins/security/server/usage_collector/security_usage_collector.ts @@ -181,7 +181,7 @@ export function registerSecurityUsageCollector({ usageCollection, config, licens WELL_KNOWN_AUTH_SCHEMES.includes(scheme.toLowerCase()) ); - const sessionExpirations = config.session.getExpirationTimeouts(); // get global expiration values + const sessionExpirations = config.session.getExpirationTimeouts(undefined); // use `undefined` to get global expiration values const sessionIdleTimeoutInMinutes = sessionExpirations.idleTimeout?.asMinutes() ?? 0; const sessionLifespanInMinutes = sessionExpirations.lifespan?.asMinutes() ?? 0; const sessionCleanupInMinutes = config.session.cleanupInterval?.asMinutes() ?? 0;