Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

test(cloud-send): pin team-refusal/move-scope wrapper behavior

Prit Patel71dfb9990c35
diff --git a/server/routes/cloud-send.test.ts b/server/routes/cloud-send.test.ts
index ef28f56926..240d70f472 100644
--- a/server/routes/cloud-send.test.ts
+++ b/server/routes/cloud-send.test.ts
@@ -76,3 +76,71 @@ describe("what a move asks of a server", () => {
expect(other.body.secrets["login:example.test|alice"]).not.toBe(answered.body.secrets["login:example.test|alice"]);
});
});
+
+describe("cloud-send outer wrapper gating", () => {
+ const teamRefusal = { error: "A team server does not accept inbound moves." };
+
+ it("returns 403 refusal on team server when request is not scoped to a bot move", async () => {
+ let answered: { status: number; body: unknown } | undefined;
+ const req = { resume() {} };
+ const res = { setHeader() {} };
+ const route = createCloudSendRoutes({
+ appVersion: "0.1.120",
+ bots: () => [{ id: "bot-00000001", threadId: "thread-0001", name: "Yuki" } as never],
+ messagesTail: () => ({ messages: [], hasMore: false }),
+ skills: () => [],
+ logins: { listSecrets: () => [], secret: () => null, changes: () => [], get: () => null, onePasswordConnectedAt: () => null, onePasswordGrants: () => ({}), onePasswordItemGrants: () => ({}), onePasswordToken: () => null },
+ config: () => ({}),
+ refusal: teamRefusal,
+ scope: () => null,
+ });
+
+ await route({
+ path: "/api/cloud-send",
+ method: "GET",
+ url: new URL("http://127.0.0.1/api/cloud-send"),
+ req: req as never,
+ res: res as never,
+ auth: { kind: "session", email: "[email protected]" } as never,
+ json: (_res: unknown, status: number, value: unknown) => {
+ answered = { status, body: value };
+ },
+ readBody: async () => null,
+ } as never);
+
+ expect(answered?.status).toBe(403);
+ expect(answered?.body).toEqual(teamRefusal);
+ });
+
+ it("permits dispatch past team refusal when request has a scoped bot move session", async () => {
+ let answered: { status: number; body: unknown } | undefined;
+ const req = { resume() {} };
+ const res = { setHeader() {} };
+ const route = createCloudSendRoutes({
+ appVersion: "0.1.120",
+ bots: () => [{ id: "bot-00000001", threadId: "thread-0001", name: "Yuki", soul: "" } as never],
+ messagesTail: () => ({ messages: [], hasMore: false }),
+ skills: () => [],
+ logins: { listSecrets: () => [], secret: () => null, changes: () => [], get: () => null, onePasswordConnectedAt: () => null, onePasswordGrants: () => ({}), onePasswordItemGrants: () => ({}), onePasswordToken: () => null },
+ config: () => ({}),
+ refusal: teamRefusal,
+ scope: () => "bot-00000001",
+ });
+
+ await route({
+ path: "/api/cloud-send",
+ method: "GET",
+ url: new URL("http://127.0.0.1/api/cloud-send"),
+ req: req as never,
+ res: res as never,
+ auth: { kind: "session", email: "[email protected]" } as never,
+ json: (_res: unknown, status: number, value: unknown) => {
+ answered = { status, body: value };
+ },
+ readBody: async () => null,
+ } as never);
+
+ expect(answered?.status).toBe(200);
+ expect((answered?.body as { items: unknown[] })?.items).toBeDefined();
+ });
+});
diff --git a/server/routes/cloud-send.ts b/server/routes/cloud-send.ts
index 64c1033848..420fe848f3 100644
--- a/server/routes/cloud-send.ts
+++ b/server/routes/cloud-send.ts
@@ -85,6 +85,8 @@ export function createCloudSendRoutes(deps: CloudSendRouteDeps): RouteHandler {
if (path !== "/api/cloud-send" && !path.startsWith("/api/cloud-send/")) return PASS;
const home = deps.cloudHome === true || deps.ownHome?.(ctx.auth) === true;
const scoped = deps.scope?.(ctx.auth) ?? null;
+ // Downstream handlers rely on this outer wrapper as the sole gate: team refusal rejects callers unless
+ // scoped to a specific bot move session.
if (deps.refusal && !scoped) { req.resume(); return json(res, 403, deps.refusal); }
// A move of one bot into a team reads that bot only, on both sides.
const bot = scoped ?? (/^[\w-]{1,128}$/u.test(url.searchParams.get("bot") ?? "") ? url.searchParams.get("bot")! : undefined);