github.com/erriapo/docker@v1.6.0-rc2/integration-cli/docker_cli_proxy_test.go (about) 1 package main 2 3 import ( 4 "net" 5 "os/exec" 6 "strings" 7 "testing" 8 ) 9 10 func TestCliProxyDisableProxyUnixSock(t *testing.T) { 11 testRequires(t, SameHostDaemon) // test is valid when DOCKER_HOST=unix://.. 12 13 cmd := exec.Command(dockerBinary, "info") 14 cmd.Env = appendBaseEnv([]string{"HTTP_PROXY=http://127.0.0.1:9999"}) 15 16 if out, _, err := runCommandWithOutput(cmd); err != nil { 17 t.Fatal(err, out) 18 } 19 20 logDone("cli proxy - HTTP_PROXY is not used when connecting to unix sock") 21 } 22 23 // Can't use localhost here since go has a special case to not use proxy if connecting to localhost 24 // See http://golang.org/pkg/net/http/#ProxyFromEnvironment 25 func TestCliProxyProxyTCPSock(t *testing.T) { 26 testRequires(t, SameHostDaemon) 27 // get the IP to use to connect since we can't use localhost 28 addrs, err := net.InterfaceAddrs() 29 if err != nil { 30 t.Fatal(err) 31 } 32 var ip string 33 for _, addr := range addrs { 34 sAddr := addr.String() 35 if !strings.Contains(sAddr, "127.0.0.1") { 36 addrArr := strings.Split(sAddr, "/") 37 ip = addrArr[0] 38 break 39 } 40 } 41 42 if ip == "" { 43 t.Fatal("could not find ip to connect to") 44 } 45 46 d := NewDaemon(t) 47 if err := d.Start("-H", "tcp://"+ip+":2375"); err != nil { 48 t.Fatal(err) 49 } 50 51 cmd := exec.Command(dockerBinary, "info") 52 cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"} 53 if out, _, err := runCommandWithOutput(cmd); err == nil { 54 t.Fatal(err, out) 55 } 56 57 // Test with no_proxy 58 cmd.Env = append(cmd.Env, "NO_PROXY="+ip) 59 if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "info")); err != nil { 60 t.Fatal(err, out) 61 } 62 63 logDone("cli proxy - HTTP_PROXY is used for TCP sock") 64 }