Files
liqa/server/test/logging.interceptor.spec.ts
T
c0fe15dc01
CI / changes (push) Successful in 4s
CI / server (push) Failing after 1h44m8s
CI / client (push) Successful in 1m52s
CI / image (push) Skipped
Keep test output quiet with opt-in diagnostic logs (#25)
Test runs stay quiet by default. Diagnostic logs can be enabled explicitly when troubleshooting, while normal application logging and saved scenario output remain available.

Resolves #22.

---------

Co-authored-by: ars9 <ars9@pm.me>
Co-authored-by: agent <agent@halstation.halstation.local>
Reviewed-on: #25
Co-authored-by: agent-codex <agent-codex@ars9.space>
2026-11-11 22:23:44 +02:00

63 lines
2.1 KiB
TypeScript

import { CallHandler, ExecutionContext } from "@nestjs/common";
import { of } from "rxjs";
import { DebugLogger } from "../src/common/debug-logger";
import {
LoggingInterceptor,
redactAuthRequestBody,
} from "../src/interceptors/logging.interceptor";
describe("redactAuthRequestBody", () => {
it("redacts login passwords on local and API-prefixed route paths", () => {
const body = { username: "operator", password: "synthetic-secret" };
expect(redactAuthRequestBody("/auth/login", body)).toEqual({
username: "operator",
password: "[REDACTED]",
});
expect(redactAuthRequestBody("/api/v1/auth/login", body)).toEqual({
username: "operator",
password: "[REDACTED]",
});
expect(redactAuthRequestBody("/api/v1/auth/login/", body)).toEqual({
username: "operator",
password: "[REDACTED]",
});
expect(redactAuthRequestBody("/API/V1/AUTH/LOGIN/", body)).toEqual({
username: "operator",
password: "[REDACTED]",
});
expect(redactAuthRequestBody("/api/v1/scenarios", body)).toBe(body);
});
it("never logs a password received on the accepted trailing-slash login path", () => {
const loggedMessages: unknown[][] = [];
const debug = jest
.spyOn(DebugLogger.prototype, "debug")
.mockImplementation((...args: unknown[]) => {
loggedMessages.push(args);
});
const context = {
switchToHttp: () => ({
getRequest: () => ({
method: "POST",
url: "/api/v1/auth/login/",
path: "/api/v1/auth/login/",
body: { username: "operator", password: "synthetic-login-secret" },
}),
getResponse: () => ({ statusCode: 200 }),
}),
} as unknown as ExecutionContext;
const handler = {
handle: () => of({ user: { username: "operator" } }),
} as CallHandler;
try {
new LoggingInterceptor().intercept(context, handler).subscribe();
const output = JSON.stringify(loggedMessages);
expect(output).toContain("[REDACTED]");
expect(output).not.toContain("synthetic-login-secret");
} finally {
debug.mockRestore();
}
});
});