(query: string | null, header: boolean)
| 38 | const cases: Array<{ surface: string; carrier: string; status: number }> = []; |
| 39 | for (const surface of ["api", "mcp"]) { |
| 40 | const send = async (query: string | null, header: boolean) => { |
| 41 | const url = new URL(surface === "api" ? "/api/policies" : "/mcp", target.baseUrl); |
| 42 | if (query) url.searchParams.set(query, key.value); |
| 43 | const response = await fetch(url, { |
| 44 | method: surface === "api" ? "GET" : "POST", |
| 45 | headers: { |
| 46 | accept: "application/json, text/event-stream", |
| 47 | "content-type": "application/json", |
| 48 | ...(header ? { authorization: `Bearer ${key.value}` } : {}), |
| 49 | }, |
| 50 | ...(surface === "mcp" |
| 51 | ? { |
| 52 | body: JSON.stringify({ |
| 53 | jsonrpc: "2.0", |
| 54 | id: 1, |
| 55 | method: "initialize", |
| 56 | params: { |
| 57 | protocolVersion: "2025-03-26", |
| 58 | capabilities: {}, |
| 59 | clientInfo: { name: "authentication-evidence", version: "1" }, |
| 60 | }, |
| 61 | }), |
| 62 | } |
| 63 | : {}), |
| 64 | }); |
| 65 | await response.text(); |
| 66 | cases.push({ |
| 67 | surface, |
| 68 | carrier: query ?? "Authorization header", |
| 69 | status: response.status, |
| 70 | }); |
| 71 | return response.status; |
| 72 | }; |
| 73 | expect(await send(null, true), `${surface} accepts the valid header credential`).toBe(200); |
| 74 | for (const query of [ |
| 75 | "api_key", |
no test coverage detected