- Company login via Authentik OIDC (openid-client, PKCE/state/nonce, employee_number scope); AUTH_MODE=dev alternative login at /login/dev, refused at startup when platform OIDC_ISSUER is present - provisionOnLogin: accounts created on first login (employee role, pending department), inactive accounts rejected, bootstrap sysadmins - DB sessions (hashed tokens, 8h idle timeout, revoked on deactivate) - Authorization: ROUTE_RULES + requireRouteAccess/requireRole per page and action, forbidden() 403 page, proxy.ts cookie redirect, scopeApplications/canReview/requireDepartment, role-based navigation - Admin: departments (code, type, deactivate, managers), accounts (pending filter, department assignment with effective date, roles, deactivate), roster CSV import with two-phase preview/commit - departmentMembersAt for headcount snapshots - Tests: 168 unit/integration (incl. mock OIDC provider), 12 e2e - CI: e2e job; CLAUDE.md: auth rules and commands Tasks 15/17 done. Pending: 5.1 (confirm CI run once a remote exists), 5.3 (manual verification with real Authentik after first deploy). Co-Authored-By: Claude Opus 5.5 <[email protected]>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import { users } from "@/server/db/schema";
|
|
import { parseEnv } from "@/server/env";
|
|
import { createTestDatabase, type TestDatabase } from "@/server/testing/test-db";
|
|
import { DevLoginDisabledError, devLogin, isDevLoginEnabled } from "./dev-login";
|
|
|
|
const secret = "x".repeat(32);
|
|
const devEnv = parseEnv({ SESSION_SECRET: secret, AUTH_MODE: "dev" });
|
|
const oidcEnv = parseEnv({
|
|
SESSION_SECRET: secret,
|
|
OIDC_ISSUER: "https://auth.example/application/o/vibe-x/",
|
|
OIDC_CLIENT_ID: "id",
|
|
OIDC_CLIENT_SECRET: "secret",
|
|
APP_URL: "https://x-vibe.example",
|
|
});
|
|
|
|
describe("替代登入", () => {
|
|
let t: TestDatabase;
|
|
beforeEach(() => {
|
|
t = createTestDatabase();
|
|
});
|
|
afterEach(() => t.cleanup());
|
|
|
|
it("dev 模式以員工編號登入,套用首次登入建帳號規則", () => {
|
|
const result = devLogin(t.db, devEnv, "E1234", new Date());
|
|
expect(result).toMatchObject({ ok: true, created: true });
|
|
expect(t.db.select().from(users).get()).toMatchObject({
|
|
employeeNo: "E1234",
|
|
departmentId: null,
|
|
});
|
|
});
|
|
|
|
it("oidc 模式下不可用,也不建立帳號", () => {
|
|
expect(isDevLoginEnabled(oidcEnv)).toBe(false);
|
|
expect(() => devLogin(t.db, oidcEnv, "E1234", new Date())).toThrow(DevLoginDisabledError);
|
|
expect(t.db.select().from(users).all()).toHaveLength(0);
|
|
});
|
|
});
|