docker_cli_proxy_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "net"
  4. "strings"
  5. "testing"
  6. "gotest.tools/v3/assert"
  7. "gotest.tools/v3/icmd"
  8. )
  9. func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *testing.T) {
  10. testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
  11. icmd.RunCmd(icmd.Cmd{
  12. Command: []string{dockerBinary, "info"},
  13. Env: appendBaseEnv(false, "HTTP_PROXY=http://127.0.0.1:9999"),
  14. }).Assert(c, icmd.Success)
  15. }
  16. // Can't use localhost here since go has a special case to not use proxy if connecting to localhost
  17. // See https://golang.org/pkg/net/http/#ProxyFromEnvironment
  18. func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *testing.T) {
  19. // get the IP to use to connect since we can't use localhost
  20. addrs, err := net.InterfaceAddrs()
  21. assert.NilError(c, err)
  22. var ip string
  23. for _, addr := range addrs {
  24. sAddr := addr.String()
  25. if !strings.Contains(sAddr, "127.0.0.1") {
  26. addrArr := strings.Split(sAddr, "/")
  27. ip = addrArr[0]
  28. break
  29. }
  30. }
  31. assert.Assert(c, ip != "")
  32. s.d.Start(c, "-H", "tcp://"+ip+":2375")
  33. icmd.RunCmd(icmd.Cmd{
  34. Command: []string{dockerBinary, "info"},
  35. Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"},
  36. }).Assert(c, icmd.Expected{Error: "exit status 1", ExitCode: 1})
  37. // Test with no_proxy
  38. icmd.RunCmd(icmd.Cmd{
  39. Command: []string{dockerBinary, "info"},
  40. Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999", "NO_PROXY=" + ip},
  41. }).Assert(c, icmd.Success)
  42. }