Skip to content

Commit 5427350

Browse files
committed
test: zero call timestamps before checking that Capacitor secrets are masked
The Capacitor redaction tests checked that the serialized calls never contain 1234, but a startedAt such as 1794072512340 contains those digits too, which failed Test coverage on this branch at random. The checks now zero startedAt and durationMs first, so they still cover every argument and result.
1 parent 535fa05 commit 5427350

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎packages/devtools/src/__tests__/capacitor-collector.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ describe('createCapacitorHook', () => {
242242
});
243243
await settle();
244244

245-
const text = JSON.stringify(hook.calls());
245+
// Timing fields are zeroed, since a timestamp can contain the digits too.
246+
const text = JSON.stringify(
247+
hook.calls().map((call) => ({ ...call, startedAt: 0, durationMs: 0 })),
248+
);
246249
expect(text).not.toContain('hunter2');
247250
expect(text).not.toContain('1234');
248251
expect(text).not.toContain(jwt);

‎packages/devtools/src/__tests__/capacitor-core-native-early.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ it('installed before core on Android, logs native calls once, as native, and kno
5858
]);
5959
expect(nativePromise).toHaveBeenCalledTimes(2);
6060
// `pin` is a configured secret name: the value under it is masked both ways.
61-
expect(JSON.stringify(hook.calls())).not.toContain('1234');
61+
// Timing fields are zeroed, since a timestamp can contain the digits too.
62+
const untimed = hook.calls().map((call) => ({ ...call, startedAt: 0, durationMs: 0 }));
63+
expect(JSON.stringify(untimed)).not.toContain('1234');
6264

6365
const plugins = readCapacitorInfo(globalThis as HookWindow)?.plugins ?? [];
6466
expect(plugins.find((p) => p.name === 'Preferences')?.registered).toBe(true);

0 commit comments

Comments
 (0)