mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
Bind test server to localhost interface (#6164)
Fixes #6162 Signed-off-by: Anders Eknert <anders@styra.com>
This commit is contained in:
+3
-3
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user