Skip to content

Commit 4ba168b

Browse files
committed
Added cli SNI integration test
Signed-off-by: Federico Gimenez <fgimenez@coit.es>
1 parent 667c224 commit 4ba168b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
// there may be more than one hit to the server for each registry request
18+
serverNameReceived := []string{}
19+
var serverName string
20+
21+
virtualHostServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
22+
serverNameReceived = append(serverNameReceived, r.TLS.ServerName)
23+
}))
24+
defer virtualHostServer.Close()
25+
// discard TLS handshake errors written by default to os.Stderr
26+
virtualHostServer.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
27+
28+
u, err := url.Parse(virtualHostServer.URL)
29+
c.Assert(err, check.IsNil)
30+
hostPort := u.Host
31+
serverName = strings.Split(hostPort, ":")[0]
32+
33+
repoName := fmt.Sprintf("%v/dockercli/image:latest", hostPort)
34+
cmd := exec.Command(dockerBinary, "pull", repoName)
35+
cmd.Run()
36+
37+
// check that the fake server was hit at least once
38+
c.Assert(len(serverNameReceived) > 0, check.Equals, true)
39+
// check that for each hit the right server name was received
40+
for _, item := range serverNameReceived {
41+
c.Check(item, check.Equals, serverName)
42+
}
43+
}

0 commit comments

Comments
 (0)