- Extract auth DTOs, cookie/JWT helpers and the generic duration parser. - Configure the session cookie and map domain auth failures to HTTP responses. - Add typed Swagger responses and focused regression coverage.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
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<string, string | undefined>();
|
|
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);
|
|
});
|
|
});
|