From e381c189e4e4cc5a468f217728337175be67afa1 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Tue, 8 Nov 2016 10:31:35 -0500 Subject: [PATCH] Fix cluster testing on OSX; see the inline comment for details --- vault/testing.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/vault/testing.go b/vault/testing.go index f721da0e8..0ea8d5e71 100644 --- a/vault/testing.go +++ b/vault/testing.go @@ -584,6 +584,11 @@ func TestCluster(t *testing.T, handlers []http.Handler, base *CoreConfig, unseal } // Create three cores with the same physical and different redirect/cluster addrs + // N.B.: On OSX, instead of random ports, it assigns new ports to new + // listeners sequentially. Aside from being a bad idea in a security sense, + // it also broke tests that assumed it was OK to just use the port above + // the redirect addr. This has now been changed to 10 ports above, but if + // we ever do more than three nodes in a cluster it may need to be bumped. coreConfig := &CoreConfig{ Physical: physical.NewInmem(logger), HAPhysical: physical.NewInmemHA(logger), @@ -591,7 +596,7 @@ func TestCluster(t *testing.T, handlers []http.Handler, base *CoreConfig, unseal CredentialBackends: make(map[string]logical.Factory), AuditBackends: make(map[string]audit.Factory), RedirectAddr: fmt.Sprintf("https://127.0.0.1:%d", c1lns[0].Address.Port), - ClusterAddr: fmt.Sprintf("https://127.0.0.1:%d", c1lns[0].Address.Port+1), + ClusterAddr: fmt.Sprintf("https://127.0.0.1:%d", c1lns[0].Address.Port+10), DisableMlock: true, } @@ -629,7 +634,7 @@ func TestCluster(t *testing.T, handlers []http.Handler, base *CoreConfig, unseal coreConfig.RedirectAddr = fmt.Sprintf("https://127.0.0.1:%d", c2lns[0].Address.Port) if coreConfig.ClusterAddr != "" { - coreConfig.ClusterAddr = fmt.Sprintf("https://127.0.0.1:%d", c2lns[0].Address.Port+1) + coreConfig.ClusterAddr = fmt.Sprintf("https://127.0.0.1:%d", c2lns[0].Address.Port+10) } c2, err := NewCore(coreConfig) if err != nil { @@ -638,7 +643,7 @@ func TestCluster(t *testing.T, handlers []http.Handler, base *CoreConfig, unseal coreConfig.RedirectAddr = fmt.Sprintf("https://127.0.0.1:%d", c3lns[0].Address.Port) if coreConfig.ClusterAddr != "" { - coreConfig.ClusterAddr = fmt.Sprintf("https://127.0.0.1:%d", c3lns[0].Address.Port+1) + coreConfig.ClusterAddr = fmt.Sprintf("https://127.0.0.1:%d", c3lns[0].Address.Port+10) } c3, err := NewCore(coreConfig) if err != nil { @@ -653,7 +658,7 @@ func TestCluster(t *testing.T, handlers []http.Handler, base *CoreConfig, unseal for i, ln := range lns { ret[i] = &net.TCPAddr{ IP: ln.Address.IP, - Port: ln.Address.Port + 1, + Port: ln.Address.Port + 10, } } return ret