Something went wrong. Try again.
The logic for serving and storing associations between users and apps
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import { describe, expect, it } from "vitest";import { developersPage } from "./developers";import { landingPage } from "./landing";import { embedPage, exampleRendererJs, savePage, savePageLogout } from "./pages";
describe("landing page", () => { it("explains the Atmosphere hint without becoming a sign-in service", () => { const html = landingPage(); expect(html).toContain("Atmosphere"); expect(html).toContain("#111827"); expect(html).toContain("#15803d"); expect(html).toContain("#FDFCFA"); expect(html).toContain("#57822B"); expect(html).toContain("does not replace the login"); expect(html).toContain("OAuth"); expect(html).toContain("seven days"); expect(html).toContain("Works well in Chrome."); expect(html).toContain("Safari and Firefox ask first."); expect(html).toContain("https://lightbox-loggedin.val.run"); expect(html).toContain("https://cratewalk-loggedin.val.run"); expect(html).toContain("/developers"); expect(html).toContain("Publish client metadata"); expect(html).not.toContain("Use an AT Proto account you already have."); });});
describe("developers documentation", () => { it("walks app developers through client metadata and the embed", () => { const html = developersPage(); expect(html).toContain("Integrating loggedin.fyi"); expect(html).toContain("oauth-client-metadata.json"); expect(html).toContain("no static allowlist"); expect(html).toContain("Loggedin.mountEmbed"); expect(html).toContain("Loggedin.heartbeat"); expect(html).toContain("Loggedin.logout"); expect(html).toContain("fyi.loggedin.account.list"); expect(html).toContain("storage-access"); expect(html).toContain("GET /origins"); expect(html).toContain("Rate Limits"); expect(html).toContain("X-Loggedin-Token"); expect(html).toContain("ASWebAuthenticationSession"); expect(html).toContain("/app/start"); expect(html).toContain("sdks/ios"); expect(html).toContain("Listing 11"); expect(html).not.toContain("READ_PHONE_STATE"); expect(html).not.toContain("IMEI"); expect(html).toContain("This is not single sign-on"); expect(html).not.toContain("public git repository"); expect(html).not.toContain("GET /allowlist"); });});
describe("embed and renderer", () => { it("tries storage access before listing, and only posts popup after Continue fails", () => { const html = embedPage(); expect(html).toContain("requestStorageAccess"); expect(html).toContain('type: "needs-access"'); expect(html).toContain('type: "popup"'); expect(html).toContain("Do not call hasStorageAccess()"); expect(html).toContain("isHttpOrigin"); expect(html).not.toContain("ALLOWED"); expect(html.indexOf("if (await hasAccess())")).toBeLessThan(html.indexOf("await bootSilent()")); expect(html.indexOf("if (await tryActivateExistingGrant())")).toBeLessThan(html.indexOf("showChoose();\n }")); expect(html.indexOf("addEventListener(\"click\"")).toBeLessThan(html.indexOf('type: "popup"')); });
it("opens first-party /save from the parent origin, not a hardcoded host", () => { const js = exampleRendererJs(); expect(js).toContain("/save"); expect(js).toContain("popupMode"); expect(js).toContain("prepareEmbed"); expect(js).toContain("mountEmbed"); expect(js).toContain("storage-access"); expect(js).toContain("needs-access"); expect(js).toContain("location.origin"); expect(js).not.toContain("https://loggedin.fyi"); });
it("renders first-party save and logout pages", () => { const did = "did:plc:z72i7hdynmk6r22z27h6tvur"; const origin = "https://lightbox-loggedin.val.run"; expect(savePage(did, origin)).toContain(did); expect(savePage(did, origin)).toContain("fyi.loggedin.account.loggedIn"); expect(savePageLogout(did, origin)).toContain("fyi.loggedin.account.logout"); });});