import { INestApplication } from "@nestjs/common"; import request from "supertest"; import { buildTestApp } from "./app.harness"; describe("authentication disabled", () => { const envKeys = ["AUTH_ENABLED", "AUTH_JWT_SECRET"] as const; const previousEnv = new Map(); let app: INestApplication; beforeAll(async () => { for (const key of envKeys) previousEnv.set(key, process.env[key]); process.env.AUTH_ENABLED = "false"; delete process.env.AUTH_JWT_SECRET; app = await buildTestApp(); }); afterAll(async () => { await app?.close(); for (const key of envKeys) { const value = previousEnv.get(key); if (value === undefined) delete process.env[key]; else process.env[key] = value; } }); it("starts without a secret and leaves existing REST behavior public", async () => { await request(app.getHttpServer()).get("/scenarios").expect(200); await request(app.getHttpServer()).get("/health").expect(200); const manifest = await request(app.getHttpServer()) .get("/manifest.json") .expect(200); expect(manifest.body.auth).toEqual({ enabled: false }); }); it("returns not found for login while authentication is disabled", async () => { await request(app.getHttpServer()) .post("/auth/login") .send({ username: "nobody", password: "synthetic" }) .expect(404); }); });