mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 12:52:11 +03:00
validateWebCookieProvider() previously required a providerRegistry.ts entry and
returned "Provider not found in registry" for web-cookie-only providers like
lmarena, gemini-business, poe-web, venice-web and v0-vercel-web. A fallback to
WEB_COOKIE_PROVIDERS[provider].website was proposed, but live verification showed
probing `${website}/models` does not reliably signal session validity for these
(redirects/SPA 200s regardless of cookie validity) — it would report an expired
or garbage cookie as valid, which is worse than an honest "not supported". Until
each provider has a verified, side-effect-free auth probe against its real API
host, the fallback now returns `unsupported: true` with no network call. Also
reverts the probe transport from validationRead back to directHttpsRequest,
which fixes a globalThis.fetch mock/patch-timing mismatch that made the
pre-existing tests/unit/provider-validation-web-cookie-auth007.test.ts hit the
live network in CI, and adds the missing Cookie header to the probe request.
Regression guard: tests/unit/web-cookie-validation-fallback.test.ts.
Co-authored-by: oyi77 <oyi77@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
111 lines
4.3 KiB
TypeScript
111 lines
4.3 KiB
TypeScript
// Tests for validateWebCookieProvider fallback when no registry entry exists.
|
|
// Covers providers like lmarena, gemini-business, poe-web, venice-web and v0-vercel-web
|
|
// that are listed in WEB_COOKIE_PROVIDERS but have no entry in providerRegistry.ts.
|
|
//
|
|
// These providers only expose a marketing website URL (WEB_COOKIE_PROVIDERS[id].website),
|
|
// not a real API host. Probing `${website}/models` does not reliably signal session
|
|
// validity — live verification showed most of these hosts return redirects or SPA 200s
|
|
// regardless of cookie validity, which would silently report an expired/garbage cookie as
|
|
// "OK". Until each provider has a verified, side-effect-free auth probe against its real
|
|
// API host, validateWebCookieProvider reports `unsupported: true` for this fallback case
|
|
// instead of a false "valid" — and does so WITHOUT making any network probe.
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { validateProviderApiKey } = await import("../../src/lib/providers/validation.ts");
|
|
|
|
const originalFetch = globalThis.fetch;
|
|
|
|
const fetchCalls: Array<{ url: string; headers: Record<string, string> }> = [];
|
|
|
|
test.beforeEach(() => {
|
|
fetchCalls.length = 0;
|
|
globalThis.fetch = (async (url: string | URL, init?: RequestInit) => {
|
|
const headers: Record<string, string> = {};
|
|
if (init?.headers) {
|
|
if (init.headers instanceof Headers) {
|
|
init.headers.forEach((v, k) => {
|
|
headers[k] = v;
|
|
});
|
|
} else if (Array.isArray(init.headers)) {
|
|
for (const [k, v] of init.headers) headers[k] = v;
|
|
} else {
|
|
Object.assign(headers, init.headers);
|
|
}
|
|
}
|
|
fetchCalls.push({ url: String(url), headers });
|
|
// If this mock is ever hit for a no-registry-entry provider, the test will fail on
|
|
// the `fetchCalls.length` assertion below — this response is never meant to be read.
|
|
return new Response("", { status: 404 });
|
|
}) as typeof fetch;
|
|
});
|
|
|
|
test.afterEach(() => {
|
|
globalThis.fetch = originalFetch;
|
|
});
|
|
|
|
// ── lmarena (no registry entry, falls back to WEB_COOKIE_PROVIDERS) ──
|
|
|
|
test("lmarena validation is unsupported (no verified auth probe) and makes no network call", async () => {
|
|
const result = await validateProviderApiKey({
|
|
provider: "lmarena",
|
|
apiKey: "test-lmarena-cookie",
|
|
});
|
|
assert.strictEqual(result.valid, false);
|
|
assert.equal(result.unsupported, true);
|
|
assert.equal(fetchCalls.length, 0, "must not probe the marketing website");
|
|
});
|
|
|
|
test("lmarena validation rejects empty cookie before checking support", async () => {
|
|
const result = await validateProviderApiKey({
|
|
provider: "lmarena",
|
|
apiKey: "",
|
|
});
|
|
assert.strictEqual(result.valid, false);
|
|
assert.match(result.error, /api key required|cookie/i);
|
|
assert.equal(fetchCalls.length, 0);
|
|
});
|
|
|
|
// ── gemini-business (no registry entry, falls back to WEB_COOKIE_PROVIDERS) ──
|
|
|
|
test("gemini-business validation is unsupported and makes no network call", async () => {
|
|
const result = await validateProviderApiKey({
|
|
provider: "gemini-business",
|
|
apiKey: "test-gemini-cookie",
|
|
});
|
|
assert.strictEqual(result.valid, false);
|
|
assert.equal(result.unsupported, true);
|
|
assert.equal(fetchCalls.length, 0);
|
|
});
|
|
|
|
// ── remaining WEB_COOKIE_PROVIDERS-only providers (no registry entry) ──
|
|
// NOTE: doubao-web and zenmux-free are intentionally NOT covered here — unlike when this
|
|
// fix was proposed, both now carry a providerRegistry.ts entry (added independently of
|
|
// this PR), so they no longer exercise the no-registry-entry fallback branch this test
|
|
// file targets; they go through the pre-existing entry-based probe instead, which is out
|
|
// of scope for this fix.
|
|
|
|
for (const provider of ["poe-web", "venice-web", "v0-vercel-web"]) {
|
|
test(`${provider} validation is unsupported and makes no network call`, async () => {
|
|
const result = await validateProviderApiKey({
|
|
provider,
|
|
apiKey: "some-cookie-value",
|
|
});
|
|
assert.strictEqual(result.valid, false);
|
|
assert.equal(result.unsupported, true);
|
|
assert.equal(fetchCalls.length, 0);
|
|
});
|
|
}
|
|
|
|
// ── generic fallback guard ──
|
|
|
|
test("unknown web-cookie provider without registry returns unsupported", async () => {
|
|
const result = await validateProviderApiKey({
|
|
provider: "fake-web",
|
|
apiKey: "some-key",
|
|
});
|
|
assert.strictEqual(result.valid, false);
|
|
assert.equal(result.unsupported, true);
|
|
});
|