github.com/kaisenlinux/docker@v0.0.0-20230510090727-ea55db55fac7/engine/integration-cli/docker_cli_proxy_test.go (about) 1 package main 2 3 import ( 4 "net" 5 "strings" 6 "testing" 7 8 "gotest.tools/v3/assert" 9 "gotest.tools/v3/icmd" 10 ) 11 12 func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *testing.T) { 13 testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) 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 *testing.T) { 24 // get the IP to use to connect since we can't use localhost 25 addrs, err := net.InterfaceAddrs() 26 assert.NilError(c, err) 27 var ip string 28 for _, addr := range addrs { 29 sAddr := addr.String() 30 if !strings.Contains(sAddr, "127.0.0.1") { 31 addrArr := strings.Split(sAddr, "/") 32 ip = addrArr[0] 33 break 34 } 35 } 36 37 assert.Assert(c, ip != "") 38 39 s.d.Start(c, "-H", "tcp://"+ip+":2375") 40 41 icmd.RunCmd(icmd.Cmd{ 42 Command: []string{dockerBinary, "info"}, 43 Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"}, 44 }).Assert(c, icmd.Expected{Error: "exit status 1", ExitCode: 1}) 45 // Test with no_proxy 46 icmd.RunCmd(icmd.Cmd{ 47 Command: []string{dockerBinary, "info"}, 48 Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999", "NO_PROXY=" + ip}, 49 }).Assert(c, icmd.Success) 50 }