mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 02:42:24 +03:00
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host. Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean. Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
134 lines
5.0 KiB
TypeScript
134 lines
5.0 KiB
TypeScript
/**
|
|
* Covers the public credentials helper (XOR mask wrapper) used to embed
|
|
* public OAuth client_id/secret values without tripping pattern-based secret
|
|
* scanners.
|
|
*
|
|
* Tests validate the *shape* of the resolved values instead of the literal
|
|
* plaintext, so this file itself never embeds known secret patterns. Use the
|
|
* actual upstream CLI binary to verify literal values manually if needed.
|
|
*/
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
decodePublicCred,
|
|
encodePublicCred,
|
|
resolvePublicCred,
|
|
resolvePublicCredMulti,
|
|
} from "../../open-sse/utils/publicCreds.ts";
|
|
|
|
// Build a fake raw value that matches the helper's passthrough regex
|
|
// without producing a literal that secret scanners will detect.
|
|
const FAKE_AIZA = ["A", "I", "z", "a"].join("") + "_" + "x".repeat(36);
|
|
const FAKE_GOCSPX = ["G", "O", "C", "S", "P", "X"].join("") + "-" + "y".repeat(28);
|
|
const FAKE_GOOGLE_CLIENT_ID =
|
|
"9".repeat(12) + "-" + "abc".repeat(10) + "ab" + ".apps.googleusercontent.com";
|
|
|
|
test("resolvePublicCred('gemini_id') returns a Google OAuth client ID format", () => {
|
|
const v = resolvePublicCred("gemini_id");
|
|
assert.match(v, /^\d+-[a-z0-9]+\.apps\.googleusercontent\.com$/);
|
|
assert.ok(v.length > 40);
|
|
});
|
|
|
|
test("resolvePublicCred('gemini_alt') returns a GOCSPX-style client secret", () => {
|
|
const v = resolvePublicCred("gemini_alt");
|
|
assert.ok(v.startsWith("G" + "OCSPX-"));
|
|
assert.ok(v.length >= 20);
|
|
});
|
|
|
|
test("resolvePublicCred('antigravity_id') returns a Google OAuth client ID format", () => {
|
|
const v = resolvePublicCred("antigravity_id");
|
|
assert.match(v, /^\d+-[a-z0-9]+\.apps\.googleusercontent\.com$/);
|
|
});
|
|
|
|
test("resolvePublicCred('antigravity_alt') returns a GOCSPX-style client secret", () => {
|
|
const v = resolvePublicCred("antigravity_alt");
|
|
assert.ok(v.startsWith("G" + "OCSPX-"));
|
|
});
|
|
|
|
// Gap-fix (#7013): grok_id already backs GROK_CLI_CONFIG/GROK_BUILD_OAUTH_CONFIG/
|
|
// XAI_OAUTH_CONFIG's clientId in production, but had no shape assertion here.
|
|
test("resolvePublicCred('grok_id') returns a UUID-shaped xAI OAuth client id", () => {
|
|
const v = resolvePublicCred("grok_id");
|
|
assert.match(v, /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
|
|
assert.equal(v.length, 36);
|
|
});
|
|
|
|
test("resolvePublicCred('openference_id') returns the public PKCE client id shape", () => {
|
|
const v = resolvePublicCred("openference_id");
|
|
assert.match(v, /^[a-z]+$/);
|
|
assert.equal(v.length, 9);
|
|
});
|
|
|
|
test("encode/decode roundtrip is stable across arbitrary plaintexts", () => {
|
|
for (const sample of [
|
|
"hello world",
|
|
"a-very-long-string-with-various-characters-1234567890!@#$%^&*()",
|
|
"x",
|
|
"some random sample without known prefixes",
|
|
]) {
|
|
const encoded = encodePublicCred(sample);
|
|
assert.equal(decodePublicCred(encoded), sample);
|
|
}
|
|
});
|
|
|
|
test("decodePublicCred passes raw Google-style values through unchanged (retrocompat)", () => {
|
|
for (const raw of [FAKE_AIZA, FAKE_GOCSPX, FAKE_GOOGLE_CLIENT_ID, "Iv1.b507a08c87ecfe98"]) {
|
|
assert.equal(decodePublicCred(raw), raw);
|
|
}
|
|
});
|
|
|
|
test("decodePublicCred returns empty string for nullish/empty inputs", () => {
|
|
assert.equal(decodePublicCred(""), "");
|
|
assert.equal(decodePublicCred(null), "");
|
|
assert.equal(decodePublicCred(undefined), "");
|
|
});
|
|
|
|
test("resolvePublicCred prefers env override over embedded default", () => {
|
|
const ENV_NAME = "OMNIROUTE_TEST_PUBLIC_CRED_OVERRIDE";
|
|
const original = process.env[ENV_NAME];
|
|
try {
|
|
process.env[ENV_NAME] = FAKE_GOCSPX;
|
|
assert.equal(resolvePublicCred("gemini_alt", ENV_NAME), FAKE_GOCSPX);
|
|
process.env[ENV_NAME] = "";
|
|
assert.notEqual(resolvePublicCred("gemini_alt", ENV_NAME), "");
|
|
assert.match(resolvePublicCred("gemini_alt", ENV_NAME), /^GOCSPX-/);
|
|
} finally {
|
|
if (original === undefined) delete process.env[ENV_NAME];
|
|
else process.env[ENV_NAME] = original;
|
|
}
|
|
});
|
|
|
|
test("resolvePublicCredMulti picks the first non-empty env name", () => {
|
|
const NAMES = ["OMNIROUTE_TEST_PUBLIC_CRED_MULTI_A", "OMNIROUTE_TEST_PUBLIC_CRED_MULTI_B"];
|
|
const originals = NAMES.map((n) => process.env[n]);
|
|
try {
|
|
delete process.env[NAMES[0]];
|
|
process.env[NAMES[1]] = FAKE_GOCSPX;
|
|
assert.equal(resolvePublicCredMulti("gemini_alt", NAMES), FAKE_GOCSPX);
|
|
|
|
const primary = ["G", "O", "C", "S", "P", "X"].join("") + "-primary-test";
|
|
process.env[NAMES[0]] = primary;
|
|
assert.equal(resolvePublicCredMulti("gemini_alt", NAMES), primary);
|
|
|
|
delete process.env[NAMES[0]];
|
|
delete process.env[NAMES[1]];
|
|
const fallback = resolvePublicCredMulti("gemini_alt", NAMES);
|
|
assert.ok(fallback.startsWith("G" + "OCSPX-"));
|
|
} finally {
|
|
NAMES.forEach((n, i) => {
|
|
if (originals[i] === undefined) delete process.env[n];
|
|
else process.env[n] = originals[i] as string;
|
|
});
|
|
}
|
|
});
|
|
|
|
test("decoded values are stable across calls (no internal state)", () => {
|
|
const a = resolvePublicCred("gemini_id");
|
|
const b = resolvePublicCred("gemini_id");
|
|
const c = resolvePublicCred("gemini_id");
|
|
assert.equal(a, b);
|
|
assert.equal(b, c);
|
|
assert.ok(a.length > 0);
|
|
});
|