mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 08:52:12 +00:00
* feat(settings): HTTP Proxy settings for the IDE's outgoing connections Add Appearance & Behavior › System Settings › HTTP Proxy with three modes: No proxy, Auto-detect proxy settings (the default; environment proxy as before) and Manual proxy configuration (HTTP or SOCKS, host and port, a comma-separated "No proxy for" list with `*` wildcards, optional proxy authentication). "Check connection…" GETs a URL with the settings as edited and reports the status or the error. - ide-core: `ProxySettings` plus routing (no-proxy globs, loopback always direct, credentials percent-encoded), the current proxy for the process, curl arguments and child-process variables. - ide-http: `client::build` / `client::shared` is the one HTTP client constructor; the HTTP Client requests and the update check go through it. - ide-tools: curl downloads (tools, JDKs, debug adapters, agent registry, remote server) follow the setting. - A manual proxy reaches child processes (language servers, debug adapters, terminals, git) as HTTP_PROXY / HTTPS_PROXY / ALL_PROXY / NO_PROXY. - The proxy password is kept in the owner-only saved passwords file (`proxy-password.json` in the app data directory), not in settings.toml. Co-Authored-By: Claude <[email protected]> * fix(host): Allow the Unix-only post-start test helpers on Windows Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
69 lines
2.7 KiB
TypeScript
69 lines
2.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { validateSettings } from "@/features/settings/model/schema";
|
|
import { DEFAULT_PROXY, proxyProblem, validateProxy, withProxyKind, type ProxySettingsValid } from "./proxySettings";
|
|
|
|
const manual = (patch: Partial<ProxySettingsValid> = {}): ProxySettingsValid => ({
|
|
...DEFAULT_PROXY,
|
|
mode: "manual",
|
|
host: "proxy.corp",
|
|
port: 3128,
|
|
...patch,
|
|
});
|
|
|
|
describe("validateProxy", () => {
|
|
it("defaults to auto-detect", () => {
|
|
expect(validateProxy(undefined)).toEqual(DEFAULT_PROXY);
|
|
expect(DEFAULT_PROXY.mode).toBe("auto");
|
|
expect(validateSettings({}).proxy).toEqual(DEFAULT_PROXY);
|
|
});
|
|
|
|
it("keeps valid values", () => {
|
|
const raw = {
|
|
mode: "manual",
|
|
kind: "socks",
|
|
host: "10.0.0.1",
|
|
port: 1081,
|
|
noProxy: "*.example.com, 192.168.*",
|
|
authenticate: true,
|
|
login: "me",
|
|
password: "pw",
|
|
};
|
|
expect(validateProxy(raw)).toEqual(raw);
|
|
expect(validateProxy({ mode: "none" }).mode).toBe("none");
|
|
});
|
|
|
|
it("falls back on malformed values", () => {
|
|
const p = validateProxy({ mode: "pac", kind: "ftp", host: 7, port: 70000, authenticate: "yes", login: null });
|
|
expect(p).toEqual(DEFAULT_PROXY);
|
|
expect(validateProxy({ kind: "socks", port: 0 }).port).toBe(1080);
|
|
expect(validateProxy({ port: 80.5 }).port).toBe(80);
|
|
expect(validateProxy([]).mode).toBe("auto");
|
|
});
|
|
});
|
|
|
|
describe("withProxyKind", () => {
|
|
it("moves a default port along and keeps a custom one", () => {
|
|
expect(withProxyKind(manual({ port: 80 }), "socks")).toMatchObject({ kind: "socks", port: 1080 });
|
|
expect(withProxyKind(manual({ kind: "socks", port: 1080 }), "http").port).toBe(80);
|
|
expect(withProxyKind(manual({ port: 3128 }), "socks").port).toBe(3128);
|
|
});
|
|
});
|
|
|
|
describe("proxyProblem", () => {
|
|
it("checks only a manual configuration", () => {
|
|
expect(proxyProblem({ ...DEFAULT_PROXY, host: "" })).toBeNull();
|
|
expect(proxyProblem({ ...DEFAULT_PROXY, mode: "none" })).toBeNull();
|
|
expect(proxyProblem(manual())).toBeNull();
|
|
});
|
|
|
|
it("reports a missing or invalid host, port and login", () => {
|
|
expect(proxyProblem(manual({ host: " " }))).toBe("Proxy host is empty");
|
|
expect(proxyProblem(manual({ host: "http://proxy" }))).toBe("Invalid proxy host");
|
|
expect(proxyProblem(manual({ host: "user@proxy" }))).toBe("Invalid proxy host");
|
|
expect(proxyProblem(manual({ port: 0 }))).toBe("Proxy port must be between 1 and 65535");
|
|
expect(proxyProblem(manual({ authenticate: true, login: "" }))).toBe("Proxy login is empty");
|
|
expect(proxyProblem(manual({ authenticate: true, login: "me", password: "" }))).toBeNull();
|
|
expect(proxyProblem(manual({ authenticate: false, login: "" }))).toBeNull();
|
|
});
|
|
});
|