mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
add test for transport/tls.go:ValidateSecureEndpoints()
This commit is contained in:
parent
bd7d09255b
commit
983ee82c98
36
client/pkg/transport/tls_test.go
Normal file
36
client/pkg/transport/tls_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateSecureEndpoints(t *testing.T) {
|
||||
tlsInfo, err := createSelfCert(t)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create cert: %v", err)
|
||||
}
|
||||
|
||||
remoteAddr := func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(r.RemoteAddr))
|
||||
}
|
||||
srv := httptest.NewServer(http.HandlerFunc(remoteAddr))
|
||||
defer srv.Close()
|
||||
|
||||
insecureEps := []string{
|
||||
"http://" + srv.Listener.Addr().String(),
|
||||
"invalid remote address",
|
||||
}
|
||||
if _, err := ValidateSecureEndpoints(*tlsInfo, insecureEps); err == nil || !strings.Contains(err.Error(), "is insecure") {
|
||||
t.Error("validate secure endpoints should fail")
|
||||
}
|
||||
|
||||
secureEps := []string{
|
||||
"https://" + srv.Listener.Addr().String(),
|
||||
}
|
||||
if _, err := ValidateSecureEndpoints(*tlsInfo, secureEps); err != nil {
|
||||
t.Error("validate secure endpoints should succeed")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user