41 lines · 2.6 KB · TypeScriptRaw
/** * CIRCLE GAPS 1 (28 Nov 2026): the Circle is the person's own. An assistant's token, a plain one (an OAuth * connection, no allow list) or an allow-list key, never adds, accepts, removes, blocks, invites, redeems, sends or * shares on their behalf, and never reads who is in it; the person's own phone still does. Every name is invented. */import { env, runInDurableObject } from "cloudflare:test";import { describe, expect, it } from "vitest";import { http, mint, personalObject } from "./personal.ts";const ROUTES: [string, string][] = [ ["GET", "/v1/chat/people"], ["POST", "/v1/chat/accept"], ["POST", "/v1/chat/refuse"], ["POST", "/v1/chat/block"], ["POST", "/v1/chat/unblock"], ["POST", "/v1/chat/remove"], ["POST", "/v1/chat/discover"], ["POST", "/v1/chat/send"], ["POST", "/v1/chat/circle/invite"], ["POST", "/v1/chat/circle/invite/stop"], ["GET", "/v1/chat/circle/invites"], ["POST", "/v1/chat/circle/redeem"], ["POST", "/v1/invite/send"], ["GET", "/v1/send/people"], ["POST", "/v1/send/make"], ["POST", "/v1/send/trust"], ["GET", "/v1/shared/lists"], ["POST", "/v1/shared/lists"], ["POST", "/v1/shared/list/item"],];async function setSwitch(slug: string, value: string): Promise<void> { await runInDurableObject(env.BUSINESS.get(env.BUSINESS.idFromName(slug)), (instance) => { (instance as unknown as { env: Record<string, unknown> }).env.KEY_DEFAULT = value; });}describe("an assistant in the Circle", () => { it("is refused every Circle, send and share route, plain token or allow-list key; the phone still reads the Circle", async () => { const slug = "circle-assistant"; const { credential } = await personalObject(slug); await setSwitch(slug, "today"); const plain = await mint(slug, credential, "Invented connection", ["owner"], undefined, undefined, null); await setSwitch(slug, "narrow"); const listed = await mint(slug, credential, "Invented key", ["owner"]); for (const token of [plain, listed]) { for (const [method, path] of ROUTES) { const answer = await http<{ error?: string }>(slug, method, path, method === "GET" ? undefined : { number: "+15550100001", code: "x", id: "x" }, { authorization: `Bearer ${token}` }); expect(answer.status, `${method} ${path}: ${JSON.stringify(answer.body)}`).toBe(403); expect(JSON.stringify(answer.body), `${method} ${path}`).toContain("circle_is_theirs"); } } const phone = await http(slug, "GET", "/v1/chat/people", undefined, { authorization: `Bearer ${credential}` }); expect(phone.status, JSON.stringify(phone.body)).toBe(200); });});