Files
liqa/server/test/logging.interceptor.spec.ts
T
agent 7235abdcef
CI / changes (pull_request) Successful in 6s
CI / server (pull_request) Failing after 34m29s
CI / client (pull_request) Successful in 3m0s
CI / image (pull_request) Skipped
refactor(logging): separate console and debug logger classes
- Preserve TraceLogger console formatting and add DebugLogger with DEBUG namespace output.
- Select the logger through LOG_MODE and route application call sites through the factory.
- Cover factory selection, console formatting, debug output and auth-log redaction.
2026-11-11 14:30:37 -05: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();
}
});
});