Feature: homepage MCP (#6771)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled

This commit is contained in:
shamoon
2026-06-18 23:34:58 -07:00
committed by GitHub
parent b11f3f0c4d
commit 7c5e34503d
10 changed files with 1501 additions and 4 deletions
+20 -2
View File
@@ -18,11 +18,14 @@ async function loadMiddleware() {
return mod.middleware;
}
function createReq(host = "localhost:3000", url = "http://localhost:3000/") {
function createReq(host = "localhost:3000", url = "http://localhost:3000/", headers = {}) {
return {
url,
headers: {
get: (key) => (key === "host" ? host : null),
get: (key) => {
if (key === "host") return host;
return headers[key] ?? null;
},
},
};
}
@@ -127,4 +130,19 @@ describe("middleware", () => {
expect(NextResponse.next).toHaveBeenCalled();
expect(res).toEqual({ type: "next" });
});
it("allows MCP requests with a bearer token when auth is enabled", async () => {
process.env.HOMEPAGE_AUTH_ENABLED = "true";
process.env.HOMEPAGE_AUTH_SECRET = "secret";
process.env.HOMEPAGE_MCP_TOKEN = "mcp-secret";
const middleware = await loadMiddleware();
const res = await middleware(
createReq("localhost:3000", "http://localhost:3000/api/mcp", { authorization: "Bearer mcp-secret" }),
);
expect(getToken).not.toHaveBeenCalled();
expect(NextResponse.next).toHaveBeenCalled();
expect(res).toEqual({ type: "next" });
});
});