Menu
popagent
publicLatest change 6edc7e928c57dab23c0973ed3f7ee70b3ebb72d5 - Initial popagent baseline by AkurAI Build
import { afterEach, describe, expect, test } from "bun:test";
import { requireApiKey } from "./auth";
describe("requireApiKey", () => {
afterEach(() => {
delete process.env.POPAGENT_API_KEY;
});
test("allows when key is unset", () => {
expect(requireApiKey(new Request("http://localhost/api/models"))).toBeUndefined();
});
test("rejects missing or wrong keys", () => {
process.env.POPAGENT_API_KEY = "test-key";
expect(requireApiKey(new Request("http://localhost/api/models"))?.status).toBe(401);
expect(requireApiKey(new Request("http://localhost/api/models", { headers: { "x-popagent-key": "wrong" } }))?.status).toBe(401);
});
test("accepts the configured key", () => {
process.env.POPAGENT_API_KEY = "test-key";
expect(requireApiKey(new Request("http://localhost/api/models", { headers: { "x-popagent-key": "test-key" } }))).toBeUndefined();
});
});