Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import { describe, expect, it, vi } from "vitest";import { didOf } from "$lib/api/syntax";import type { OAuthUserAgent } from "@atcute/oauth-browser-client";
vi.mock("$lib/auth/agent", () => ({ createClient: () => ({}), mintServiceAuth: async () => "token", serviceDidForHost: (host: string) => `did:web:${host}`, hostForServiceDid: () => null}));
vi.mock("$lib/api/knot", () => ({ knotCapabilities: async () => null}));
const { addSecret, listSecrets, removeSecret } = await import("$lib/api/secrets");const agent = { sub: "did:plc:nel" } as unknown as OAuthUserAgent;const target = { repoDid: didOf("did:plc:repoproof") };
const spindle = (body: unknown) => { const fetch = vi.fn<typeof globalThis.fetch>( async () => new Response(JSON.stringify(body), { status: 200, headers: { "content-type": "application/json" } }) ); vi.stubGlobal("fetch", fetch); return fetch;};
describe("pipeline secrets", () => { it("asks the repo's spindle over https", async () => { const fetch = spindle({ secrets: [] });
await expect(listSecrets(agent, new URL("https://spindle.test"), target)).resolves.toEqual( [] ); const asked = new URL(String(fetch.mock.calls[0][0])); expect(new Headers(fetch.mock.calls[0][1]?.headers).get("authorization")).toBe( "Bearer token" ); expect(asked.origin).toBe("https://spindle.test"); expect(asked.pathname).toBe("/xrpc/org.tangled.secret.listSecrets"); expect(asked.searchParams.get("repo")).toBe(target.repoDid); });
it("keys writes by the repo did", async () => { const fetch = spindle({});
await addSecret(agent, new URL("https://spindle.test"), target, "API_KEY", "value"); expect(JSON.parse(String(fetch.mock.calls[0][1]?.body))).toEqual({ repo: target.repoDid, key: "API_KEY", value: "value" });
await removeSecret(agent, new URL("https://spindle.test"), target, "API_KEY"); expect(JSON.parse(String(fetch.mock.calls[1][1]?.body))).toEqual({ repo: target.repoDid, key: "API_KEY" }); });});