Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(mock-api): assert ngrok-skip-browser-warning is CORS-allowed

Steven Enamakelbd102831dbc1
diff --git a/scripts/mock-api/http.test.mjs b/scripts/mock-api/http.test.mjs
index 869fc6cf66..d622ecf620 100644
--- a/scripts/mock-api/http.test.mjs
+++ b/scripts/mock-api/http.test.mjs
@@ -18,4 +18,7 @@ test("CORS allows every product identity header used by browser requests", () =>
.map(header => header.trim().toLowerCase());
assert.ok(allowedHeaders.includes("x-sdk-name"));
assert.ok(allowedHeaders.includes("x-web-version"));
+ // Dev builds send it on every backend request (services/apiClient.ts);
+ // without it a browser dev build fails every preflight to the mock.
+ assert.ok(allowedHeaders.includes("ngrok-skip-browser-warning"));
});
diff --git a/scripts/mock-api/routes/__tests__/auth.test.mjs b/scripts/mock-api/routes/__tests__/auth.test.mjs
new file mode 100644
index 0000000000..38ea7b026f
--- /dev/null
+++ b/scripts/mock-api/routes/__tests__/auth.test.mjs
@@ -0,0 +1,59 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { resetMockBehavior, startMockServer, stopMockServer } from "../../index.mjs";
+import { loopbackSignInRedirect } from "../auth.mjs";
+import { MOCK_JWT } from "../../state.mjs";
+
+test.beforeEach(async () => {
+ await stopMockServer();
+ resetMockBehavior();
+});
+
+test.afterEach(async () => {
+ await stopMockServer();
+});
+
+test("signs a loopback redirectUri back in with a session JWT and the echoed state", () => {
+ const location = loopbackSignInRedirect(
+ "/auth/github/login?redirectUri=http%3A%2F%2Flocalhost%3A1420%2F__dev-auth&state=nonce-1",
+ );
+ const target = new URL(location);
+ assert.equal(target.origin + target.pathname, "http://localhost:1420/__dev-auth");
+ assert.equal(target.searchParams.get("token"), MOCK_JWT);
+ assert.equal(target.searchParams.get("key"), "auth");
+ assert.equal(target.searchParams.get("state"), "nonce-1");
+});
+
+test("ignores a missing, non-loopback or non-http redirectUri", () => {
+ assert.equal(loopbackSignInRedirect("/auth/github/login"), null);
+ assert.equal(
+ loopbackSignInRedirect("/auth/github/login?redirectUri=http%3A%2F%2Fevil.example%2Fcb"),
+ null,
+ );
+ assert.equal(
+ loopbackSignInRedirect("/auth/github/login?redirectUri=openhuman%3A%2F%2Fauth"),
+ null,
+ );
+});
+
+test("serves the provider-login redirect and the /health probe", async () => {
+ const started = await startMockServer(18576, { retryIfInUse: true });
+ const baseUrl = `http://127.0.0.1:${started.port}`;
+
+ const login = await fetch(
+ `${baseUrl}/auth/github/login?redirectUri=${encodeURIComponent("http://127.0.0.1:5173/__dev-auth")}`,
+ { redirect: "manual" },
+ );
+ assert.equal(login.status, 302);
+ assert.match(login.headers.get("location"), /^http:\/\/127\.0\.0\.1:5173\/__dev-auth\?token=/);
+
+ // Without a redirectUri the legacy mock-oauth page is unchanged.
+ const legacy = await fetch(`${baseUrl}/auth/github/login`, { redirect: "manual" });
+ assert.equal(legacy.status, 302);
+ assert.equal(legacy.headers.get("location"), `${baseUrl}/mock-oauth`);
+
+ const health = await fetch(`${baseUrl}/health`);
+ assert.equal(health.status, 200);
+ assert.deepEqual(await health.json(), { status: "ok" });
+});