github.com/portworx/docker@v1.12.1/integration-cli/docker_cli_sni_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "log" 7 "net/http" 8 "net/http/httptest" 9 "net/url" 10 "os/exec" 11 "strings" 12 13 "github.com/go-check/check" 14 ) 15 16 func (s *DockerSuite) TestClientSetsTLSServerName(c *check.C) { 17 c.Skip("Flakey test") 18 // there may be more than one hit to the server for each registry request 19 serverNameReceived := []string{} 20 var serverName string 21 22 virtualHostServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 23 serverNameReceived = append(serverNameReceived, r.TLS.ServerName) 24 })) 25 defer virtualHostServer.Close() 26 // discard TLS handshake errors written by default to os.Stderr 27 virtualHostServer.Config.ErrorLog = log.New(ioutil.Discard, "", 0) 28 29 u, err := url.Parse(virtualHostServer.URL) 30 c.Assert(err, check.IsNil) 31 hostPort := u.Host 32 serverName = strings.Split(hostPort, ":")[0] 33 34 repoName := fmt.Sprintf("%v/dockercli/image:latest", hostPort) 35 cmd := exec.Command(dockerBinary, "pull", repoName) 36 cmd.Run() 37 38 // check that the fake server was hit at least once 39 c.Assert(len(serverNameReceived) > 0, check.Equals, true) 40 // check that for each hit the right server name was received 41 for _, item := range serverNameReceived { 42 c.Check(item, check.Equals, serverName) 43 } 44 }