hetingyi (#666): from a mainland-China network, Akamai answers every agent.minimax.io request with 307 Location: https://agent.minimaxi.com/... (X-From: ak). fetch followed it, the China site turned the international token away, and MiniMax Code (Global) read as "account: the sign-in was refused (HTTP 401)" on the credits card and the check-in. The chat path was worse: its 401 forced a refresh (a refresh token spent) and sent the chat again, to the same redirect, on every request. - siteFetch: every request to a site's hosts (account API, check-in, credit ledger, M Plan, models, chats, OAuth device code, poll and refresh) goes with redirect "manual". A redirect on the same host is followed as fetch would (up to five; 301/302/303 turn a POST into a GET; a 307/308 resends only a string body). One to another host is an OtherSite error: "<what>: agent.minimax.io sent the request on to agent.minimaxi.com (HTTP 307), which doesn't take MiniMax Code (Global)'s sign-in. MiniMax does that for a network in mainland China; set a proxy outside mainland China for MiniMax Code (Global)." - It is never an AccountRefused: the card's sign-in stays "kept", the check-in's 401 retry isn't taken, and a chat answers 502 api_error with the message (X-Magpie-Sign-In kept), with no refresh and no second send. - The China site gets the same handling with a neutral hint, since nothing says which networks it sends elsewhere. - README: the international site needs a network outside mainland China. Run at this commit on mote: bun test packages/minimax 87 pass, 0 fail. region.test.mjs (the reporter's 307s: status, Location, X-From, an _abck cookie) against origin/main's index.mjs: the card, check-in, chat, models and refresh tests red; the same-host redirect test passes on both. Not tried: a real mainland-China egress or a real global account; the fixtures are the reporter's table. A proxy injected by magpie's plugin host passes init through (host.js spreads it), so redirect "manual" reaches Bun's fetch, checked by reading host.js only.
106 lines
4.8 KiB
JavaScript
106 lines
4.8 KiB
JavaScript
// A request from a mainland-China network to the international site:
|
|
// Akamai answers agent.minimax.io with a 307 to agent.minimaxi.com, whose
|
|
// China site turns the international token away (hetingyi, #666). The
|
|
// redirect is never followed: the account card, the check-in, the chats and
|
|
// the models say where it went and what to do, never that the sign-in was
|
|
// refused, and no refresh token is spent on it. The 307s here are the
|
|
// reporter's: their status, Location and X-From.
|
|
import "./nonet.mjs"
|
|
import { afterEach, expect, test } from "bun:test"
|
|
import { MiniMaxCodeAuthPlugin, MiniMaxCodeGlobalAuthPlugin } from "./index.mjs"
|
|
import { fakeMiniMax, json } from "./fake.mjs"
|
|
|
|
let f
|
|
afterEach(() => f?.close())
|
|
|
|
const auth = { type: "oauth", access: "tok", refresh: "r", expires: Date.now() + 3600_000, accountId: "a@example.com" }
|
|
|
|
// Akamai's answer from a mainland-China egress (#666's table)
|
|
const toChina = (r) => new Response(null, {
|
|
status: 307,
|
|
headers: { Location: "https://agent.minimaxi.com" + r.url.replace(/\?.*$/, ""), "X-From": "ak", "Set-Cookie": "_abck=0~-1~-1~-1; Domain=.minimax.io; Path=/" },
|
|
})
|
|
|
|
function chinaEgress(f) {
|
|
for (const k of [
|
|
"GET /v1/api/user/info",
|
|
"POST /matrix/api/v1/user/get_user_extra_info",
|
|
"POST /matrix/api/v1/commerce/get_membership_info",
|
|
"GET /minimax-cloud/api/v1/signin/status",
|
|
"GET /minimax-cloud/api/v1/credit/details",
|
|
"POST /mavis/api/v1/llm/v1/messages",
|
|
"GET /mavis/api/v1/models",
|
|
]) f.route(k, toChina)
|
|
f.route("POST /oauth2/token", () => {
|
|
throw new Error("a refresh was spent on a redirect")
|
|
})
|
|
}
|
|
|
|
const china = /agent\.minimaxi\.com/
|
|
|
|
test("the account card says the request went to the China site, not that the sign-in was refused", async () => {
|
|
f = fakeMiniMax()
|
|
chinaEgress(f)
|
|
const hooks = await MiniMaxCodeGlobalAuthPlugin({ client: {} })
|
|
const u = await hooks.auth.usage(async () => auth)
|
|
expect(u.error).toMatch(china)
|
|
expect(u.error).toMatch(/proxy outside mainland China/)
|
|
expect(u.error).not.toMatch(/refused|401/)
|
|
expect(u.signIn).toBe("kept")
|
|
expect(f.seen.some((r) => r.path === "/oauth2/token")).toBe(false)
|
|
})
|
|
|
|
test("the check-in fails with the reason and spends no refresh", async () => {
|
|
f = fakeMiniMax()
|
|
chinaEgress(f)
|
|
const hooks = await MiniMaxCodeGlobalAuthPlugin({ client: { auth: { set: async () => {} } } })
|
|
const c = await hooks.auth.checkin(async () => ({ ...auth, realUserID: "u-42" }))
|
|
expect(c.outcome).toBe("failed")
|
|
expect(c.message).toMatch(/^check-in: .* sent the request on to agent\.minimaxi\.com \(HTTP 307\)/)
|
|
expect(c.signIn).toBeUndefined()
|
|
expect(f.seen.some((r) => r.path === "/oauth2/token")).toBe(false)
|
|
})
|
|
|
|
test("a chat is a 502 that names the redirect, the sign-in kept", async () => {
|
|
f = fakeMiniMax()
|
|
chinaEgress(f)
|
|
const opts = await (await MiniMaxCodeGlobalAuthPlugin({ client: {} })).auth.loader(async () => auth)
|
|
const res = await opts.fetch(opts.baseURL + "/messages", { method: "POST", body: '{"model":"MiniMax-M3","max_tokens":1,"messages":[]}' })
|
|
expect(res.status).toBe(502)
|
|
expect(res.headers.get("X-Magpie-Sign-In")).toBe("kept")
|
|
const e = (await res.json()).error
|
|
expect(e.type).toBe("api_error")
|
|
expect(e.message).toMatch(china)
|
|
// sent once: the 401 path (refresh, send again) wasn't taken
|
|
expect(f.seen.filter((r) => r.path.endsWith("/messages")).length).toBe(1)
|
|
expect(f.seen.some((r) => r.path === "/oauth2/token")).toBe(false)
|
|
})
|
|
|
|
test("the models fall back to the list", async () => {
|
|
f = fakeMiniMax()
|
|
chinaEgress(f)
|
|
const hooks = await MiniMaxCodeGlobalAuthPlugin({ client: {} })
|
|
const listed = { "MiniMax-M3": { id: "MiniMax-M3" } }
|
|
expect(await hooks.provider.models({ models: listed }, { auth })).toBe(listed)
|
|
})
|
|
|
|
test("a refresh sent on to the other site keeps the sign-in", async () => {
|
|
f = fakeMiniMax()
|
|
f.route("POST /oauth2/token", () => new Response(null, { status: 307, headers: { Location: "https://account.minimaxi.com/oauth2/token" } }))
|
|
const hooks = await MiniMaxCodeGlobalAuthPlugin({ client: {} })
|
|
const e = await hooks.auth.refresh({ ...auth, refresh: "r2" }).catch((e) => e)
|
|
expect(e).toBeInstanceOf(Error)
|
|
expect(e.message).toMatch(/account\.minimaxi\.com/)
|
|
expect(e.signIn).toBeUndefined()
|
|
})
|
|
|
|
test("a redirect on the same host is followed", async () => {
|
|
f = fakeMiniMax()
|
|
f.route("GET /v1/api/user/info", (r) => new Response(null, { status: 302, headers: { Location: "/v1/api/user/info2" + r.url.slice(r.path.length) } }))
|
|
f.route("GET /v1/api/user/info2", () => json({ statusInfo: { code: 0 }, data: { userInfo: { realUserID: "u-42", userEmail: "a@example.com" } } }))
|
|
f.route("POST /matrix/api/v1/user/get_user_extra_info", () => json({ statusInfo: { code: 0 }, data: { workspaces: [] } }))
|
|
const hooks = await MiniMaxCodeAuthPlugin({ client: {} })
|
|
const u = await hooks.auth.usage(async () => auth)
|
|
expect(u.user).toBe("a@example.com")
|
|
})
|