test(config): dedupe nested redaction round-trip assertions

This commit is contained in:
Peter Steinberger
2026-02-21 23:17:01 +00:00
parent 71c17da2ba
commit 271999d42a

View File

@@ -392,6 +392,32 @@ describe("redactConfigSnapshot", () => {
});
it("round-trips nested and array sensitivity cases", () => {
const customSecretValue = "this-is-a-custom-secret-value";
const buildNestedValuesSnapshot = () =>
makeSnapshot({
custom1: { anykey: { mySecret: customSecretValue } },
custom2: [{ mySecret: customSecretValue }],
});
const assertNestedValuesRoundTrip = ({
redacted,
restored,
}: {
redacted: Record<string, unknown>;
restored: Record<string, unknown>;
}) => {
const cfg = redacted as Record<string, Record<string, unknown>>;
const cfgCustom2 = cfg.custom2 as unknown as unknown[];
expect(cfgCustom2.length).toBeGreaterThan(0);
expect((cfg.custom1.anykey as Record<string, unknown>).mySecret).toBe(REDACTED_SENTINEL);
expect((cfgCustom2[0] as Record<string, unknown>).mySecret).toBe(REDACTED_SENTINEL);
const out = restored as Record<string, Record<string, unknown>>;
const outCustom2 = out.custom2 as unknown as unknown[];
expect(outCustom2.length).toBeGreaterThan(0);
expect((out.custom1.anykey as Record<string, unknown>).mySecret).toBe(customSecretValue);
expect((outCustom2[0] as Record<string, unknown>).mySecret).toBe(customSecretValue);
};
const cases: Array<{
name: string;
snapshot: TestSnapshot<Record<string, unknown>>;
@@ -403,28 +429,8 @@ describe("redactConfigSnapshot", () => {
}> = [
{
name: "nested values (schema)",
snapshot: makeSnapshot({
custom1: { anykey: { mySecret: "this-is-a-custom-secret-value" } },
custom2: [{ mySecret: "this-is-a-custom-secret-value" }],
}),
assert: ({ redacted, restored }) => {
const cfg = redacted;
const cfgCustom2 = Array.isArray(cfg.custom2) ? cfg.custom2 : [];
expect(cfgCustom2.length).toBeGreaterThan(0);
expect(
((cfg.custom1 as Record<string, unknown>).anykey as Record<string, unknown>).mySecret,
).toBe(REDACTED_SENTINEL);
expect((cfgCustom2[0] as Record<string, unknown>).mySecret).toBe(REDACTED_SENTINEL);
const out = restored;
const outCustom2 = Array.isArray(out.custom2) ? out.custom2 : [];
expect(outCustom2.length).toBeGreaterThan(0);
expect(
((out.custom1 as Record<string, unknown>).anykey as Record<string, unknown>).mySecret,
).toBe("this-is-a-custom-secret-value");
expect((outCustom2[0] as Record<string, unknown>).mySecret).toBe(
"this-is-a-custom-secret-value",
);
},
snapshot: buildNestedValuesSnapshot(),
assert: assertNestedValuesRoundTrip,
},
{
name: "nested values (uiHints)",
@@ -432,28 +438,8 @@ describe("redactConfigSnapshot", () => {
"custom1.*.mySecret": { sensitive: true },
"custom2[].mySecret": { sensitive: true },
},
snapshot: makeSnapshot({
custom1: { anykey: { mySecret: "this-is-a-custom-secret-value" } },
custom2: [{ mySecret: "this-is-a-custom-secret-value" }],
}),
assert: ({ redacted, restored }) => {
const cfg = redacted;
const cfgCustom2 = Array.isArray(cfg.custom2) ? cfg.custom2 : [];
expect(cfgCustom2.length).toBeGreaterThan(0);
expect(
((cfg.custom1 as Record<string, unknown>).anykey as Record<string, unknown>).mySecret,
).toBe(REDACTED_SENTINEL);
expect((cfgCustom2[0] as Record<string, unknown>).mySecret).toBe(REDACTED_SENTINEL);
const out = restored;
const outCustom2 = Array.isArray(out.custom2) ? out.custom2 : [];
expect(outCustom2.length).toBeGreaterThan(0);
expect(
((out.custom1 as Record<string, unknown>).anykey as Record<string, unknown>).mySecret,
).toBe("this-is-a-custom-secret-value");
expect((outCustom2[0] as Record<string, unknown>).mySecret).toBe(
"this-is-a-custom-secret-value",
);
},
snapshot: buildNestedValuesSnapshot(),
assert: assertNestedValuesRoundTrip,
},
{
name: "directly sensitive records and arrays",