mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #6568 from gyuho/e2e
e2e: test 'https' scheme endpoints
This commit is contained in:
commit
b7f02a8c0a
@ -15,17 +15,11 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/etcd/clientv3"
|
"github.com/coreos/etcd/clientv3"
|
||||||
"github.com/coreos/etcd/embed"
|
|
||||||
"github.com/coreos/etcd/integration"
|
"github.com/coreos/etcd/integration"
|
||||||
"github.com/coreos/etcd/pkg/testutil"
|
"github.com/coreos/etcd/pkg/testutil"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
@ -64,69 +58,3 @@ func TestDialSetEndpoints(t *testing.T) {
|
|||||||
}
|
}
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
testMu sync.Mutex
|
|
||||||
testPort = 31000
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestDialWithHTTPS ensures that client can handle 'https' scheme in endpoints.
|
|
||||||
func TestDialWithHTTPS(t *testing.T) {
|
|
||||||
defer testutil.AfterTest(t)
|
|
||||||
|
|
||||||
testMu.Lock()
|
|
||||||
port := testPort
|
|
||||||
testPort += 10 // to avoid port conflicts
|
|
||||||
testMu.Unlock()
|
|
||||||
|
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "dial-test")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
// set up single-node cluster with client auto TLS
|
|
||||||
cfg := embed.NewConfig()
|
|
||||||
cfg.Dir = dir
|
|
||||||
|
|
||||||
cfg.ClientAutoTLS = true
|
|
||||||
clientURL := url.URL{Scheme: "https", Host: fmt.Sprintf("localhost:%d", port)}
|
|
||||||
cfg.LCUrls, cfg.ACUrls = []url.URL{clientURL}, []url.URL{clientURL}
|
|
||||||
|
|
||||||
peerURL := url.URL{Scheme: "http", Host: fmt.Sprintf("localhost:%d", port+1)}
|
|
||||||
cfg.LPUrls, cfg.APUrls = []url.URL{peerURL}, []url.URL{peerURL}
|
|
||||||
cfg.InitialCluster = cfg.Name + "=" + peerURL.String()
|
|
||||||
|
|
||||||
srv, err := embed.StartEtcd(cfg)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
nc := srv.Config() // overwrite config after processing ClientTLSInfo
|
|
||||||
cfg = &nc
|
|
||||||
|
|
||||||
<-srv.Server.ReadyNotify()
|
|
||||||
defer func() {
|
|
||||||
srv.Close()
|
|
||||||
<-srv.Err()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// wait for leader election to finish
|
|
||||||
time.Sleep(500 * time.Millisecond)
|
|
||||||
|
|
||||||
ccfg := clientv3.Config{Endpoints: []string{clientURL.String()}}
|
|
||||||
tcfg, err := cfg.ClientTLSInfo.ClientConfig()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
ccfg.TLS = tcfg
|
|
||||||
|
|
||||||
cli, err := clientv3.New(ccfg)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer cli.Close()
|
|
||||||
|
|
||||||
if _, err = cli.Get(context.Background(), "foo"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -37,6 +37,18 @@ func ctlV3Version(cx ctlCtx) error {
|
|||||||
return spawnWithExpect(cmdArgs, version.Version)
|
return spawnWithExpect(cmdArgs, version.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestCtlV3DialWithHTTPScheme ensures that client handles endpoints with HTTPS scheme.
|
||||||
|
func TestCtlV3DialWithHTTPScheme(t *testing.T) {
|
||||||
|
testCtl(t, dialWithSchemeTest, withCfg(configClientTLS))
|
||||||
|
}
|
||||||
|
|
||||||
|
func dialWithSchemeTest(cx ctlCtx) {
|
||||||
|
cmdArgs := append(cx.prefixArgs(cx.epc.endpoints()), "put", "foo", "bar")
|
||||||
|
if err := spawnWithExpect(cmdArgs, "OK"); err != nil {
|
||||||
|
cx.t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type ctlCtx struct {
|
type ctlCtx struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
cfg etcdProcessClusterConfig
|
cfg etcdProcessClusterConfig
|
||||||
@ -141,12 +153,12 @@ func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cx *ctlCtx) PrefixArgs() []string {
|
func (cx *ctlCtx) prefixArgs(eps []string) []string {
|
||||||
if len(cx.epc.proxies()) > 0 { // TODO: add proxy check as in v2
|
if len(cx.epc.proxies()) > 0 { // TODO: add proxy check as in v2
|
||||||
panic("v3 proxy not implemented")
|
panic("v3 proxy not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdArgs := []string{ctlBinPath, "--endpoints", strings.Join(cx.epc.grpcEndpoints(), ","), "--dial-timeout", cx.dialTimeout.String()}
|
cmdArgs := []string{ctlBinPath, "--endpoints", strings.Join(eps, ","), "--dial-timeout", cx.dialTimeout.String()}
|
||||||
if cx.epc.cfg.clientTLS == clientTLS {
|
if cx.epc.cfg.clientTLS == clientTLS {
|
||||||
if cx.epc.cfg.isClientAutoTLS {
|
if cx.epc.cfg.isClientAutoTLS {
|
||||||
cmdArgs = append(cmdArgs, "--insecure-transport=false", "--insecure-skip-tls-verify")
|
cmdArgs = append(cmdArgs, "--insecure-transport=false", "--insecure-skip-tls-verify")
|
||||||
@ -162,6 +174,10 @@ func (cx *ctlCtx) PrefixArgs() []string {
|
|||||||
return cmdArgs
|
return cmdArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cx *ctlCtx) PrefixArgs() []string {
|
||||||
|
return cx.prefixArgs(cx.epc.grpcEndpoints())
|
||||||
|
}
|
||||||
|
|
||||||
func isGRPCTimedout(err error) bool {
|
func isGRPCTimedout(err error) bool {
|
||||||
return strings.Contains(err.Error(), "grpc: timed out trying to connect")
|
return strings.Contains(err.Error(), "grpc: timed out trying to connect")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user