Files
kai e3efa97b44
release / which version (push) Successful in 2s
release / olares chart · sanity (push) Successful in 3s
release / app (push) Successful in 58s
release / tag and release (push) Successful in 2s
AI setting with vault, cookbook photo import, text model fallback (26.11.7) (#8)
2026-11-06 22:05:34 +00:00

28 lines
1.0 KiB
TypeScript

import { mkdtempSync, statSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, expect, it, vi } from "vitest";
vi.mock("server-only", () => ({}));
describe("vault", () => {
it("seals and opens, refuses tampering and a foreign key", async () => {
const dir = mkdtempSync(path.join(tmpdir(), "lunch-vault-"));
process.env.APP_DATA_DIR = dir;
const vault = await import("@/lib/vault");
vault.forgetKeyForTests();
const sealed = await vault.seal("sk-geheim");
expect(sealed.toString("utf8")).not.toContain("sk-geheim");
expect(await vault.unseal(sealed)).toBe("sk-geheim");
expect(statSync(path.join(dir, "tresor.key")).mode & 0o777).toBe(0o600);
const tampered = Buffer.from(sealed);
tampered[tampered.length - 1]! ^= 1;
await expect(vault.unseal(tampered)).rejects.toThrow();
writeFileSync(path.join(dir, "tresor.key"), Buffer.alloc(32, 7));
vault.forgetKeyForTests();
await expect(vault.unseal(sealed)).rejects.toThrow();
});
});