github.com/stevegt/moby@v1.13.1/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/docker/docker/pkg/integration/checker" 9 "github.com/go-check/check" 10 ) 11 12 func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *check.C) { 13 testRequires(c, DaemonIsLinux) 14 testRequires(c, SameHostDaemon) // test is valid when DOCKER_HOST=unix://.. 15 16 cmd := exec.Command(dockerBinary, "info") 17 cmd.Env = appendBaseEnv(false, "HTTP_PROXY=http://127.0.0.1:9999") 18 19 out, _, err := runCommandWithOutput(cmd) 20 c.Assert(err, checker.IsNil, check.Commentf("%v", out)) 21 22 } 23 24 // Can't use localhost here since go has a special case to not use proxy if connecting to localhost 25 // See https://golang.org/pkg/net/http/#ProxyFromEnvironment 26 func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *check.C) { 27 testRequires(c, SameHostDaemon) 28 // get the IP to use to connect since we can't use localhost 29 addrs, err := net.InterfaceAddrs() 30 c.Assert(err, checker.IsNil) 31 var ip string 32 for _, addr := range addrs { 33 sAddr := addr.String() 34 if !strings.Contains(sAddr, "127.0.0.1") { 35 addrArr := strings.Split(sAddr, "/") 36 ip = addrArr[0] 37 break 38 } 39 } 40 41 c.Assert(ip, checker.Not(checker.Equals), "") 42 43 err = s.d.Start("-H", "tcp://"+ip+":2375") 44 c.Assert(err, checker.IsNil) 45 cmd := exec.Command(dockerBinary, "info") 46 cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"} 47 out, _, err := runCommandWithOutput(cmd) 48 c.Assert(err, checker.NotNil, check.Commentf("%v", out)) 49 // Test with no_proxy 50 cmd.Env = append(cmd.Env, "NO_PROXY="+ip) 51 out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "info")) 52 c.Assert(err, checker.IsNil, check.Commentf("%v", out)) 53 }