The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | |
| 4 | import { ProviderAuthState } from "./providerSetup.ts"; |
| 5 | |
| 6 | const decodeState = Schema.decodeUnknownSync(ProviderAuthState); |
| 7 | |
| 8 | describe("provider auth state", () => { |
| 9 | it("drops auth variants from newer servers instead of rejecting the state", () => { |
| 10 | const method = { id: "browser", name: "Browser", description: null, type: "agent" }; |
| 11 | expect( |
| 12 | decodeState({ |
| 13 | instanceId: "cursor", |
| 14 | phase: "waiting", |
| 15 | flowId: null, |
| 16 | authorizationUrl: null, |
| 17 | expiresAt: null, |
| 18 | message: null, |
| 19 | methods: [method, { ...method, id: "passkey", type: "passkey" }], |
| 20 | interaction: { type: "passkey", id: "passkey" }, |
| 21 | credentialOwner: "keychain", |
| 22 | }), |
| 23 | ).toEqual({ |
| 24 | instanceId: "cursor", |
| 25 | phase: "waiting", |
| 26 | flowId: null, |
| 27 | authorizationUrl: null, |
| 28 | expiresAt: null, |
| 29 | message: null, |
| 30 | methods: [method], |
| 31 | }); |
| 32 | }); |
| 33 | |
| 34 | it("refuses sign-in URLs that are not web pages", () => { |
| 35 | const state = { |
| 36 | instanceId: "cursor", |
| 37 | phase: "waiting", |
| 38 | flowId: "flow", |
| 39 | authorizationUrl: null, |
| 40 | expiresAt: null, |
| 41 | message: null, |
| 42 | }; |
| 43 | const script = "javascript:alert(document.domain)"; |
| 44 | expect( |
| 45 | decodeState({ |
| 46 | ...state, |
| 47 | interaction: { type: "browser", id: "b", url: script, requiresConsent: true }, |
| 48 | }), |
| 49 | ).toEqual(state); |
| 50 | expect( |
| 51 | decodeState({ |
| 52 | ...state, |
| 53 | interaction: { type: "deviceCode", id: "d", url: script, userCode: "ABCD" }, |
| 54 | }), |
| 55 | ).toEqual(state); |
| 56 | expect(() => decodeState({ ...state, authorizationUrl: script })).toThrow(); |
| 57 | expect( |
| 58 | decodeState({ ...state, authorizationUrl: "https://cursor.com/login" }).authorizationUrl, |
| 59 | ).toBe("https://cursor.com/login"); |
| 60 | }); |
| 61 | }); |