fix(proxy): harden ProxyCommand summaries

This commit is contained in:
bincxz
2026-06-05 15:35:21 +08:00
parent 13f1453276
commit 28a7184cc4
14 changed files with 138 additions and 24 deletions

View File

@@ -3,6 +3,8 @@ import assert from "node:assert/strict";
import type { Host, ProxyProfile } from "./models.ts";
import {
formatProxyConfigEndpoint,
formatProxyConfigType,
isCompleteProxyConfig,
normalizeManualProxyConfig,
materializeHostProxyProfile,
@@ -121,3 +123,28 @@ test("isCompleteProxyConfig accepts a non-empty command proxy", () => {
true,
);
});
test("formatProxyConfigEndpoint hides command proxy contents in summaries", () => {
assert.equal(
formatProxyConfigEndpoint({
type: "command",
host: "",
port: 0,
command: "cloudflared access ssh --hostname %h --token secret",
}),
"ProxyCommand",
);
});
test("formatProxyConfigType labels command proxies without uppercasing", () => {
assert.equal(formatProxyConfigType({ type: "http", host: "proxy.example.com", port: 3128 }), "HTTP");
assert.equal(
formatProxyConfigType({
type: "command",
host: "",
port: 0,
command: "cloudflared access ssh --hostname %h",
}),
"ProxyCommand",
);
});

View File

@@ -50,10 +50,16 @@ export const hasUsableProxyConfig = (config: ProxyConfig | undefined): boolean =
export const formatProxyConfigEndpoint = (config: ProxyConfig | undefined): string => {
if (!config) return "";
if (isProxyCommandConfig(config)) return config.command?.trim() || "";
if (isProxyCommandConfig(config)) return "ProxyCommand";
return `${config.host}:${config.port}`;
};
export const formatProxyConfigType = (config: ProxyConfig | undefined): string => {
if (!config) return "";
if (isProxyCommandConfig(config)) return "ProxyCommand";
return config.type.toUpperCase();
};
export function findProxyProfile(
proxyProfileId: string | undefined,
proxyProfiles: ProxyProfile[],