-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage/raft: Advertise the configured cluster address (#9008)
* storage/raft: Advertise the configured cluster address * Don't allow raft to start with unspecified IP * Fix concurrent map write panic * Add test file * changelog++ * changelog++ * changelog++ * Update tcp_layer.go * Update tcp_layer.go * Only set the adverise addr if set
- Loading branch information
1 parent
b8799b3
commit 66d6fa2
Showing
8 changed files
with
142 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package raft | ||
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
"crypto/tls" | ||
"net" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/vault/vault/cluster" | ||
) | ||
|
||
type mockClusterHook struct { | ||
address net.Addr | ||
} | ||
|
||
func (*mockClusterHook) AddClient(alpn string, client cluster.Client) {} | ||
func (*mockClusterHook) RemoveClient(alpn string) {} | ||
func (*mockClusterHook) AddHandler(alpn string, handler cluster.Handler) {} | ||
func (*mockClusterHook) StopHandler(alpn string) {} | ||
func (*mockClusterHook) TLSConfig(ctx context.Context) (*tls.Config, error) { return nil, nil } | ||
func (m *mockClusterHook) Addr() net.Addr { return m.address } | ||
func (*mockClusterHook) GetDialerFunc(ctx context.Context, alpnProto string) func(string, time.Duration) (net.Conn, error) { | ||
return func(string, time.Duration) (net.Conn, error) { | ||
return nil, nil | ||
} | ||
} | ||
|
||
func TestStreamLayer_UnspecifiedIP(t *testing.T) { | ||
m := &mockClusterHook{ | ||
address: &cluster.NetAddr{ | ||
Host: "0.0.0.0:8200", | ||
}, | ||
} | ||
|
||
raftTLSKey, err := GenerateTLSKey(rand.Reader) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
raftTLS := &TLSKeyring{ | ||
Keys: []*TLSKey{raftTLSKey}, | ||
ActiveKeyID: raftTLSKey.ID, | ||
} | ||
|
||
layer, err := NewRaftLayer(nil, raftTLS, m) | ||
if err == nil { | ||
t.Fatal("expected error") | ||
} | ||
|
||
if err.Error() != "cannot use unspecified IP with raft storage: 0.0.0.0:8200" { | ||
t.Fatalf("unexpected error: %s", err.Error()) | ||
} | ||
|
||
if layer != nil { | ||
t.Fatal("expected nil layer") | ||
} | ||
|
||
m.address.(*cluster.NetAddr).Host = "10.0.0.1:8200" | ||
|
||
layer, err = NewRaftLayer(nil, raftTLS, m) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if layer == nil { | ||
t.Fatal("nil layer") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters