github.com/docker/Engine@v17.12.1-ce-rc2+incompatible/integration-cli/docker_cli_proxy_test.go (about) 1 package main 2 3 import ( 4 "net" 5 "strings" 6 7 "github.com/docker/docker/integration-cli/checker" 8 "github.com/go-check/check" 9 "github.com/gotestyourself/gotestyourself/icmd" 10 ) 11 12 func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *check.C) { 13 testRequires(c, DaemonIsLinux, SameHostDaemon) 14 15 icmd.RunCmd(icmd.Cmd{ 16 Command: []string{dockerBinary, "info"}, 17 Env: appendBaseEnv(false, "HTTP_PROXY=http://127.0.0.1:9999"), 18 }).Assert(c, icmd.Success) 19 } 20 21 // Can't use localhost here since go has a special case to not use proxy if connecting to localhost 22 // See https://golang.org/pkg/net/http/#ProxyFromEnvironment 23 func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *check.C) { 24 testRequires(c, SameHostDaemon) 25 // get the IP to use to connect since we can't use localhost 26 addrs, err := net.InterfaceAddrs() 27 c.Assert(err, checker.IsNil) 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 c.Assert(ip, checker.Not(checker.Equals), "") 39 40 s.d.Start(c, "-H", "tcp://"+ip+":2375") 41 42 icmd.RunCmd(icmd.Cmd{ 43 Command: []string{dockerBinary, "info"}, 44 Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"}, 45 }).Assert(c, icmd.Expected{Error: "exit status 1", ExitCode: 1}) 46 // Test with no_proxy 47 icmd.RunCmd(icmd.Cmd{ 48 Command: []string{dockerBinary, "info"}, 49 Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999", "NO_PROXY=" + ip}, 50 }).Assert(c, icmd.Success) 51 }