2015-12-11 11:55:41 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/url"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2019-04-04 09:23:19 -04:00
|
|
|
"gotest.tools/assert"
|
2015-12-11 11:55:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestClientSetsTLSServerName(c *check.C) {
|
2016-02-02 22:56:31 -05:00
|
|
|
c.Skip("Flakey test")
|
2015-12-11 11:55:41 -05:00
|
|
|
// there may be more than one hit to the server for each registry request
|
2018-05-19 07:38:54 -04:00
|
|
|
var serverNameReceived []string
|
2015-12-11 11:55:41 -05:00
|
|
|
var serverName string
|
|
|
|
|
|
|
|
virtualHostServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
serverNameReceived = append(serverNameReceived, r.TLS.ServerName)
|
|
|
|
}))
|
|
|
|
defer virtualHostServer.Close()
|
|
|
|
// discard TLS handshake errors written by default to os.Stderr
|
|
|
|
virtualHostServer.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
|
|
|
|
|
|
|
|
u, err := url.Parse(virtualHostServer.URL)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-12-11 11:55:41 -05:00
|
|
|
hostPort := u.Host
|
|
|
|
serverName = strings.Split(hostPort, ":")[0]
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/image:latest", hostPort)
|
|
|
|
cmd := exec.Command(dockerBinary, "pull", repoName)
|
|
|
|
cmd.Run()
|
|
|
|
|
|
|
|
// check that the fake server was hit at least once
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Assert(c, len(serverNameReceived) > 0)
|
2015-12-11 11:55:41 -05:00
|
|
|
// check that for each hit the right server name was received
|
|
|
|
for _, item := range serverNameReceived {
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Check(c, item == serverName)
|
2015-12-11 11:55:41 -05:00
|
|
|
}
|
|
|
|
}
|