Files
OmniRoute/tests/unit/proxy-assigned-unavailable-6246.test.ts
Tushar Agarwal 1089c24bc8 Remove/mimocode sunset provider (#10186)
* remove: drop sunset MiMoCode provider from model catalog

* remove: drop sunset MiMoCode provider from model catalog (shared.ts)

Remove unused imports, types, and comments from shared.ts.

* remove: MiMoCode provider (Xiaomi sunset) — executor, registry, no-auth config, icon, tests

* refactor(providers): finish MiMoCode removal — sweep remaining no-auth references

Drop the leftover mimocode entries from the no-auth provider controls, the
translate-path snapshot, the eslint suppressions, and the #3061 auth-loop
test. Re-point the fingerprint-pin (#6696) and proxy-noauth (#6272) tests at
opencode, which exercises the same fingerprint path, so the removal does not
break runtime behavior.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

* docs(providers): reconcile provider/executor counts after MiMoCode sunset

The base's parallel doc-count sync (#10433) pinned 340 providers / 101
executors. With mimocode removed, live code has 339 providers and 100
executors; refresh the user-facing counts (package.json description,
llm.txt, README/AGENTS, i18n llm.txt, provider reference, diagrams) so the
check-docs-counts STRICT gate stays green.

Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>

* test(providers): fix orphaned mimocode references after MiMoCode sunset

The sunset removed mimocode/mcode from the free-onboarding candidates and
from FINGERPRINT_PROVIDERS, but two tests still referenced them:

- free-provider-onboarding-setup: the mimocode->theoldllm substitution
  introduced duplicate 'opencode' rows (impossible given the request-set
  dedupe) and the wrong display name; align expectations with the actual
  {opencode, theoldllm} dedupe behavior and 'The Old LLM (Free)' name.
- combo-system-prompt-templates-5501: resolveTargetFingerprint tested with
  provider 'mcode', which is no longer a fingerprint provider; point it at
  the remaining fingerprint provider 'opencode'.

Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>

---------

Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
Co-authored-by: Tushar49 <Tushar49@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: adevwithpurpose <adevwithpurpose@users.noreply.github.com>
Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
2026-08-18 10:49:24 -03:00

160 lines
5.1 KiB
TypeScript

/**
* TDD — #6246 IP leak (part 1, fail-closed).
*
* When a proxy is ASSIGNED to a connection (account/provider/global scope) but is
* dead/inactive, `resolveProxyForConnection` returns a direct result (no alive
* proxy resolved). The chat path used to egress DIRECTLY in that case, leaking
* the operator's real IP. The fix is a fail-closed guard: if the only reason a
* connection resolves to direct is that its ASSIGNED proxy is dead, block instead
* of leaking. Explicit "proxy off" toggles are a deliberate direct choice and must
* NOT be treated as a leak.
*
* This test exercises the pure DB predicate `hasBlockingProxyAssignment`, which
* encodes exactly that decision (honoring the global + connection proxy toggles).
*/
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-proxy-6246-"));
process.env.DATA_DIR = TEST_DATA_DIR;
process.env.API_KEY_SECRET = "test-secret";
const core = await import("../../src/lib/db/core.ts");
const proxiesDb = await import("../../src/lib/db/proxies.ts");
const providersDb = await import("../../src/lib/db/providers.ts");
async function resetStorage() {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
}
function setGlobalProxyEnabled(enabled: boolean) {
const db = core.getDbInstance();
db.prepare(
"INSERT OR REPLACE INTO key_value (namespace, key, value) VALUES ('settings', 'proxyEnabled', ?)"
).run(JSON.stringify(enabled));
}
async function makeConnection(): Promise<string> {
const conn = await providersDb.createProviderConnection({
provider: "openai",
authType: "apiKey",
name: `Conn ${Date.now()} ${Math.random()}`,
apiKey: "sk-test",
});
return (conn as { id: string }).id;
}
test.after(async () => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
test("BLOCKS: an account proxy assigned but marked inactive (the IP-leak case)", async () => {
await resetStorage();
const connId = await makeConnection();
const proxy = await proxiesDb.createProxy({
name: "Dead paid proxy",
type: "http",
host: "127.0.0.1",
port: 9001,
});
await proxiesDb.updateProxy(proxy!.id, { status: "inactive" });
await proxiesDb.assignProxyToScope("account", connId, proxy!.id);
assert.equal(
proxiesDb.hasBlockingProxyAssignment(connId),
true,
"a dead assigned proxy must block, not fall back to a direct egress"
);
});
test("ALLOWS DIRECT: a connection with no proxy assignment at all", async () => {
await resetStorage();
const connId = await makeConnection();
assert.equal(
proxiesDb.hasBlockingProxyAssignment(connId),
false,
"no assignment = user never configured a proxy = direct is legitimate"
);
});
test("NOT BLOCKING: an assigned proxy that is still ALIVE", async () => {
await resetStorage();
const connId = await makeConnection();
const proxy = await proxiesDb.createProxy({
name: "Live proxy",
type: "http",
host: "127.0.0.1",
port: 9002,
});
await proxiesDb.assignProxyToScope("account", connId, proxy!.id);
assert.equal(
proxiesDb.hasBlockingProxyAssignment(connId),
false,
"an alive assigned proxy resolves normally; nothing to block"
);
});
test("EXPLICIT DIRECT: global proxyEnabled=false is a deliberate choice, not a leak", async () => {
await resetStorage();
const connId = await makeConnection();
const proxy = await proxiesDb.createProxy({
name: "Dead proxy",
type: "http",
host: "127.0.0.1",
port: 9003,
});
await proxiesDb.updateProxy(proxy!.id, { status: "inactive" });
await proxiesDb.assignProxyToScope("account", connId, proxy!.id);
setGlobalProxyEnabled(false);
assert.equal(
proxiesDb.hasBlockingProxyAssignment(connId),
false,
"operator turned proxying off globally — direct is intended, do not block"
);
});
test("BLOCKS: a dead GLOBAL proxy assignment blocks any connection", async () => {
await resetStorage();
const connId = await makeConnection();
const proxy = await proxiesDb.createProxy({
name: "Dead global proxy",
type: "http",
host: "127.0.0.1",
port: 9004,
});
await proxiesDb.updateProxy(proxy!.id, { status: "error" });
await proxiesDb.assignProxyToScope("global", null, proxy!.id);
assert.equal(
proxiesDb.hasBlockingProxyAssignment(connId),
true,
"a dead global proxy assignment must block, not leak direct"
);
});
test("BLOCKS: a dead no-auth provider proxy assignment", async () => {
await resetStorage();
const proxy = await proxiesDb.createProxy({
name: "Dead no-auth proxy",
type: "http",
host: "127.0.0.1",
port: 9005,
});
await proxiesDb.updateProxy(proxy!.id, { status: "inactive" });
await proxiesDb.assignProxyToScope("provider", "opencode", proxy!.id);
assert.equal(
proxiesDb.hasBlockingProxyAssignment("noauth", "opencode"),
true,
"a dead no-auth provider proxy must block instead of allowing direct egress"
);
});