forked from NateBJones-Projects/OB1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdual-key-auth.test.ts
More file actions
56 lines (49 loc) · 1.67 KB
/
Copy pathdual-key-auth.test.ts
File metadata and controls
56 lines (49 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { assertEquals } from "jsr:@std/assert@1";
import { app, configureAgentMemoryAppForTest } from "./index.ts";
const NEW_KEY = "test-dedicated-agent-memory-key";
const OLD_KEY = "test-shared-mcp-key";
async function healthStatus(key?: string): Promise<number> {
const headers: Record<string, string> = {};
if (key) headers["x-brain-key"] = key;
const res = await app.fetch(
new Request("http://localhost/health", { headers }),
);
await res.body?.cancel();
return res.status;
}
Deno.test("dual-key: new dedicated key accepted when set", async () => {
configureAgentMemoryAppForTest({
mcpAccessKey: OLD_KEY,
agentMemoryAccessKey: NEW_KEY,
});
assertEquals(await healthStatus(NEW_KEY), 200);
});
Deno.test("dual-key: MCP_ACCESS_KEY fallback still accepted (D1 interim)", async () => {
configureAgentMemoryAppForTest({
mcpAccessKey: OLD_KEY,
agentMemoryAccessKey: NEW_KEY,
});
assertEquals(await healthStatus(OLD_KEY), 200);
});
Deno.test("dual-key: wrong key rejected 401", async () => {
configureAgentMemoryAppForTest({
mcpAccessKey: OLD_KEY,
agentMemoryAccessKey: NEW_KEY,
});
assertEquals(await healthStatus("wrong-key"), 401);
});
Deno.test("dual-key: missing key rejected 401", async () => {
configureAgentMemoryAppForTest({
mcpAccessKey: OLD_KEY,
agentMemoryAccessKey: NEW_KEY,
});
assertEquals(await healthStatus(undefined), 401);
});
Deno.test("dual-key: unset dedicated key preserves MCP-only behavior", async () => {
configureAgentMemoryAppForTest({
mcpAccessKey: OLD_KEY,
agentMemoryAccessKey: "",
});
assertEquals(await healthStatus(OLD_KEY), 200);
assertEquals(await healthStatus(NEW_KEY), 401);
});