mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
integration: add "TestTLSReloadCopyIPOnly"
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
233af4b4ec
commit
6ab9776601
@ -124,6 +124,9 @@ type ClusterConfig struct {
|
|||||||
|
|
||||||
ClientMaxCallSendMsgSize int
|
ClientMaxCallSendMsgSize int
|
||||||
ClientMaxCallRecvMsgSize int
|
ClientMaxCallRecvMsgSize int
|
||||||
|
|
||||||
|
// UseIP is true to use only IP for gRPC requests.
|
||||||
|
UseIP bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type cluster struct {
|
type cluster struct {
|
||||||
@ -262,6 +265,7 @@ func (c *cluster) mustNewMember(t *testing.T) *member {
|
|||||||
grpcKeepAliveTimeout: c.cfg.GRPCKeepAliveTimeout,
|
grpcKeepAliveTimeout: c.cfg.GRPCKeepAliveTimeout,
|
||||||
clientMaxCallSendMsgSize: c.cfg.ClientMaxCallSendMsgSize,
|
clientMaxCallSendMsgSize: c.cfg.ClientMaxCallSendMsgSize,
|
||||||
clientMaxCallRecvMsgSize: c.cfg.ClientMaxCallRecvMsgSize,
|
clientMaxCallRecvMsgSize: c.cfg.ClientMaxCallRecvMsgSize,
|
||||||
|
useIP: c.cfg.UseIP,
|
||||||
})
|
})
|
||||||
m.DiscoveryURL = c.cfg.DiscoveryURL
|
m.DiscoveryURL = c.cfg.DiscoveryURL
|
||||||
if c.cfg.UseGRPC {
|
if c.cfg.UseGRPC {
|
||||||
@ -525,6 +529,7 @@ type member struct {
|
|||||||
keepDataDirTerminate bool
|
keepDataDirTerminate bool
|
||||||
clientMaxCallSendMsgSize int
|
clientMaxCallSendMsgSize int
|
||||||
clientMaxCallRecvMsgSize int
|
clientMaxCallRecvMsgSize int
|
||||||
|
useIP bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *member) GRPCAddr() string { return m.grpcAddr }
|
func (m *member) GRPCAddr() string { return m.grpcAddr }
|
||||||
@ -541,6 +546,7 @@ type memberConfig struct {
|
|||||||
grpcKeepAliveTimeout time.Duration
|
grpcKeepAliveTimeout time.Duration
|
||||||
clientMaxCallSendMsgSize int
|
clientMaxCallSendMsgSize int
|
||||||
clientMaxCallRecvMsgSize int
|
clientMaxCallRecvMsgSize int
|
||||||
|
useIP bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// mustNewMember return an inited member with the given name. If peerTLS is
|
// mustNewMember return an inited member with the given name. If peerTLS is
|
||||||
@ -614,6 +620,7 @@ func mustNewMember(t *testing.T, mcfg memberConfig) *member {
|
|||||||
}
|
}
|
||||||
m.clientMaxCallSendMsgSize = mcfg.clientMaxCallSendMsgSize
|
m.clientMaxCallSendMsgSize = mcfg.clientMaxCallSendMsgSize
|
||||||
m.clientMaxCallRecvMsgSize = mcfg.clientMaxCallRecvMsgSize
|
m.clientMaxCallRecvMsgSize = mcfg.clientMaxCallRecvMsgSize
|
||||||
|
m.useIP = mcfg.useIP
|
||||||
|
|
||||||
m.InitialCorruptCheck = true
|
m.InitialCorruptCheck = true
|
||||||
|
|
||||||
@ -624,6 +631,9 @@ func mustNewMember(t *testing.T, mcfg memberConfig) *member {
|
|||||||
func (m *member) listenGRPC() error {
|
func (m *member) listenGRPC() error {
|
||||||
// prefix with localhost so cert has right domain
|
// prefix with localhost so cert has right domain
|
||||||
m.grpcAddr = "localhost:" + m.Name
|
m.grpcAddr = "localhost:" + m.Name
|
||||||
|
if m.useIP { // for IP-only sTLS certs
|
||||||
|
m.grpcAddr = "127.0.0.1:" + m.Name
|
||||||
|
}
|
||||||
l, err := transport.NewUnixListener(m.grpcAddr)
|
l, err := transport.NewUnixListener(m.grpcAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("listen failed on grpc socket %s (%v)", m.grpcAddr, err)
|
return fmt.Errorf("listen failed on grpc socket %s (%v)", m.grpcAddr, err)
|
||||||
|
@ -1654,7 +1654,7 @@ func TestTLSReloadAtomicReplace(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testTLSReload(t, cloneFunc, replaceFunc, revertFunc)
|
testTLSReload(t, cloneFunc, replaceFunc, revertFunc, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTLSReloadCopy ensures server reloads expired/valid certs
|
// TestTLSReloadCopy ensures server reloads expired/valid certs
|
||||||
@ -1684,17 +1684,57 @@ func TestTLSReloadCopy(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
testTLSReload(t, cloneFunc, replaceFunc, revertFunc)
|
testTLSReload(t, cloneFunc, replaceFunc, revertFunc, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testTLSReload(t *testing.T, cloneFunc func() transport.TLSInfo, replaceFunc func(), revertFunc func()) {
|
// TestTLSReloadCopyIPOnly ensures server reloads expired/valid certs
|
||||||
|
// when new certs are copied over, one by one. And expects server
|
||||||
|
// to reject client requests, and vice versa.
|
||||||
|
func TestTLSReloadCopyIPOnly(t *testing.T) {
|
||||||
|
certsDir, err := ioutil.TempDir(os.TempDir(), "fixtures-to-load")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(certsDir)
|
||||||
|
|
||||||
|
cloneFunc := func() transport.TLSInfo {
|
||||||
|
tlsInfo, terr := copyTLSFiles(testTLSInfoIP, certsDir)
|
||||||
|
if terr != nil {
|
||||||
|
t.Fatal(terr)
|
||||||
|
}
|
||||||
|
return tlsInfo
|
||||||
|
}
|
||||||
|
replaceFunc := func() {
|
||||||
|
if _, err = copyTLSFiles(testTLSInfoExpiredIP, certsDir); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
revertFunc := func() {
|
||||||
|
if _, err = copyTLSFiles(testTLSInfoIP, certsDir); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
testTLSReload(t, cloneFunc, replaceFunc, revertFunc, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTLSReload(
|
||||||
|
t *testing.T,
|
||||||
|
cloneFunc func() transport.TLSInfo,
|
||||||
|
replaceFunc func(),
|
||||||
|
revertFunc func(),
|
||||||
|
useIP bool) {
|
||||||
defer testutil.AfterTest(t)
|
defer testutil.AfterTest(t)
|
||||||
|
|
||||||
// 1. separate copies for TLS assets modification
|
// 1. separate copies for TLS assets modification
|
||||||
tlsInfo := cloneFunc()
|
tlsInfo := cloneFunc()
|
||||||
|
|
||||||
// 2. start cluster with valid certs
|
// 2. start cluster with valid certs
|
||||||
clus := NewClusterV3(t, &ClusterConfig{Size: 1, PeerTLS: &tlsInfo, ClientTLS: &tlsInfo})
|
clus := NewClusterV3(t, &ClusterConfig{
|
||||||
|
Size: 1,
|
||||||
|
PeerTLS: &tlsInfo,
|
||||||
|
ClientTLS: &tlsInfo,
|
||||||
|
UseIP: useIP,
|
||||||
|
})
|
||||||
defer clus.Terminate(t)
|
defer clus.Terminate(t)
|
||||||
|
|
||||||
// 3. concurrent client dialing while certs become expired
|
// 3. concurrent client dialing while certs become expired
|
||||||
|
Loading…
x
Reference in New Issue
Block a user