diff --git a/src/config/redact-snapshot.test.ts b/src/config/redact-snapshot.test.ts index 84b03c2e76b..95b26ecaebf 100644 --- a/src/config/redact-snapshot.test.ts +++ b/src/config/redact-snapshot.test.ts @@ -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; + restored: Record; + }) => { + const cfg = redacted as Record>; + const cfgCustom2 = cfg.custom2 as unknown as unknown[]; + expect(cfgCustom2.length).toBeGreaterThan(0); + expect((cfg.custom1.anykey as Record).mySecret).toBe(REDACTED_SENTINEL); + expect((cfgCustom2[0] as Record).mySecret).toBe(REDACTED_SENTINEL); + + const out = restored as Record>; + const outCustom2 = out.custom2 as unknown as unknown[]; + expect(outCustom2.length).toBeGreaterThan(0); + expect((out.custom1.anykey as Record).mySecret).toBe(customSecretValue); + expect((outCustom2[0] as Record).mySecret).toBe(customSecretValue); + }; + const cases: Array<{ name: string; snapshot: TestSnapshot>; @@ -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).anykey as Record).mySecret, - ).toBe(REDACTED_SENTINEL); - expect((cfgCustom2[0] as Record).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).anykey as Record).mySecret, - ).toBe("this-is-a-custom-secret-value"); - expect((outCustom2[0] as Record).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).anykey as Record).mySecret, - ).toBe(REDACTED_SENTINEL); - expect((cfgCustom2[0] as Record).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).anykey as Record).mySecret, - ).toBe("this-is-a-custom-secret-value"); - expect((outCustom2[0] as Record).mySecret).toBe( - "this-is-a-custom-secret-value", - ); - }, + snapshot: buildNestedValuesSnapshot(), + assert: assertNestedValuesRoundTrip, }, { name: "directly sensitive records and arrays",