From 338d30e4c4dd5ab21447e77c32abbd187a0137a1 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 7 Mar 2026 00:05:06 +0200 Subject: [PATCH] fix(enterprise/cli): use :0 for http-address in proxy server tests (#22726) `Test_ProxyServer_Headers` never passed `--http-address`, so it bound to the default `127.0.0.1:3000`. `TestWorkspaceProxy_Server_PrometheusEnabled` used `RandomPort(t)` for `--http-address` (a drive-by from #14972 which was fixing the Prometheus port). Both now use `--http-address :0`. `ConfigureHTTPServers` calls `net.Listen("tcp", ":0")` and holds the listener open, so there is no TOCTOU window. Neither test connects to the HTTP listener, so the assigned port is irrelevant. This matches `cli/server_test.go` where `:0` is used throughout. --- enterprise/cli/proxyserver_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/enterprise/cli/proxyserver_test.go b/enterprise/cli/proxyserver_test.go index b8df3d2c6a..5e01f70151 100644 --- a/enterprise/cli/proxyserver_test.go +++ b/enterprise/cli/proxyserver_test.go @@ -46,6 +46,7 @@ func Test_ProxyServer_Headers(t *testing.T) { "--primary-access-url", srv.URL, "--proxy-session-token", "test-token", "--access-url", "http://localhost:8080", + "--http-address", ":0", "--header", fmt.Sprintf("%s=%s", headerName1, headerVal1), "--header-command", fmt.Sprintf("printf %s=%s", headerName2, headerVal2), ) @@ -97,7 +98,7 @@ func TestWorkspaceProxy_Server_PrometheusEnabled(t *testing.T) { "--primary-access-url", srv.URL, "--proxy-session-token", "test-token", "--access-url", "http://foobar:3001", - "--http-address", fmt.Sprintf("127.0.0.1:%d", testutil.RandomPort(t)), + "--http-address", ":0", "--prometheus-enable", "--prometheus-address", fmt.Sprintf("127.0.0.1:%d", prometheusPort), )