const { test } = require("node:test"); const assert = require("node:assert"); const crypto = require("node:crypto"); const { encrypt, decrypt } = require("../src/lib/tokenCrypto"); const KEY_HEX = crypto.randomBytes(32).toString("hex"); test("encrypt then decrypt returns the original plain text", () => { const plain = "sample-access-token-value"; const encrypted = encrypt(plain, KEY_HEX); assert.notStrictEqual(encrypted, plain); assert.strictEqual(decrypt(encrypted, KEY_HEX), plain); }); test("encrypt output contains iv, authTag, cipherText separated by colons", () => { const encrypted = encrypt("abc", KEY_HEX); const parts = encrypted.split(":"); assert.strictEqual(parts.length, 3); }); test("decrypt throws when the key does not match", () => { const encrypted = encrypt("abc", KEY_HEX); const otherKey = crypto.randomBytes(32).toString("hex"); assert.throws(() => decrypt(encrypted, otherKey)); });