1
7import { describe, expect, it } from "vitest";
8import { assertScannerConfigured } from "../steps/scan.js";
9import type { WorkerEnv } from "../../../config.js";
10
11function env(over: Partial<WorkerEnv>): WorkerEnv {
12 return {
13 NODE_ENV: "development",
14 CLAMD_SOCKET: "",
15 CLAMAV_HOST: "",
16 CLAMAV_PORT: 3310,
17 ...over
18 } as WorkerEnv;
19}
20
21describe("clamav boot gate (TASK-0102 §3 fail closed)", () => {
22 it("dev + no scanner → allowed (scan skipped, WARN at run time)", () => {
23 expect(() => assertScannerConfigured(env({ NODE_ENV: "development" }))).not.toThrow();
24 });
25
26 it("production + no scanner → boot error (fail closed)", () => {
27 expect(() => assertScannerConfigured(env({ NODE_ENV: "production" }))).toThrow(
28 /requires a ClamAV scanner/i
29 );
30 });
31
32 it("production + unix socket → allowed", () => {
33 expect(() =>
34 assertScannerConfigured(env({ NODE_ENV: "production", CLAMD_SOCKET: "/run/clamav/clamd.sock" }))
35 ).not.toThrow();
36 });
37
38 it("production + TCP host → allowed", () => {
39 expect(() =>
40 assertScannerConfigured(env({ NODE_ENV: "production", CLAMAV_HOST: "clamav" }))
41 ).not.toThrow();
42 });
43});
44