diff --git a/cli/resetpassword_test.go b/cli/resetpassword_test.go index 73a4fed692d..8810b42ed06 100644 --- a/cli/resetpassword_test.go +++ b/cli/resetpassword_test.go @@ -39,7 +39,7 @@ func TestResetPassword(t *testing.T) { serverDone := make(chan struct{}) serverinv, cfg := clitest.New(t, "server", - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--postgres-url", connectionURL, "--cache-dir", t.TempDir(), diff --git a/cli/server_test.go b/cli/server_test.go index a1d6a33e616..956ab3ef56a 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -229,7 +229,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--cache-dir", t.TempDir(), ) @@ -252,7 +252,7 @@ func TestServer(t *testing.T) { inv, _ := clitest.New(t, "server", - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--ephemeral", ) @@ -330,7 +330,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://localhost:3000/", "--cache-dir", t.TempDir(), ) @@ -537,7 +537,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://localhost:3000/", "--cache-dir", t.TempDir(), ) @@ -563,7 +563,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "https://foobarbaz.mydomain", "--cache-dir", t.TempDir(), ) @@ -587,7 +587,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "https://google.com", "--cache-dir", t.TempDir(), ) @@ -611,7 +611,7 @@ func TestServer(t *testing.T) { root, _ := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "google.com", "--cache-dir", t.TempDir(), ) @@ -630,7 +630,7 @@ func TestServer(t *testing.T) { "--http-address", "", "--access-url", "http://example.com", "--tls-enable", - "--tls-address", ":0", + "--tls-address", "127.0.0.1:0", "--tls-min-version", "tls9", "--cache-dir", t.TempDir(), ) @@ -648,7 +648,7 @@ func TestServer(t *testing.T) { "--http-address", "", "--access-url", "http://example.com", "--tls-enable", - "--tls-address", ":0", + "--tls-address", "127.0.0.1:0", "--tls-client-auth", "something", "--cache-dir", t.TempDir(), ) @@ -697,7 +697,7 @@ func TestServer(t *testing.T) { args := []string{ "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--cache-dir", t.TempDir(), } @@ -722,7 +722,7 @@ func TestServer(t *testing.T) { "--http-address", "", "--access-url", "https://example.com", "--tls-enable", - "--tls-address", ":0", + "--tls-address", "127.0.0.1:0", "--tls-cert-file", certPath, "--tls-key-file", keyPath, "--cache-dir", t.TempDir(), @@ -758,7 +758,7 @@ func TestServer(t *testing.T) { "--http-address", "", "--access-url", "https://example.com", "--tls-enable", - "--tls-address", ":0", + "--tls-address", "127.0.0.1:0", "--tls-cert-file", cert1Path, "--tls-key-file", key1Path, "--tls-cert-file", cert2Path, @@ -833,11 +833,11 @@ func TestServer(t *testing.T) { inv, _ := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "https://example.com", "--tls-enable", "--tls-redirect-http-to-https=false", - "--tls-address", ":0", + "--tls-address", "127.0.0.1:0", "--tls-cert-file", certPath, "--tls-key-file", keyPath, "--cache-dir", t.TempDir(), @@ -952,7 +952,7 @@ func TestServer(t *testing.T) { httpListenAddr := "" if c.httpListener { - httpListenAddr = ":0" + httpListenAddr = "127.0.0.1:0" } certPath, keyPath := generateTLSCertificate(t) @@ -965,7 +965,7 @@ func TestServer(t *testing.T) { if c.tlsListener { flags = append(flags, "--tls-enable", - "--tls-address", ":0", + "--tls-address", "127.0.0.1:0", "--tls-cert-file", certPath, "--tls-key-file", keyPath, "--wildcard-access-url", "*.example.com", @@ -1153,7 +1153,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--address", ":0", + "--address", "127.0.0.1:0", "--access-url", "http://example.com", "--cache-dir", t.TempDir(), ) @@ -1178,7 +1178,7 @@ func TestServer(t *testing.T) { root, cfg := clitest.New(t, "server", dbArg(t), - "--address", ":0", + "--address", "127.0.0.1:0", "--access-url", "https://example.com", "--tls-enable", "--tls-cert-file", certPath, @@ -1213,7 +1213,7 @@ func TestServer(t *testing.T) { inv, _ := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--trace=true", "--cache-dir", t.TempDir(), @@ -1235,7 +1235,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--telemetry", "--telemetry-url", telemetryServerURL.String(), @@ -1275,11 +1275,11 @@ func TestServer(t *testing.T) { inv, _ := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--provisioner-daemons", "1", "--prometheus-enable", - "--prometheus-address", ":0", + "--prometheus-address", "127.0.0.1:0", // "--prometheus-collect-db-metrics", // disabled by default "--cache-dir", t.TempDir(), ) @@ -1336,11 +1336,11 @@ func TestServer(t *testing.T) { inv, _ := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--provisioner-daemons", "1", "--prometheus-enable", - "--prometheus-address", ":0", + "--prometheus-address", "127.0.0.1:0", "--prometheus-collect-db-metrics", "--cache-dir", t.TempDir(), ) @@ -1392,7 +1392,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--oauth2-github-allow-everyone", "--oauth2-github-client-id", "fake", @@ -1439,7 +1439,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--oidc-client-id", "fake", "--oidc-client-secret", "fake", @@ -1515,7 +1515,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--oidc-client-id", "fake", "--oidc-client-secret", "fake", @@ -1616,7 +1616,7 @@ func TestServer(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--oidc-client-id", "fake", "--oidc-client-secret", "fake", @@ -1668,7 +1668,7 @@ func TestServer(t *testing.T) { root, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", ) serverErr := make(chan error, 1) @@ -1696,7 +1696,7 @@ func TestServer(t *testing.T) { root, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--api-rate-limit", val, ) @@ -1724,7 +1724,7 @@ func TestServer(t *testing.T) { root, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--api-rate-limit", "-1", ) @@ -1756,7 +1756,7 @@ func TestServer(t *testing.T) { "server", "--log-filter=.*", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--provisioner-daemons=3", "--provisioner-types=echo", @@ -1775,7 +1775,7 @@ func TestServer(t *testing.T) { "server", "--log-filter=.*", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--provisioner-daemons=3", "--provisioner-types=echo", @@ -1794,7 +1794,7 @@ func TestServer(t *testing.T) { "server", "--log-filter=.*", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--provisioner-daemons=3", "--provisioner-types=echo", @@ -1818,7 +1818,7 @@ func TestServer(t *testing.T) { args := []string{ "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--log-human", filepath.Join(t.TempDir(), "coder-logging-test-human"), // We use ecdsa here because it's the fastest alternative algorithm. @@ -2017,7 +2017,7 @@ func TestServer_ExternalAuthGitHubDefaultProvider(t *testing.T) { args := []string{ "server", "--postgres-url", dbURL, - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "https://example.com", } args = append(args, tc.args...) @@ -2142,7 +2142,7 @@ func TestServer_Logging_NoParallel(t *testing.T) { "server", "--log-filter=.*", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--provisioner-daemons=3", "--provisioner-types=echo", @@ -2177,7 +2177,7 @@ func TestServer_Logging_NoParallel(t *testing.T) { "server", "--log-filter=.*", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--provisioner-daemons=3", "--provisioner-types=echo", @@ -2234,7 +2234,7 @@ func TestServer_Production(t *testing.T) { inv, cfg := clitest.New(t, "server", - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", dbArg(t), "--cache-dir", t.TempDir(), @@ -2293,7 +2293,7 @@ func TestServer_InterruptShutdown(t *testing.T) { root, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--provisioner-daemons", "1", "--cache-dir", t.TempDir(), @@ -2330,7 +2330,7 @@ func TestServer_AIGatewayShutdownOrdering(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--cache-dir", t.TempDir(), // Explicit so the test catches the regression even if the @@ -2372,7 +2372,7 @@ func TestServer_GracefulShutdown(t *testing.T) { root, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--provisioner-daemons", "1", "--cache-dir", t.TempDir(), @@ -2557,7 +2557,7 @@ func TestServer_DisabledDERP_EmptyBaseMap(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--derp-server-enable=false", ) @@ -2582,7 +2582,7 @@ func TestServer_DisabledDERP_ExternalMap(t *testing.T) { inv, cfg := clitest.New(t, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--derp-server-enable=false", "--derp-config-url", srv.URL, @@ -2620,7 +2620,7 @@ func TestServer_TelemetryDisabled_FinalReport(t *testing.T) { inv, _ := clitest.New(t, "server", "--postgres-url", dbConnURL, - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--telemetry="+strconv.FormatBool(!opts.telemetryDisabled), "--telemetry-url", telemetryServerURL.String(), diff --git a/coderd/workspaceapps/apptest/apptest.go b/coderd/workspaceapps/apptest/apptest.go index 0454e7b58d7..cefdf90a54f 100644 --- a/coderd/workspaceapps/apptest/apptest.go +++ b/coderd/workspaceapps/apptest/apptest.go @@ -2158,7 +2158,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { // server canonicalizes all HTTP request headers it receives, so we // can't use it to test that we forward non-canonical headers. // #nosec - ln, err := net.Listen("tcp", ":0") + ln, err := net.Listen("tcp", "127.0.0.1:0") require.NoError(t, err) go func() { for { diff --git a/enterprise/cli/proxyserver_test.go b/enterprise/cli/proxyserver_test.go index 3861dcf785d..0924b4a82d3 100644 --- a/enterprise/cli/proxyserver_test.go +++ b/enterprise/cli/proxyserver_test.go @@ -46,7 +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", + "--http-address", "127.0.0.1:0", "--header", fmt.Sprintf("%s=%s", headerName1, headerVal1), "--header-command", fmt.Sprintf("printf %s=%s", headerName2, headerVal2), ) @@ -94,7 +94,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", ":0", + "--http-address", "127.0.0.1:0", "--prometheus-enable", "--prometheus-address", fmt.Sprintf("127.0.0.1:%d", prometheusPort), ) diff --git a/enterprise/cli/server_dbcrypt_test.go b/enterprise/cli/server_dbcrypt_test.go index d13e1a877fe..0915f2d3157 100644 --- a/enterprise/cli/server_dbcrypt_test.go +++ b/enterprise/cli/server_dbcrypt_test.go @@ -386,7 +386,7 @@ func TestServerAIProviderKeysEncryptedWithDBCrypt(t *testing.T) { inv, cfg := clitest.NewWithCommand(t, cmd, "server", "--postgres-url="+dbURL, - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", "--external-token-encryption-keys", b64Key, "--aibridge-enabled", diff --git a/enterprise/cli/server_test.go b/enterprise/cli/server_test.go index 38001b701a9..154c930c8f2 100644 --- a/enterprise/cli/server_test.go +++ b/enterprise/cli/server_test.go @@ -38,7 +38,7 @@ func TestServer_Single(t *testing.T) { inv, cfg := clitest.NewWithCommand(t, cmd, "server", dbArg(t), - "--http-address", ":0", + "--http-address", "127.0.0.1:0", "--access-url", "http://example.com", ) clitest.Start(t, inv.WithContext(ctx))