Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142import { describe, expect, it } from "vitest";import metadata, { loopbackClientId, loopbackScope } from "$lib/oauth-client-metadata";
const KNOT_WRITE_LXMS = [ "com.atproto.repo.createRecord", "com.atproto.repo.putRecord", "com.atproto.repo.deleteRecord", "com.atproto.repo.uploadBlob", "sh.tangled.repo.pull.merge"] as const;
describe("oauth client scope", () => { it("grants any-audience RPC scopes for every lxm used in knot writes", () => { const granted = new Set(metadata.scope.split(" ")); for (const lxm of KNOT_WRITE_LXMS) { expect( granted.has(`rpc:${lxm}?aud=*`), `The grant must include rpc:${lxm}?aud=* or the PDS rejects tokens minted for it.` ).toBe(true); } });
it("grants repo scope over org.tangled.graph.attestation", () => { expect(metadata.scope.split(" ")).toContain("repo:org.tangled.graph.attestation"); });});
describe("loopbackClientId", () => { it("keeps authorize URLs within chromium's referrer length limit", () => { const url = new URL("https://tngl.sh/oauth/authorize"); url.searchParams.set( "client_id", loopbackClientId("http://127.0.0.1:5173/oauth/callback", loopbackScope) ); url.searchParams.set( "request_uri", `urn:ietf:params:oauth:request_uri:req-${"0".repeat(32)}` ); expect(url.href.length).toBeLessThanOrEqual(4096); });});