From 700e2c97de172b03acc3d3632059d9a25667a44a Mon Sep 17 00:00:00 2001 From: Anders Eknert Date: Thu, 17 Aug 2023 15:56:35 +0200 Subject: [PATCH] Bind test server to localhost interface (#6164) Fixes #6162 Signed-off-by: Anders Eknert --- cmd/run_test.go | 6 +++--- internal/gojsonschema/jsonschema_test.go | 2 +- runtime/logging_test.go | 2 +- runtime/runtime_test.go | 6 +++--- server/server_test.go | 6 +++--- test/e2e/diagnostics/diagnostics_test.go | 3 ++- test/e2e/distributedtracing/distributedtracing_test.go | 1 + test/e2e/h2c/h2c_test.go | 4 ++-- test/e2e/testing.go | 2 +- 9 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cmd/run_test.go b/cmd/run_test.go index a0ad554e96..bc83a9862e 100644 --- a/cmd/run_test.go +++ b/cmd/run_test.go @@ -50,7 +50,7 @@ func TestRunServerBase(t *testing.T) { func TestRunServerWithDiagnosticAddr(t *testing.T) { params := newTestRunParams() - params.rt.DiagnosticAddrs = &[]string{":0"} + params.rt.DiagnosticAddrs = &[]string{"localhost:0"} ctx, cancel := context.WithCancel(context.Background()) rt, err := initRuntime(ctx, params, nil, false) @@ -194,7 +194,7 @@ func TestInitRuntimeAddrSetByUser(t *testing.T) { } params := newTestRunParams() - params.rt.Addrs = &[]string{":0"} + params.rt.Addrs = &[]string{"localhost:0"} ctx, cancel := context.WithCancel(context.Background()) rt, err := initRuntime(ctx, params, []string{}, cmd.Flags().Changed("addr")) @@ -214,7 +214,7 @@ func TestInitRuntimeAddrSetByUser(t *testing.T) { func newTestRunParams() runCmdParams { params := newRunParams() params.rt.GracefulShutdownPeriod = 1 - params.rt.Addrs = &[]string{":0"} + params.rt.Addrs = &[]string{"localhost:0"} params.rt.DiagnosticAddrs = &[]string{} params.serverMode = true return params diff --git a/internal/gojsonschema/jsonschema_test.go b/internal/gojsonschema/jsonschema_test.go index aa7767f653..7381caa733 100644 --- a/internal/gojsonschema/jsonschema_test.go +++ b/internal/gojsonschema/jsonschema_test.go @@ -126,7 +126,7 @@ func TestSuite(t *testing.T) { wd = filepath.Join(wd, "testdata") go func() { - err := http.ListenAndServe(":1234", http.FileServer(http.Dir(filepath.Join(wd, "remotes")))) + err := http.ListenAndServe("localhost:1234", http.FileServer(http.Dir(filepath.Join(wd, "remotes")))) if err != nil { panic(err.Error()) diff --git a/runtime/logging_test.go b/runtime/logging_test.go index 6a823ac388..facd0d9717 100644 --- a/runtime/logging_test.go +++ b/runtime/logging_test.go @@ -110,7 +110,7 @@ func TestRequestLogging(t *testing.T) { gzipMinLength := "server.encoding.gzip.min_length=5" shutdownSeconds := 1 params := NewParams() - params.Addrs = &[]string{":0"} + params.Addrs = &[]string{"localhost:0"} params.Logger = logger params.PprofEnabled = true params.GracefulShutdownPeriod = shutdownSeconds // arbitrary, must be non-zero diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index f71d7c52e1..f9674be272 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -293,7 +293,7 @@ func TestCheckAuthIneffective(t *testing.T) { logger.SetOutput(stdout) params.Logger = logger - params.Addrs = &[]string{":0"} + params.Addrs = &[]string{"localhost:0"} params.GracefulShutdownPeriod = 1 rt, err := NewRuntime(ctx, params) if err != nil { @@ -321,7 +321,7 @@ func TestServerInitialized(t *testing.T) { params := NewParams() params.Output = &output - params.Addrs = &[]string{":0"} + params.Addrs = &[]string{"localhost:0"} params.GracefulShutdownPeriod = 1 params.Logger = logging.NewNoOpLogger() @@ -476,7 +476,7 @@ func TestAddrWarningMessage(t *testing.T) { logLevel := logging.Info params.Logger = logger - params.Addrs = &[]string{":8181"} + params.Addrs = &[]string{"localhost:8181"} params.AddrSetByUser = tc.addrSetByUser params.GracefulShutdownPeriod = 1 rt, err := NewRuntime(ctx, params) diff --git a/server/server_test.go b/server/server_test.go index 3f69f6a9ee..59cb03f62a 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -3511,7 +3511,7 @@ func TestStatusV1MetricsWithSystemAuthzPolicy(t *testing.T) { func TestQueryPostBasic(t *testing.T) { f := newFixture(t) f.server, _ = New(). - WithAddresses([]string{":8182"}). + WithAddresses([]string{"localhost:8182"}). WithStore(f.server.store). WithManager(f.server.manager). Init(context.Background()) @@ -4024,7 +4024,7 @@ func TestAuthorization(t *testing.T) { } server, err := New(). - WithAddresses([]string{":8182"}). + WithAddresses([]string{"localhost:8182"}). WithStore(store). WithManager(m). WithAuthorization(AuthorizationBasic). @@ -4155,7 +4155,7 @@ allow { } server, err := New(). - WithAddresses([]string{":8182"}). + WithAddresses([]string{"localhost:8182"}). WithStore(store). WithManager(m). WithAuthorization(AuthorizationBasic). diff --git a/test/e2e/diagnostics/diagnostics_test.go b/test/e2e/diagnostics/diagnostics_test.go index 0b2cdd028d..f6b0a76fd1 100644 --- a/test/e2e/diagnostics/diagnostics_test.go +++ b/test/e2e/diagnostics/diagnostics_test.go @@ -15,7 +15,8 @@ var testRuntime *e2e.TestRuntime func TestMain(m *testing.M) { flag.Parse() testServerParams := e2e.NewAPIServerTestParams() - testServerParams.DiagnosticAddrs = &[]string{":0"} + testServerParams.Addrs = &[]string{"localhost:0"} + testServerParams.DiagnosticAddrs = &[]string{"localhost:0"} var err error testRuntime, err = e2e.NewTestRuntimeWithOpts(e2e.TestRuntimeOpts{}, testServerParams) diff --git a/test/e2e/distributedtracing/distributedtracing_test.go b/test/e2e/distributedtracing/distributedtracing_test.go index d34367ecb7..4f90b761b2 100644 --- a/test/e2e/distributedtracing/distributedtracing_test.go +++ b/test/e2e/distributedtracing/distributedtracing_test.go @@ -38,6 +38,7 @@ func TestMain(m *testing.M) { flag.Parse() testServerParams := e2e.NewAPIServerTestParams() testServerParams.DistributedTracingOpts = options + testServerParams.Addrs = &[]string{"localhost:0"} var err error testRuntime, err = e2e.NewTestRuntime(testServerParams) diff --git a/test/e2e/h2c/h2c_test.go b/test/e2e/h2c/h2c_test.go index 25446e6d5e..520bcd20ae 100644 --- a/test/e2e/h2c/h2c_test.go +++ b/test/e2e/h2c/h2c_test.go @@ -18,8 +18,8 @@ var testRuntime *e2e.TestRuntime func TestMain(m *testing.M) { flag.Parse() testServerParams := e2e.NewAPIServerTestParams() - testServerParams.Addrs = &[]string{":0"} - testServerParams.DiagnosticAddrs = &[]string{":0"} + testServerParams.Addrs = &[]string{"localhost:0"} + testServerParams.DiagnosticAddrs = &[]string{"localhost:0"} testServerParams.H2CEnabled = true var err error diff --git a/test/e2e/testing.go b/test/e2e/testing.go index db6a18beab..6fd48a4f0c 100644 --- a/test/e2e/testing.go +++ b/test/e2e/testing.go @@ -29,7 +29,7 @@ import ( ) const ( - defaultAddr = ":0" // default listening address for server, use a random open port + defaultAddr = "localhost:0" // default listening address for server, use a random open port ) // NewAPIServerTestParams creates a new set of runtime.Params with enough