Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -49,6 +49,27 @@ describe("@hivegrid/logger", () => {
|
||||
expect(sink.records[0]).not.toHaveProperty("hostname");
|
||||
});
|
||||
|
||||
it("passes sanitized arguments through a caller log hook", () => {
|
||||
const sink = createLogSink();
|
||||
let hookCalls = 0;
|
||||
const logger = createLogger({
|
||||
level: "info",
|
||||
stream: sink.stream,
|
||||
hooks: {
|
||||
logMethod(args, method) {
|
||||
hookCalls += 1;
|
||||
method.apply(this, args);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
logger.info({ requestId: "req-hook", token: "raw-hook-token" }, "hooked");
|
||||
|
||||
expect(hookCalls).toBe(1);
|
||||
expect(sink.records[0]).toMatchObject({ requestId: "req-hook", token: "[Redacted]", msg: "hooked" });
|
||||
expect(JSON.stringify(sink.records[0])).not.toContain("raw-hook-token");
|
||||
});
|
||||
|
||||
it("creates child loggers with runtime bindings", () => {
|
||||
const sink = createLogSink();
|
||||
const logger = createLogger({ level: "info", stream: sink.stream });
|
||||
@@ -93,13 +114,13 @@ describe("@hivegrid/logger", () => {
|
||||
connectionString: rawSecrets[7],
|
||||
},
|
||||
},
|
||||
"secret payload",
|
||||
"secret payload"
|
||||
);
|
||||
|
||||
expect(sink.records).toHaveLength(1);
|
||||
expect(sink.records[0]).toMatchObject({
|
||||
authorization: "[Redacted]",
|
||||
headers: { cookie: "[Redacted]" },
|
||||
headers: "[Redacted]",
|
||||
password: "[Redacted]",
|
||||
nested: {
|
||||
token: "[Redacted]",
|
||||
@@ -131,7 +152,7 @@ describe("@hivegrid/logger", () => {
|
||||
requestId: "req_correlation_1",
|
||||
nested: { secret: "nested-secret", requestId: "req_nested_1" },
|
||||
},
|
||||
"correlated event",
|
||||
"correlated event"
|
||||
);
|
||||
|
||||
expect(sink.records).toHaveLength(1);
|
||||
@@ -151,4 +172,96 @@ describe("@hivegrid/logger", () => {
|
||||
expect(serializedRecord).not.toContain("Bearer request-token");
|
||||
expect(serializedRecord).not.toContain("nested-secret");
|
||||
});
|
||||
|
||||
it("recursively redacts PII, nested payloads, URL queries, and secret text", () => {
|
||||
const sink = createLogSink();
|
||||
const logger = createLogger({ level: "info", stream: sink.stream });
|
||||
|
||||
logger.error(
|
||||
{
|
||||
clientIp: "203.0.113.42",
|
||||
email: "alice@example.test",
|
||||
nested: {
|
||||
deeper: {
|
||||
payload: { safe: false, password: "raw-password" },
|
||||
url: "https://example.test/reset?token=raw-token#private",
|
||||
},
|
||||
},
|
||||
err: new Error("request failed with Bearer raw-bearer and redis://user:secret@cache.example/0"),
|
||||
},
|
||||
"provider token=raw-message-token failed at https://example.test/path?email=alice@example.test"
|
||||
);
|
||||
|
||||
const serialized = JSON.stringify(sink.records[0]);
|
||||
for (const sensitive of [
|
||||
"203.0.113.42",
|
||||
"alice@example.test",
|
||||
"raw-password",
|
||||
"raw-token",
|
||||
"raw-bearer",
|
||||
"redis://user:secret@cache.example/0",
|
||||
"raw-message-token",
|
||||
]) {
|
||||
expect(serialized).not.toContain(sensitive);
|
||||
}
|
||||
expect(sink.records[0]?.nested).toEqual({
|
||||
deeper: {
|
||||
payload: "[Redacted]",
|
||||
url: "https://example.test/reset",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("bounds circular, deeply nested, oversized, and wide log values", () => {
|
||||
const sink = createLogSink();
|
||||
const logger = createLogger({ level: "info", stream: sink.stream });
|
||||
const circular: Record<string, unknown> = {};
|
||||
circular.self = circular;
|
||||
const wide = Object.fromEntries(Array.from({ length: 120 }, (_, index) => [`key${index}`, index]));
|
||||
|
||||
logger.info({ circular, huge: "x".repeat(9 * 1024), wide }, "bounded");
|
||||
|
||||
const record = sink.records[0] as Record<string, unknown>;
|
||||
expect(record.circular).toEqual({ self: "[Circular]" });
|
||||
expect(record.huge).toMatch(/^<string truncated/);
|
||||
expect((record.wide as Record<string, unknown>).__omittedEntries).toBe(20);
|
||||
});
|
||||
|
||||
it("sanitizes recursive edge types and bounds arrays and depth", () => {
|
||||
const sink = createLogSink();
|
||||
const logger = createLogger({ level: "info", stream: sink.stream });
|
||||
const deep: Record<string, unknown> = {};
|
||||
let cursor = deep;
|
||||
for (let index = 0; index < 10; index += 1) {
|
||||
const next: Record<string, unknown> = {};
|
||||
cursor.next = next;
|
||||
cursor = next;
|
||||
}
|
||||
const errorWithoutStack = new Error("token=raw-error-token");
|
||||
errorWithoutStack.stack = undefined;
|
||||
|
||||
logger.info(
|
||||
{
|
||||
binary: Buffer.from("private bytes"),
|
||||
createdAt: new Date("2026-07-12T10:00:00.000Z"),
|
||||
deep,
|
||||
errorWithoutStack,
|
||||
malformed: { url: "http://[::1?token=raw-url-token" },
|
||||
relative: { url: "/private/path?token=raw-relative-token#fragment" },
|
||||
values: Array.from({ length: 102 }, (_, index) => index),
|
||||
},
|
||||
"edge values"
|
||||
);
|
||||
|
||||
const record = sink.records[0] as Record<string, unknown>;
|
||||
expect(record.binary).toBe("[Buffer 13 bytes]");
|
||||
expect(record.createdAt).toBe("2026-07-12T10:00:00.000Z");
|
||||
expect(JSON.stringify(record.deep)).toContain("[MaxDepth]");
|
||||
expect(record.errorWithoutStack).toEqual({ name: "Error", message: "[Redacted]" });
|
||||
expect(record.relative).toEqual({ url: "/private/path" });
|
||||
expect(JSON.stringify(record.malformed)).not.toContain("raw-url-token");
|
||||
const values = record.values as unknown[];
|
||||
expect(values).toHaveLength(101);
|
||||
expect(values.at(-1)).toBe("[2 entries omitted]");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user