Files
doktainer-upstream/tests/backend/auth-session-retention.test.ts
KodekaTeam 0bd696d37f feat(auth): add session history retention and lifecycle updates
- Add daily session history cleanup with a 180-day retention period
- Run cleanup on startup and every 24 hours in batches of up to 1,000 sessions
- Add tests for session retention and derived session status
- Allow viewers to manage their own sessions while preserving global access for super admins
- Prevent the current browser session from being revoked through session management
- Derive active, expired, and revoked status without writing during list requests
- Count only active sessions toward the 20-session per-user limit
- Remove unused session event queries and payloads from the session listing endpoint
- Update the session management UI for the revised access and revocation policies
2026-09-13 10:24:49 +07:00

34 lines
1.0 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
getSessionHistoryCutoff,
getSessionHistoryRetentionFilter,
SESSION_HISTORY_RETENTION_DAYS,
SESSION_RETENTION_BATCH_SIZE,
} from "../../src/server/services/auth-session-retention.service";
test("session history retention keeps 180 days and deletes in bounded batches", () => {
assert.equal(SESSION_HISTORY_RETENTION_DAYS, 180);
assert.equal(SESSION_RETENTION_BATCH_SIZE, 1000);
assert.equal(
getSessionHistoryCutoff(new Date("2026-09-12T00:00:00.000Z")).toISOString(),
"2026-03-16T00:00:00.000Z",
);
assert.deepEqual(
getSessionHistoryRetentionFilter(new Date("2026-09-12T00:00:00.000Z")),
{
OR: [
{ revokedAt: { lte: new Date("2026-03-16T00:00:00.000Z") } },
{
revokedAt: null,
OR: [
{ idleExpiresAt: { lte: new Date("2026-03-16T00:00:00.000Z") } },
{ absoluteExpiresAt: { lte: new Date("2026-03-16T00:00:00.000Z") } },
],
},
],
},
);
});