mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-02 05:12:11 +03:00
No-auth providers (mimocode, opencode, ...) are always dispatched with a single
hardcoded connectionId ("noauth" — SYNTHETIC_NOAUTH_CONNECTION_ID in
src/sse/services/auth.ts). No provider_connections row ever has id="noauth", so
resolveProxyForConnection() in src/lib/db/settings.ts could never populate
connectionRecord for them, and its provider-level proxy lookup (Steps 6/8) only
runs when connectionRecord is present. A proxy assigned via Settings -> Providers
-> mimocode was therefore silently ignored, reproducing the reporter's "same
thing happen when i set the proxy directly in the provider menu" symptom.
Adds a best-effort fallback (src/lib/db/settings/noAuthProxyFallback.ts): when
connectionRecord could not be resolved, scan the known no-auth provider ids for a
configured provider-level proxy (registry first, then legacy) before falling
through to the global/direct steps.
Regression test: tests/unit/proxy-noauth-provider-6272.test.ts (RED on unfixed
code — resolved to level=direct/proxy=null; GREEN after the fix).
52 lines
2.1 KiB
TypeScript
52 lines
2.1 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-6272-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
const ORIGINAL_INITIAL_PASSWORD = process.env.INITIAL_PASSWORD;
|
|
delete process.env.INITIAL_PASSWORD;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const settingsDb = await import("../../src/lib/db/settings.ts");
|
|
|
|
test.after(async () => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
if (ORIGINAL_INITIAL_PASSWORD === undefined) delete process.env.INITIAL_PASSWORD;
|
|
else process.env.INITIAL_PASSWORD = ORIGINAL_INITIAL_PASSWORD;
|
|
});
|
|
|
|
test("#6272: resolveProxyForConnection('noauth', ...) honors a provider-level proxy assigned to 'mimocode'", async () => {
|
|
core.getDbInstance();
|
|
const proxy = { type: "http", host: "127.0.0.1", port: 8888 };
|
|
|
|
// Reporter's second symptom: "same thing happen when i set the proxy directly
|
|
// in the provider menu" -> assign a provider-scoped proxy to the mimocode
|
|
// provider id, the way Settings -> Providers -> mimocode would persist it.
|
|
await settingsDb.setProxyForLevel("provider", "mimocode", proxy);
|
|
|
|
const resolved = await settingsDb.resolveProxyForConnection("noauth", undefined);
|
|
|
|
assert.equal(
|
|
resolved?.proxy?.host,
|
|
"127.0.0.1",
|
|
`expected the mimocode provider-level proxy to be honored, got level=${resolved?.level} proxy=${JSON.stringify(resolved?.proxy)}`
|
|
);
|
|
assert.equal(resolved?.level, "provider");
|
|
assert.equal(resolved?.levelId, "mimocode");
|
|
});
|
|
|
|
test("control: resolveProxyForConnection('noauth', ...) still honors the GLOBAL proxy when no no-auth provider proxy is set", async () => {
|
|
core.getDbInstance();
|
|
await settingsDb.deleteProxyForLevel("provider", "mimocode");
|
|
const proxy = { type: "http", host: "10.0.0.1", port: 9999 };
|
|
await settingsDb.setProxyForLevel("global", null, proxy);
|
|
|
|
const resolved = await settingsDb.resolveProxyForConnection("noauth", undefined);
|
|
assert.equal(resolved?.proxy?.host, "10.0.0.1");
|
|
assert.equal(resolved?.level, "global");
|
|
});
|