2015-12-11 16:55:41 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-07-14 18:02:38 +00:00
|
|
|
"context"
|
2015-12-11 16:55:41 +00:00
|
|
|
"fmt"
|
2021-08-24 10:10:50 +00:00
|
|
|
"io"
|
2015-12-11 16:55:41 +00:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/url"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2019-09-09 21:06:12 +00:00
|
|
|
"testing"
|
2015-12-11 16:55:41 +00:00
|
|
|
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
2015-12-11 16:55:41 +00:00
|
|
|
)
|
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
type DockerCLISNISuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
}
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
func (s *DockerCLISNISuite) TearDownTest(ctx context.Context, c *testing.T) {
|
|
|
|
s.ds.TearDownTest(ctx, c)
|
2022-06-16 21:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLISNISuite) OnTimeout(c *testing.T) {
|
|
|
|
s.ds.OnTimeout(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLISNISuite) TestClientSetsTLSServerName(c *testing.T) {
|
2016-02-03 03:56:31 +00:00
|
|
|
c.Skip("Flakey test")
|
2015-12-11 16:55:41 +00:00
|
|
|
// there may be more than one hit to the server for each registry request
|
2018-05-19 11:38:54 +00:00
|
|
|
var serverNameReceived []string
|
2015-12-11 16:55:41 +00: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 10:10:50 +00:00
|
|
|
virtualHostServer.Config.ErrorLog = log.New(io.Discard, "", 0)
|
2015-12-11 16:55:41 +00:00
|
|
|
|
|
|
|
u, err := url.Parse(virtualHostServer.URL)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2015-12-11 16:55:41 +00: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 13:23:19 +00:00
|
|
|
assert.Assert(c, len(serverNameReceived) > 0)
|
2015-12-11 16:55:41 +00:00
|
|
|
// check that for each hit the right server name was received
|
|
|
|
for _, item := range serverNameReceived {
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Check(c, item == serverName)
|
2015-12-11 16:55:41 +00:00
|
|
|
}
|
|
|
|
}
|