github.com/adityamillind98/moby@v23.0.0-rc.4+incompatible/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  type DockerCLIProxySuite struct {
    13  	ds *DockerSuite
    14  }
    15  
    16  func (s *DockerCLIProxySuite) TearDownTest(c *testing.T) {
    17  	s.ds.TearDownTest(c)
    18  }
    19  
    20  func (s *DockerCLIProxySuite) OnTimeout(c *testing.T) {
    21  	s.ds.OnTimeout(c)
    22  }
    23  
    24  func (s *DockerCLIProxySuite) TestCLIProxyDisableProxyUnixSock(c *testing.T) {
    25  	testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
    26  
    27  	icmd.RunCmd(icmd.Cmd{
    28  		Command: []string{dockerBinary, "info"},
    29  		Env:     appendBaseEnv(false, "HTTP_PROXY=http://127.0.0.1:9999"),
    30  	}).Assert(c, icmd.Success)
    31  }
    32  
    33  // Can't use localhost here since go has a special case to not use proxy if connecting to localhost
    34  // See https://golang.org/pkg/net/http/#ProxyFromEnvironment
    35  func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *testing.T) {
    36  	// get the IP to use to connect since we can't use localhost
    37  	addrs, err := net.InterfaceAddrs()
    38  	assert.NilError(c, err)
    39  	var ip string
    40  	for _, addr := range addrs {
    41  		sAddr := addr.String()
    42  		if !strings.Contains(sAddr, "127.0.0.1") {
    43  			addrArr := strings.Split(sAddr, "/")
    44  			ip = addrArr[0]
    45  			break
    46  		}
    47  	}
    48  
    49  	assert.Assert(c, ip != "")
    50  
    51  	s.d.Start(c, "-H", "tcp://"+ip+":2375")
    52  
    53  	icmd.RunCmd(icmd.Cmd{
    54  		Command: []string{dockerBinary, "info"},
    55  		Env:     []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"},
    56  	}).Assert(c, icmd.Expected{Error: "exit status 1", ExitCode: 1})
    57  	// Test with no_proxy
    58  	icmd.RunCmd(icmd.Cmd{
    59  		Command: []string{dockerBinary, "info"},
    60  		Env:     []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999", "NO_PROXY=" + ip},
    61  	}).Assert(c, icmd.Success)
    62  }