Stop the tamper test from tampering with its own prefix

This commit is contained in:
2026-10-23 06:10:41 +01:00
parent eb29e2bca9
commit 017e1cb988
+7 -2
View File
@@ -42,7 +42,12 @@ describe("encrypt/decrypt", () => {
test("decrypt fails on tampered input", async () => { test("decrypt fails on tampered input", async () => {
const encrypted = await encrypt("secret"); const encrypted = await encrypt("secret");
const tampered = "A" + encrypted.slice(1); // Flip the first character to one it is not, so the ciphertext is
expect(async () => await decrypt(tampered)).toThrow(); // always different: prefixing "A" left it untouched whenever the
// base64 happened to start with "A".
const first = encrypted[0] === "A" ? "B" : "A";
const tampered = first + encrypted.slice(1);
expect(tampered).not.toBe(encrypted);
await expect(decrypt(tampered)).rejects.toThrow();
}); });
}); });