github.com/iaintshine/docker@v1.8.2/integration-cli/docker_cli_proxy_test.go (about) 1 package main 2 3 import ( 4 "net" 5 "os/exec" 6 "strings" 7 8 "github.com/go-check/check" 9 ) 10 11 func (s *DockerSuite) TestCliProxyDisableProxyUnixSock(c *check.C) { 12 testRequires(c, SameHostDaemon) // test is valid when DOCKER_HOST=unix://.. 13 14 cmd := exec.Command(dockerBinary, "info") 15 cmd.Env = appendBaseEnv([]string{"HTTP_PROXY=http://127.0.0.1:9999"}) 16 17 if out, _, err := runCommandWithOutput(cmd); err != nil { 18 c.Fatal(err, out) 19 } 20 21 } 22 23 // Can't use localhost here since go has a special case to not use proxy if connecting to localhost 24 // See https://golang.org/pkg/net/http/#ProxyFromEnvironment 25 func (s *DockerDaemonSuite) TestCliProxyProxyTCPSock(c *check.C) { 26 testRequires(c, 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 c.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 c.Fatal("could not find ip to connect to") 44 } 45 46 if err := s.d.Start("-H", "tcp://"+ip+":2375"); err != nil { 47 c.Fatal(err) 48 } 49 50 cmd := exec.Command(dockerBinary, "info") 51 cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"} 52 if out, _, err := runCommandWithOutput(cmd); err == nil { 53 c.Fatal(err, out) 54 } 55 56 // Test with no_proxy 57 cmd.Env = append(cmd.Env, "NO_PROXY="+ip) 58 if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "info")); err != nil { 59 c.Fatal(err, out) 60 } 61 62 }