@@ -29,6 +29,67 @@ describe("normalizeOAuthExpires", () => {
|
29 | 29 | }); |
30 | 30 | |
31 | 31 | describe("loginMiniMaxPortalOAuth", () => { |
| 32 | +it("uses MiniMax account OAuth endpoints directly for global and CN login", async () => { |
| 33 | +for (const [region, expectedHosts] of [ |
| 34 | +[ |
| 35 | +"global", |
| 36 | +[ |
| 37 | +"https://account.minimax.io/oauth2/device/code", |
| 38 | +"https://account.minimax.io/oauth2/token", |
| 39 | +], |
| 40 | +], |
| 41 | +[ |
| 42 | +"cn", |
| 43 | +[ |
| 44 | +"https://account.minimaxi.com/oauth2/device/code", |
| 45 | +"https://account.minimaxi.com/oauth2/token", |
| 46 | +], |
| 47 | +], |
| 48 | +] as const) { |
| 49 | +const requestedUrls: string[] = []; |
| 50 | +const fetchMock = vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => { |
| 51 | +requestedUrls.push(input instanceof Request ? input.url : String(input)); |
| 52 | +const body = |
| 53 | +init?.body instanceof URLSearchParams |
| 54 | + ? init.body |
| 55 | + : new URLSearchParams(typeof init?.body === "string" ? init.body : ""); |
| 56 | +if (requestedUrls.length === 1) { |
| 57 | +return new Response( |
| 58 | +JSON.stringify({ |
| 59 | +user_code: "CODE", |
| 60 | +verification_uri: "https://example.com/device", |
| 61 | +expired_in: Date.now() + 10_000, |
| 62 | +state: body.get("state"), |
| 63 | +}), |
| 64 | +{ status: 200, headers: { "Content-Type": "application/json" } }, |
| 65 | +); |
| 66 | +} |
| 67 | +return new Response( |
| 68 | +JSON.stringify({ |
| 69 | +status: "success", |
| 70 | +access_token: "access", |
| 71 | +refresh_token: "refresh", |
| 72 | +expired_in: 3600, |
| 73 | +}), |
| 74 | +{ status: 200, headers: { "Content-Type": "application/json" } }, |
| 75 | +); |
| 76 | +}); |
| 77 | +vi.stubGlobal("fetch", fetchMock); |
| 78 | + |
| 79 | +await expect( |
| 80 | +loginMiniMaxPortalOAuth({ |
| 81 | + region, |
| 82 | +openUrl: vi.fn(async () => undefined), |
| 83 | +note: vi.fn(async () => undefined), |
| 84 | +progress: { update: vi.fn(), stop: vi.fn() }, |
| 85 | +}), |
| 86 | +).resolves.toMatchObject({ access: "access", refresh: "refresh" }); |
| 87 | +expect(requestedUrls).toEqual(expectedHosts); |
| 88 | + |
| 89 | +vi.unstubAllGlobals(); |
| 90 | +} |
| 91 | +}); |
| 92 | + |
32 | 93 | it("rejects Date-invalid authorization expiries before formatting instructions", async () => { |
33 | 94 | const fetchMock = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => { |
34 | 95 | const body = |
|