From 42e16a6e120b6e5d49a6b0d77c0df924b527ba8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sat, 1 Aug 2026 19:35:16 +0200 Subject: [PATCH] Stop the plaintext-waveform check passing on a coincidence It asserted the stored ciphertext does not contain each sample rendered as a string. Base64 is full of digits, so a short sample value like 3 matches by accident: the check failed on a mutation that had nothing to do with encryption, and would equally have passed while leaking. It now asserts the column holds the keyId.base64 envelope and nothing else, which a serialised sample array cannot satisfy. --- tests/integration/ecg-ingest-roundtrip.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/integration/ecg-ingest-roundtrip.test.ts b/tests/integration/ecg-ingest-roundtrip.test.ts index bb2d6cb38..94a104947 100644 --- a/tests/integration/ecg-ingest-roundtrip.test.ts +++ b/tests/integration/ecg-ingest-roundtrip.test.ts @@ -194,10 +194,13 @@ describe("POST /api/insights/ecg — round trip through the real routes", () => where: { id: posted.data.id }, }); const stored = Buffer.from(row.waveformEncrypted).toString("utf8"); - for (const sample of SAMPLES) { - expect(stored).not.toContain(String(sample)); - } - expect(stored).not.toContain("[12,-7,3"); + // The column holds the `.` envelope and nothing else. A + // serialised sample array cannot satisfy that shape — it carries + // brackets, commas and minus signs — so this rules plaintext out without + // asking whether some digit happens to appear in a base64 blob, which it + // routinely does. + expect(stored).toMatch(/^[A-Za-z0-9_-]+\.[A-Za-z0-9+/=]+$/); + expect(stored).not.toContain(JSON.stringify(SAMPLES)); }); it("reports a re-post as updated and does not grow the table", async () => {