Phase 1: identity, sessions, audit, frontend shell

AD sign-in over LDAPS (search with the service account, bind as the user,
nested groups through LDAP_MATCHING_RULE_IN_CHAIN, disabled accounts refused),
roles as the union of PS-* groups mapped by a table derived from the seeded
departments. Server-side sessions with idle, lock and absolute timeouts, Origin
and X-Requested-With check, step-up unlock. Optional Argon2id PIN set with the
domain password; PIN sign-in by employee ID on registered devices only; five
wrong attempts disable the PIN, three wrong at unlock or signature end the
session. Rate limits per account and per address before any bind. Devices,
signatures table and sign helper, audit rows for every identity event, SSE over
LISTEN/NOTIFY with presence. Account settings and Admin APIs and screens
(AD view, devices, PIN clearing, group map with missing-group flags, refresh
from AD now). CLI ad-groups --list and ad-refresh. Migration 0002.

Frontend: real sign-in (password tab, PIN keypad on registered devices), lock
screen, role switcher, Account settings, Admin shell, screen placeholders.

CI: Samba AD DC container (PSTEST.LOCAL) with a generated CA, 49 of the 50
groups plus one extra, 17 test users; wired into the CI compose overlay and
the Gitea workflow; Playwright sign-in scenario.

Verified on docker-1: 171 server tests green inside the CI stack against
PostgreSQL and the Samba DC, 48 frontend tests, 8 Playwright scenarios against
the live stack (password and PIN sign-in, lock and unlock, Admin group map).
Findings recorded in the docs: the DC needs CAP_SYS_ADMIN, a hidden tab locks
only after a minute as the old build did,
and the app uses the alias ps-app for Playwright because "app" is on
Chromium's HSTS preload list.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
2026-10-16 07:40:29 -06:00
co-authored by Claude Fable 5.1
parent 0b663bb2b2
commit 97b0973130
95 changed files with 9609 additions and 183 deletions
+56
View File
@@ -0,0 +1,56 @@
import { render } from "@testing-library/react";
import { MemoryRouter } from "react-router";
import { AppRoutes } from "../App";
import { AuthProvider } from "../auth/AuthProvider";
import type { Me } from "../auth/types";
export const DEPARTMENTS = [
{ code: "CL", slug: "Clerical", name: "Clerical", kind: "support", stations: [] },
{ code: "03", slug: "WeldParts", name: "Weld Parts", kind: "shop", stations: ["Stall 1", "Stall 2"] },
{ code: "14", slug: "Electrical", name: "Electrical", kind: "shop", stations: [] },
];
/** A signed-in Me. Override any part. */
export function makeMe(over: Partial<Omit<Me, "session" | "user">> & { session?: Partial<Me["session"]>; user?: Partial<Me["user"]> } = {}): Me {
const { session, user, ...rest } = over;
return {
user: {
id: "11111111-1111-1111-1111-111111111111",
sam_account: "clerk.clara",
upn: "[email protected]",
display_name: "Clara Clerk",
emp_no: "04001",
email: "[email protected]",
...user,
},
roles: ["clerical"],
screens: ["clerical"],
groups: ["PS-Clerical"],
pin: { set: false, disabled: false },
can_register_device: false,
...rest,
session: {
id: "sess-1",
kind: "password",
created_at: "2026-10-16T08:00:00Z",
expires_at: "2026-10-16T20:00:00Z",
locked: false,
locked_since: null,
device: null,
...session,
},
};
}
export const NO_SESSION = { status: 401, body: { detail: "Not signed in", code: "no_session" } };
/** Mounts the whole app at `path` under the auth provider. */
export function renderApp(path: string, props: { idleLockMs?: number; idleCheckMs?: number; hiddenLockMs?: number } = {}) {
return render(
<MemoryRouter initialEntries={[path]}>
<AuthProvider {...props}>
<AppRoutes />
</AuthProvider>
</MemoryRouter>,
);
}
+46 -8
View File
@@ -1,20 +1,58 @@
import { vi } from "vitest";
export type Route = { status?: number; body?: unknown; contentType?: string } | Error;
export type Reply = { status?: number; body?: unknown; contentType?: string } | Error;
/** Stubs global fetch. Routes are keyed by path. Unknown paths answer 404. */
/** What a route function sees about the request. */
export interface MockRequest {
method: string;
/** Path with the query string, as the app passed it. */
url: string;
path: string;
/** Parsed JSON body, or undefined. */
body: unknown;
}
export type Route = Reply | ((req: MockRequest) => Reply);
/**
* Stubs global fetch. Routes are keyed by path, or by "METHOD path".
* Lookup order: "METHOD url", "METHOD path", "url", "path". A url key includes the query string.
* A route may be a function of the request, for answers that change between calls.
* Unknown paths answer 404.
*/
export function mockFetch(routes: Record<string, Route>) {
const fn = vi.fn(async (input: RequestInfo | URL, _init?: RequestInit) => {
const path = typeof input === "string" ? input : input instanceof URL ? input.pathname : input.url;
const r = routes[path];
const fn = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const url = typeof input === "string" ? input : input instanceof URL ? input.pathname + input.search : input.url;
const path = url.split("?")[0] ?? url;
const method = (init?.method ?? "GET").toUpperCase();
let body: unknown;
if (typeof init?.body === "string") {
try {
body = JSON.parse(init.body) as unknown;
} catch {
body = init.body;
}
}
const route = routes[`${method} ${url}`] ?? routes[`${method} ${path}`] ?? routes[url] ?? routes[path];
const r = typeof route === "function" ? route({ method, url, path, body }) : route;
if (r instanceof Error) throw r;
const status = r?.status ?? (r ? 200 : 404);
const body = r?.body;
const isText = typeof body === "string";
const replyBody = r?.body;
const isText = typeof replyBody === "string";
const contentType = r?.contentType ?? (isText ? "text/plain" : "application/json");
const text = body === undefined ? "" : isText ? body : JSON.stringify(body);
const text = replyBody === undefined ? "" : isText ? replyBody : JSON.stringify(replyBody);
return new Response(status === 204 ? null : text, { status, headers: { "content-type": contentType } });
});
vi.stubGlobal("fetch", fn);
return fn;
}
/** The calls made to one method and path, with parsed JSON bodies. */
export function callsTo(fn: ReturnType<typeof mockFetch>, method: string, path: string): unknown[] {
return fn.mock.calls
.filter(([input, init]) => {
const url = typeof input === "string" ? input : input instanceof URL ? input.pathname : input.url;
return (init?.method ?? "GET").toUpperCase() === method && url.split("?")[0] === path;
})
.map(([, init]) => (typeof init?.body === "string" ? (JSON.parse(init.body) as unknown) : undefined));
}