19 lines
732 B
TypeScript
19 lines
732 B
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { decryptJson, encryptJson, hmacHex, safeEqual } from "../src/security";
|
|
|
|
describe("security helpers", () => {
|
|
test("encrypts and decrypts gateway configuration", () => {
|
|
const value = { appId: "demo", privateKey: "secret" };
|
|
const encrypted = encryptJson(value);
|
|
expect(encrypted).not.toContain("secret");
|
|
expect(decryptJson(encrypted)).toEqual(value);
|
|
});
|
|
|
|
test("creates deterministic HMAC and constant-time comparison", () => {
|
|
const signature = hmacHex("key", "message");
|
|
expect(signature).toHaveLength(64);
|
|
expect(safeEqual(signature, signature)).toBe(true);
|
|
expect(safeEqual(signature, signature.slice(1))).toBe(false);
|
|
});
|
|
});
|