peppa/packages/testkit/test/logout-all.test.ts
Асель 6fbf10e00e PEP-95: after logout-all everyone sees the welcome page once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 14:01:15 +05:00

32 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// PEP-95: «выкинуть всех» — web sessions issued before the cut-off stop working.
import assert from "node:assert/strict";
import { after, describe, test } from "node:test";
import { core, db, teardown } from "./helpers.ts";
process.env.PEPPA_SECRET = "mock-secret-for-tests";
after(teardown);
describe("PEP-95: logout of every user", () => {
test("no cut-off by default; after logout-all, older sessions are invalid and new ones work", async () => {
assert.equal(await core.sessionsValidAfter(db), null);
const at = await core.logoutAllUsers(db, new Date("2026-11-15T10:00:00Z"));
const after = (await core.sessionsValidAfter(db))!;
assert.equal(after, at.getTime());
// The web's rule (apps/web/lib/auth.ts): issuedAt = exp − 30 days must not be before the cut-off.
const DAYS = 30 * 86400_000;
const valid = (issuedAt: number) => !(issuedAt + DAYS - DAYS < after);
assert.equal(valid(at.getTime() - 60_000), false, "a session from before is out");
assert.equal(valid(at.getTime() + 60_000), true, "signing in again works");
});
test("after logout-all everyone sees the welcome page once — users with projects too", async () => {
const u = await core.upsertUserFromGitea(db, { id: 951, login: "mock-welcome" }, { access_token: "x" });
await core.createProject(db, { slug: "mock-welcome", key: "MWLC", name: "W", giteaOwner: "x", workspacePath: "/tmp/mock-welcome", ownerId: u.id });
const t0 = new Date("2026-11-15T09:00:00Z");
assert.equal(await core.claimWelcome(db, u.id, t0), false, "has projects — not shown by itself");
await core.showWelcomeToEveryone(db, new Date("2026-11-15T10:00:00Z"));
assert.equal(await core.claimWelcome(db, u.id, new Date("2026-11-15T10:05:00Z")), true, "shown once after the reset");
assert.equal(await core.claimWelcome(db, u.id, new Date("2026-11-15T10:06:00Z")), false, "and only once");
});
});