2015-12-11 11:55:41 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-08-24 06:10:50 -04:00
|
|
|
"io"
|
2015-12-11 11:55:41 -05:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/url"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
2015-12-11 11:55:41 -05:00
|
|
|
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2015-12-11 11:55:41 -05:00
|
|
|
)
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
type DockerCLISNISuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLISNISuite) TearDownTest(c *testing.T) {
|
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLISNISuite) OnTimeout(c *testing.T) {
|
|
|
|
s.ds.OnTimeout(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLISNISuite) TestClientSetsTLSServerName(c *testing.T) {
|
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
|
2021-08-24 06:10:50 -04:00
|
|
|
virtualHostServer.Config.ErrorLog = log.New(io.Discard, "", 0)
|
2015-12-11 11:55:41 -05:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|