mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
add uds test cases into e2e TestAuthority
Signed-off-by: Chao Chen <chaochn@amazon.com>
This commit is contained in:
parent
80e2064b40
commit
a1aaa51cf1
@ -622,10 +622,10 @@ func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err erro
|
||||
for _, u := range append(cfg.ListenClientUrls, cfg.ListenClientHttpUrls...) {
|
||||
if u.Scheme == "http" || u.Scheme == "unix" {
|
||||
if !cfg.ClientTLSInfo.Empty() {
|
||||
cfg.logger.Warn("scheme is HTTP while key and cert files are present; ignoring key and cert files", zap.String("client-url", u.String()))
|
||||
cfg.logger.Warn("scheme is http or unix while key and cert files are present; ignoring key and cert files", zap.String("client-url", u.String()))
|
||||
}
|
||||
if cfg.ClientTLSInfo.ClientCertAuth {
|
||||
cfg.logger.Warn("scheme is HTTP while --client-cert-auth is enabled; ignoring client cert auth for this URL", zap.String("client-url", u.String()))
|
||||
cfg.logger.Warn("scheme is http or unix while --client-cert-auth is enabled; ignoring client cert auth for this URL", zap.String("client-url", u.String()))
|
||||
}
|
||||
}
|
||||
if (u.Scheme == "https" || u.Scheme == "unixs") && cfg.ClientTLSInfo.Empty() {
|
||||
|
@ -33,6 +33,7 @@ import (
|
||||
func TestAuthority(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
useUnix bool
|
||||
useTLS bool
|
||||
useInsecureTLS bool
|
||||
// Pattern used to generate endpoints for client. Fields filled
|
||||
@ -43,6 +44,33 @@ func TestAuthority(t *testing.T) {
|
||||
// ${MEMBER_PORT} - will be filled with member grpc port
|
||||
expectAuthorityPattern string
|
||||
}{
|
||||
{
|
||||
name: "unix:path",
|
||||
useUnix: true,
|
||||
clientURLPattern: "unix:localhost:%d",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "unix://absolute_path",
|
||||
useUnix: true,
|
||||
clientURLPattern: "unix://localhost:%d",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_PORT}",
|
||||
},
|
||||
// "unixs" is not standard schema supported by etcd
|
||||
{
|
||||
name: "unixs:absolute_path",
|
||||
useUnix: true,
|
||||
useTLS: true,
|
||||
clientURLPattern: "unixs:localhost:%d",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "unixs://absolute_path",
|
||||
useUnix: true,
|
||||
useTLS: true,
|
||||
clientURLPattern: "unixs://localhost:%d",
|
||||
expectAuthorityPattern: "localhost:${MEMBER_PORT}",
|
||||
},
|
||||
{
|
||||
name: "http://domain[:port]",
|
||||
clientURLPattern: "http://localhost:%d",
|
||||
@ -93,6 +121,9 @@ func TestAuthority(t *testing.T) {
|
||||
cfg.IsClientAutoTLS = tc.useInsecureTLS
|
||||
// Enable debug mode to get logs with http2 headers (including authority)
|
||||
cfg.EnvVars = map[string]string{"GODEBUG": "http2debug=2"}
|
||||
if tc.useUnix {
|
||||
cfg.BaseClientScheme = "unix"
|
||||
}
|
||||
|
||||
epc, err := e2e.NewEtcdProcessCluster(t, cfg)
|
||||
if err != nil {
|
||||
|
@ -58,7 +58,7 @@ func TestClusterVersion(t *testing.T) {
|
||||
cfg := e2e.NewConfigNoTLS()
|
||||
cfg.ExecPath = binary
|
||||
cfg.SnapshotCount = 3
|
||||
cfg.BaseScheme = "unix" // to avoid port conflict
|
||||
cfg.BasePeerScheme = "unix" // to avoid port conflict
|
||||
cfg.RollingStart = tt.rollingStart
|
||||
|
||||
epc, err := e2e.NewEtcdProcessCluster(t, cfg)
|
||||
|
@ -39,7 +39,7 @@ func TestReleaseUpgrade(t *testing.T) {
|
||||
copiedCfg := e2e.NewConfigNoTLS()
|
||||
copiedCfg.ExecPath = lastReleaseBinary
|
||||
copiedCfg.SnapshotCount = 3
|
||||
copiedCfg.BaseScheme = "unix" // to avoid port conflict
|
||||
copiedCfg.BasePeerScheme = "unix" // to avoid port conflict
|
||||
|
||||
epc, err := e2e.NewEtcdProcessCluster(t, copiedCfg)
|
||||
if err != nil {
|
||||
@ -125,7 +125,7 @@ func TestReleaseUpgradeWithRestart(t *testing.T) {
|
||||
copiedCfg := e2e.NewConfigNoTLS()
|
||||
copiedCfg.ExecPath = lastReleaseBinary
|
||||
copiedCfg.SnapshotCount = 10
|
||||
copiedCfg.BaseScheme = "unix"
|
||||
copiedCfg.BasePeerScheme = "unix"
|
||||
|
||||
epc, err := e2e.NewEtcdProcessCluster(t, copiedCfg)
|
||||
if err != nil {
|
||||
|
@ -148,8 +148,11 @@ type EtcdProcessClusterConfig struct {
|
||||
|
||||
ClusterSize int
|
||||
|
||||
BaseScheme string
|
||||
BasePort int
|
||||
// BasePeerScheme specifies scheme of --listen-peer-urls and --initial-advertise-peer-urls
|
||||
BasePeerScheme string
|
||||
BasePort int
|
||||
// BaseClientScheme specifies scheme of --listen-client-urls, --listen-client-http-urls and --initial-advertise-client-urls
|
||||
BaseClientScheme string
|
||||
|
||||
MetricsURLScheme string
|
||||
|
||||
@ -243,21 +246,11 @@ func StartEtcdProcessCluster(t testing.TB, epc *EtcdProcessCluster, cfg *EtcdPro
|
||||
}
|
||||
|
||||
func (cfg *EtcdProcessClusterConfig) ClientScheme() string {
|
||||
if cfg.ClientTLS == ClientTLS {
|
||||
return "https"
|
||||
}
|
||||
return "http"
|
||||
return setupScheme(cfg.BaseClientScheme, cfg.ClientTLS == ClientTLS)
|
||||
}
|
||||
|
||||
func (cfg *EtcdProcessClusterConfig) PeerScheme() string {
|
||||
peerScheme := cfg.BaseScheme
|
||||
if peerScheme == "" {
|
||||
peerScheme = "http"
|
||||
}
|
||||
if cfg.IsPeerTLS {
|
||||
peerScheme += "s"
|
||||
}
|
||||
return peerScheme
|
||||
return setupScheme(cfg.BasePeerScheme, cfg.IsPeerTLS)
|
||||
}
|
||||
|
||||
func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfigs(tb testing.TB) []*EtcdServerProcessConfig {
|
||||
@ -285,10 +278,10 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfigs(tb testing.TB) []*
|
||||
clientHttpPort := port + 4
|
||||
|
||||
if cfg.ClientTLS == ClientTLSAndNonTLS {
|
||||
curl = clientURL(clientPort, ClientNonTLS)
|
||||
curls = []string{curl, clientURL(clientPort, ClientTLS)}
|
||||
curl = clientURL(cfg.ClientScheme(), clientPort, ClientNonTLS)
|
||||
curls = []string{curl, clientURL(cfg.ClientScheme(), clientPort, ClientTLS)}
|
||||
} else {
|
||||
curl = clientURL(clientPort, cfg.ClientTLS)
|
||||
curl = clientURL(cfg.ClientScheme(), clientPort, cfg.ClientTLS)
|
||||
curls = []string{curl}
|
||||
}
|
||||
|
||||
@ -326,7 +319,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfigs(tb testing.TB) []*
|
||||
}
|
||||
var clientHttpUrl string
|
||||
if cfg.ClientHttpSeparate {
|
||||
clientHttpUrl = clientURL(clientHttpPort, cfg.ClientTLS)
|
||||
clientHttpUrl = clientURL(cfg.ClientScheme(), clientHttpPort, cfg.ClientTLS)
|
||||
args = append(args, "--listen-client-http-urls", clientHttpUrl)
|
||||
}
|
||||
args = AddV2Args(args)
|
||||
@ -429,13 +422,13 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfigs(tb testing.TB) []*
|
||||
return etcdCfgs
|
||||
}
|
||||
|
||||
func clientURL(port int, connType ClientConnType) string {
|
||||
func clientURL(scheme string, port int, connType ClientConnType) string {
|
||||
curlHost := fmt.Sprintf("localhost:%d", port)
|
||||
switch connType {
|
||||
case ClientNonTLS:
|
||||
return (&url.URL{Scheme: "http", Host: curlHost}).String()
|
||||
return (&url.URL{Scheme: scheme, Host: curlHost}).String()
|
||||
case ClientTLS:
|
||||
return (&url.URL{Scheme: "https", Host: curlHost}).String()
|
||||
return (&url.URL{Scheme: ToTLS(scheme), Host: curlHost}).String()
|
||||
default:
|
||||
panic(fmt.Sprintf("Unsupported connection type %v", connType))
|
||||
}
|
||||
|
@ -120,8 +120,24 @@ func CloseWithTimeout(p *expect.ExpectProcess, d time.Duration) error {
|
||||
return fmt.Errorf("took longer than %v to Close process %+v", d, p)
|
||||
}
|
||||
|
||||
func setupScheme(s string, isTLS bool) string {
|
||||
if s == "" {
|
||||
s = "http"
|
||||
}
|
||||
if isTLS {
|
||||
s = ToTLS(s)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func ToTLS(s string) string {
|
||||
return strings.Replace(s, "http://", "https://", 1)
|
||||
if strings.Contains(s, "http") && !strings.Contains(s, "https") {
|
||||
return strings.Replace(s, "http", "https", 1)
|
||||
}
|
||||
if strings.Contains(s, "unix") && !strings.Contains(s, "unixs") {
|
||||
return strings.Replace(s, "unix", "unixs", 1)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func SkipInShortMode(t testing.TB) {
|
||||
|
@ -38,7 +38,7 @@ import (
|
||||
"go.etcd.io/etcd/client/pkg/v3/transport"
|
||||
"go.etcd.io/etcd/client/pkg/v3/types"
|
||||
"go.etcd.io/etcd/client/v2"
|
||||
"go.etcd.io/etcd/client/v3"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"go.etcd.io/etcd/pkg/v3/grpc_testing"
|
||||
"go.etcd.io/etcd/raft/v3"
|
||||
"go.etcd.io/etcd/server/v3/config"
|
||||
@ -192,6 +192,7 @@ func schemeFromTLSInfo(tls *transport.TLSInfo) string {
|
||||
return URLSchemeTLS
|
||||
}
|
||||
|
||||
// fillClusterForMembers fills up Member.InitialPeerURLsMap from each member's [name, scheme and PeerListeners address]
|
||||
func (c *cluster) fillClusterForMembers() error {
|
||||
if c.cfg.DiscoveryURL != "" {
|
||||
// cluster will be discovered
|
||||
|
Loading…
x
Reference in New Issue
Block a user