mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-07 07:55:47 +01:00
13 lines
5.5 KiB
TypeScript
13 lines
5.5 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { randomUUID } from "node:crypto";
|
|
import { grokOperatorInputMatches, grokOperatorReceiptMatches, grokConsentUrlAllowed, grokCallbackOriginAllowed, type GrokOperatorInput } from "./runtime-grok-operator-contract.js";
|
|
import { runtimePrivateRequirements } from "../chat-runtime-private-requirements.js";
|
|
function input(): GrokOperatorInput { return { operation: "availability", executionId: "chat-features.runner-codex-subscription.local.agents.existing-grok-bot", attemptId: "a".repeat(32), receiptPath: "/owned/private/origin.json", backendOrigin: "http://127.0.0.1:43120", publicOrigin: "https://owned.example.test", companyId: randomUUID(), companyName: "Actual fixture company", prefix: "ACORN", personId: "actual-fixture-user", personName: "Fixture Person", leadId: randomUUID(), botName: "Actual existing Bot", operatorRef: "authorized-operator", botAuthorizationRef: "selected-existing-bot", operatorMode: "interactive-private-ui", publicSession: { cookies: [{ name: "secure-session", value: "synthetic-value", domain: "owned.example.test", path: "/", expires: -1, httpOnly: true, secure: true, sameSite: "Lax" }], origins: [] } }; }
|
|
function receipt(i: GrokOperatorInput) { return { operation: i.operation, executionId: i.executionId, attemptId: i.attemptId, companyId: i.companyId, personId: i.personId, operatorRef: i.operatorRef, botAuthorizationRef: i.botAuthorizationRef, processIsolation: true, testRunnerAttached: false, humanSelectedAuthorizedBot: true, publicPersonMatched: true, privateStorageClean: true, clipboardClean: true } as const; }
|
|
const expected = (i: GrokOperatorInput) => ({ operation: i.operation, executionId: i.executionId, attemptId: i.attemptId, companyId: i.companyId, personId: i.personId, operatorRef: i.operatorRef, botAuthorizationRef: i.botAuthorizationRef });
|
|
it("requires exact selected operator/authorized-Bot fields before admission, not an ambient provider session", () => { expect(runtimePrivateRequirements["agents.existing-grok-bot"].fields).toEqual(["botId", "endpoint", "challengeMethod", "credentialEnvName", "operatorRef", "botAuthorizationRef", "operatorMode"]); expect(grokOperatorInputMatches(input())).toBe(true); const i = input(); for (const change of [{ executionId: "goals.list" }, { attemptId: "wrong" }, { operatorRef: "" }, { botAuthorizationRef: "" }, { publicOrigin: "http://owned.example.test" }, { operatorMode: "simulated" }]) expect(grokOperatorInputMatches({ ...i, ...change } as GrokOperatorInput)).toBe(false); });
|
|
it("rejects loopback/copied foreign or insecure cookies and undeclared provider credentials in availability", () => { const i = input(); expect(grokOperatorInputMatches({ ...i, publicSession: { cookies: [{ ...i.publicSession.cookies[0]!, domain: "127.0.0.1" }], origins: [] } })).toBe(false); expect(grokOperatorInputMatches({ ...i, publicSession: { cookies: [{ ...i.publicSession.cookies[0]!, secure: false }], origins: [] } })).toBe(false); expect(grokOperatorInputMatches({ ...i, webhookKey: "secret-not-needed" })).toBe(false); });
|
|
it("allows only actual same-instance agent consent pages and explicitly reviewed supported callback origins", () => { const origin = "https://owned.example.test", id = randomUUID(); expect(grokConsentUrlAllowed(`${origin}/dot-connect/${id}`, origin)).toBe(true); expect(grokConsentUrlAllowed(`${origin}/mcp-connect/${id}`, origin)).toBe(true); for (const value of [`https://foreign.test/dot-connect/${id}`, `${origin}/auth?next=/`, `${origin}/dot-connect/${id}?code=private`, `${origin}/dot-connect/${id}#secret`, `https://user:pass@owned.example.test/dot-connect/${id}`]) expect(grokConsentUrlAllowed(value, origin)).toBe(false); expect(grokCallbackOriginAllowed("https://grok.example.test")).toBe(true); expect(grokCallbackOriginAllowed("http://127.0.0.1:43199")).toBe(true); for (const value of ["http://remote.example.test", "file:///tmp/fake", "https://user:pass@provider.test", "https://provider.test/path", "null"]) expect(grokCallbackOriginAllowed(value)).toBe(false); });
|
|
it("availability receipt attests presence only, never fake connection or readiness", () => { const i = input(), r = receipt(i); expect(grokOperatorReceiptMatches(r, expected(i))).toBe(true); for (const change of [{ personId: "foreign-user" }, { attemptId: "b".repeat(32) }, { humanSelectedAuthorizedBot: false }, { ready: true }, { pairingCode: "private-never-retain" }, { token: "private" }, { publicPairingConsentSubmitted: true }]) expect(grokOperatorReceiptMatches({ ...r, ...change } as typeof r, expected(i))).toBe(false); });
|
|
it("requires complete scoped human handoff controls but does not accept them as Bot verification", () => { const i = { ...input(), operation: "setup" as const, webhookUrl: "https://selected.example.test/routine", webhookKey: "synthetic-protected-key" }, r = { ...receipt(i), agentId: randomUUID(), bindingId: randomUUID(), productInvitationUi: true, accessInstructionsDelivered: true, routineInstructionsDelivered: true, publicPairingConsentSubmitted: true, publicCompanyAgentMatched: true, clientCallbackApproved: true, pairingCodeConfinedToPublicForm: true } as const; expect(grokOperatorInputMatches(i)).toBe(true); expect(grokOperatorReceiptMatches(r, expected(i))).toBe(true); for (const change of [{ privateStorageClean: false }, { clipboardClean: false }, { clientCallbackApproved: false }, { publicCompanyAgentMatched: false }, { pairingCodeConfinedToPublicForm: false }, { verified: true }]) expect(grokOperatorReceiptMatches({ ...r, ...change } as typeof r, expected(i))).toBe(false); });
|