Makes sure the CLI does not use HTTP_PROXY when connecting to unix
socket.
Also adds some tests to make sure this functionality works as expected.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
| ... | ... |
@@ -155,7 +155,6 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, keyFile string, proto, a |
| 155 | 155 |
|
| 156 | 156 |
// The transport is created here for reuse during the client session |
| 157 | 157 |
tr := &http.Transport{
|
| 158 |
- Proxy: http.ProxyFromEnvironment, |
|
| 159 | 158 |
TLSClientConfig: tlsConfig, |
| 160 | 159 |
} |
| 161 | 160 |
|
| ... | ... |
@@ -168,6 +167,7 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, keyFile string, proto, a |
| 168 | 168 |
return net.DialTimeout(proto, addr, timeout) |
| 169 | 169 |
} |
| 170 | 170 |
} else {
|
| 171 |
+ tr.Proxy = http.ProxyFromEnvironment |
|
| 171 | 172 |
tr.Dial = (&net.Dialer{Timeout: timeout}).Dial
|
| 172 | 173 |
} |
| 173 | 174 |
|
| 174 | 175 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,61 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "net" |
|
| 4 |
+ "os/exec" |
|
| 5 |
+ "strings" |
|
| 6 |
+ "testing" |
|
| 7 |
+) |
|
| 8 |
+ |
|
| 9 |
+func TestCliProxyDisableProxyUnixSock(t *testing.T) {
|
|
| 10 |
+ cmd := exec.Command(dockerBinary, "info") |
|
| 11 |
+ cmd.Env = []string{"HTTP_PROXY=http://127.0.0.1:9999"}
|
|
| 12 |
+ |
|
| 13 |
+ if out, _, err := runCommandWithOutput(cmd); err != nil {
|
|
| 14 |
+ t.Fatal(err, out) |
|
| 15 |
+ } |
|
| 16 |
+ |
|
| 17 |
+ logDone("cli proxy - HTTP_PROXY is not used when connecting to unix sock")
|
|
| 18 |
+} |
|
| 19 |
+ |
|
| 20 |
+// Can't use localhost here since go has a special case to not use proxy if connecting to localhost |
|
| 21 |
+// See http://golang.org/pkg/net/http/#ProxyFromEnvironment |
|
| 22 |
+func TestCliProxyProxyTCPSock(t *testing.T) {
|
|
| 23 |
+ // get the IP to use to connect since we can't use localhost |
|
| 24 |
+ addrs, err := net.InterfaceAddrs() |
|
| 25 |
+ if err != nil {
|
|
| 26 |
+ t.Fatal(err) |
|
| 27 |
+ } |
|
| 28 |
+ var ip string |
|
| 29 |
+ for _, addr := range addrs {
|
|
| 30 |
+ sAddr := addr.String() |
|
| 31 |
+ if !strings.Contains(sAddr, "127.0.0.1") {
|
|
| 32 |
+ addrArr := strings.Split(sAddr, "/") |
|
| 33 |
+ ip = addrArr[0] |
|
| 34 |
+ break |
|
| 35 |
+ } |
|
| 36 |
+ } |
|
| 37 |
+ |
|
| 38 |
+ if ip == "" {
|
|
| 39 |
+ t.Fatal("could not find ip to connect to")
|
|
| 40 |
+ } |
|
| 41 |
+ |
|
| 42 |
+ d := NewDaemon(t) |
|
| 43 |
+ if err := d.Start("-H", "tcp://"+ip+":2375"); err != nil {
|
|
| 44 |
+ t.Fatal(err) |
|
| 45 |
+ } |
|
| 46 |
+ |
|
| 47 |
+ cmd := exec.Command(dockerBinary, "info") |
|
| 48 |
+ cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"}
|
|
| 49 |
+ if out, _, err := runCommandWithOutput(cmd); err == nil {
|
|
| 50 |
+ t.Fatal(err, out) |
|
| 51 |
+ } |
|
| 52 |
+ |
|
| 53 |
+ // Test with no_proxy |
|
| 54 |
+ cmd.Env = append(cmd.Env, "NO_PROXY="+ip) |
|
| 55 |
+ if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "info")); err != nil {
|
|
| 56 |
+ t.Fatal(err, out) |
|
| 57 |
+ } |
|
| 58 |
+ |
|
| 59 |
+ logDone("cli proxy - HTTP_PROXY is used for TCP sock")
|
|
| 60 |
+} |