fix(proxy): harden ProxyCommand summaries
This commit is contained in:
@@ -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",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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[],
|
||||
|
||||
Reference in New Issue
Block a user