mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
Rebuilt clean on release/v3.8.49 (branch forked from old main, ~drift). Resolved 2 real conflicts against the current tip: providerModelsConfig.ts keeps BOTH the tip's DashScope text-model helpers (#7882) and this PR's ProviderModelsHeaderContext type; OAuthModal.tsx takes this PR's DEVICE_CODE_PROVIDERS set (superset of the tip's hardcoded chain + grok-cli), dropping the now-dead qwen entry (#7866 removed qwen OAuth). Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-grok-device-route-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const settingsDb = await import("../../src/lib/db/settings.ts");
|
|
const route = await import("../../src/app/api/oauth/[provider]/[action]/route.ts");
|
|
|
|
const originalFetch = globalThis.fetch;
|
|
|
|
test.before(async () => {
|
|
await settingsDb.updateSettings({ requireLogin: false });
|
|
});
|
|
|
|
test.afterEach(() => {
|
|
globalThis.fetch = originalFetch;
|
|
});
|
|
|
|
test.after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
});
|
|
|
|
test("grok-cli poll does not require a PKCE code verifier", async () => {
|
|
let upstreamBody = "";
|
|
globalThis.fetch = (async (_input, init) => {
|
|
upstreamBody = String(init?.body);
|
|
return new Response(
|
|
JSON.stringify({
|
|
error: "authorization_pending",
|
|
error_description: "User has not yet authorized",
|
|
}),
|
|
{ status: 400, headers: { "Content-Type": "application/json" } }
|
|
);
|
|
}) as typeof fetch;
|
|
|
|
const request = new Request("http://localhost:20128/api/oauth/grok-cli/poll", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ deviceCode: "opaque-device-code" }),
|
|
});
|
|
const response = await route.POST(request, {
|
|
params: Promise.resolve({ provider: "grok-cli", action: "poll" }),
|
|
});
|
|
const body = await response.json();
|
|
const params = new URLSearchParams(upstreamBody);
|
|
|
|
assert.equal(response.status, 200);
|
|
assert.equal(body.success, false);
|
|
assert.equal(body.pending, true);
|
|
assert.equal(body.error, "authorization_pending");
|
|
assert.equal(params.get("device_code"), "opaque-device-code");
|
|
});
|