forked from baron/baron-sso
세션 만료 관리 토글 동작을 실제 정책에 맞게 분리
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
SESSION_RENEW_THRESHOLD_MS,
|
||||
shouldAttemptSlidingSessionRenew,
|
||||
shouldAttemptUnlimitedSessionRenew,
|
||||
} from "./sessionSliding";
|
||||
|
||||
describe("shouldAttemptSlidingSessionRenew", () => {
|
||||
@@ -71,3 +72,55 @@ describe("shouldAttemptSlidingSessionRenew", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldAttemptUnlimitedSessionRenew", () => {
|
||||
const nowMs = 1_700_000_000_000;
|
||||
|
||||
it("returns false when unlimited mode is not active", () => {
|
||||
expect(
|
||||
shouldAttemptUnlimitedSessionRenew({
|
||||
expiresAtSec: Math.floor(
|
||||
(nowMs + SESSION_RENEW_THRESHOLD_MS - 1_000) / 1000,
|
||||
),
|
||||
nowMs,
|
||||
isEnabled: true,
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
isRenewInFlight: false,
|
||||
lastAttemptAtMs: 0,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true near expiry when session expiry management is disabled", () => {
|
||||
expect(
|
||||
shouldAttemptUnlimitedSessionRenew({
|
||||
expiresAtSec: Math.floor(
|
||||
(nowMs + SESSION_RENEW_THRESHOLD_MS - 1_000) / 1000,
|
||||
),
|
||||
nowMs,
|
||||
isEnabled: false,
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
isRenewInFlight: false,
|
||||
lastAttemptAtMs: 0,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false when the token still has enough remaining lifetime", () => {
|
||||
expect(
|
||||
shouldAttemptUnlimitedSessionRenew({
|
||||
expiresAtSec: Math.floor(
|
||||
(nowMs + SESSION_RENEW_THRESHOLD_MS + 1_000) / 1000,
|
||||
),
|
||||
nowMs,
|
||||
isEnabled: false,
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
isRenewInFlight: false,
|
||||
lastAttemptAtMs: 0,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user