mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 05:40:22 +00:00
Merged via squash.
Prepared head SHA: 07ec5b77b1
Co-authored-by: solodmd <51304754+solodmd@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { REDACTED_SENTINEL } from "./redact-snapshot.js";
|
|
import { replaceSensitiveValuesInRaw } from "./redact-snapshot.raw.js";
|
|
|
|
describe("replaceSensitiveValuesInRaw", () => {
|
|
it("ignores empty string replacement tokens", () => {
|
|
const raw = '{ "gateway": { "auth": { "token": "" } }, "other": "" }';
|
|
|
|
const result = replaceSensitiveValuesInRaw({
|
|
raw,
|
|
sensitiveValues: [""],
|
|
redactedSentinel: REDACTED_SENTINEL,
|
|
});
|
|
|
|
expect(result).toBe(raw);
|
|
});
|
|
|
|
it("redacts non-empty values while preserving blank strings", () => {
|
|
const raw = '{ "token": "", "secret": "abc123", "other": "" }';
|
|
|
|
const result = replaceSensitiveValuesInRaw({
|
|
raw,
|
|
sensitiveValues: ["", "abc123"],
|
|
redactedSentinel: REDACTED_SENTINEL,
|
|
});
|
|
|
|
expect(result).toContain('"token": ""');
|
|
expect(result).toContain('"other": ""');
|
|
expect(result).not.toContain("abc123");
|
|
expect(result).toContain(REDACTED_SENTINEL);
|
|
});
|
|
|
|
it("replaces longest values first for overlapping matches", () => {
|
|
const raw = '{ "token": "abcd", "prefix": "ab" }';
|
|
|
|
const result = replaceSensitiveValuesInRaw({
|
|
raw,
|
|
sensitiveValues: ["ab", "abcd", "abcd"],
|
|
redactedSentinel: REDACTED_SENTINEL,
|
|
});
|
|
|
|
expect(result).toBe(`{ "token": "${REDACTED_SENTINEL}", "prefix": "${REDACTED_SENTINEL}" }`);
|
|
});
|
|
});
|