Stop the tamper test from tampering with its own prefix
This commit is contained in:
@@ -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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user