chore: Encyrpted.test.ts flaky test (#13169)

This commit is contained in:
Tom Moor
2026-07-27 18:50:23 -04:00
committed by GitHub
parent 8cdd2895a3
commit 715694684c
+17 -3
View File
@@ -1,3 +1,4 @@
import { errToString } from "@shared/utils/error";
import env from "@server/env";
import { encrypt, decrypt } from "./Encrypted";
@@ -40,10 +41,23 @@ describe("Encrypted", () => {
expect(encrypt(value).equals(encrypt(value))).toBe(false);
});
it("should fail to decrypt tampered data", () => {
const encrypted = encrypt(JSON.stringify("hello world"));
it("should not return the original value for tampered data", () => {
const value = JSON.stringify("hello world");
const encrypted = encrypt(value);
encrypted[encrypted.length - 1] ^= 0xff;
expect(() => decrypt(encrypted)).toThrow();
try {
expect(decrypt(encrypted)).not.toEqual(value);
} catch (err) {
expect(errToString(err)).toMatch(/bad decrypt/);
}
});
it("should fail to decrypt a truncated ciphertext", () => {
const encrypted = encrypt(JSON.stringify("hello world"));
expect(() =>
decrypt(encrypted.subarray(0, encrypted.length - 1))
).toThrow();
});
it("should fail to decrypt with a different key", () => {