docker_cli_proxy_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "net"
  4. "strings"
  5. "github.com/docker/docker/integration-cli/checker"
  6. "github.com/go-check/check"
  7. "gotest.tools/icmd"
  8. )
  9. func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *check.C) {
  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 *check.C) {
  19. testRequires(c, testEnv.IsLocalDaemon)
  20. // get the IP to use to connect since we can't use localhost
  21. addrs, err := net.InterfaceAddrs()
  22. c.Assert(err, checker.IsNil)
  23. var ip string
  24. for _, addr := range addrs {
  25. sAddr := addr.String()
  26. if !strings.Contains(sAddr, "127.0.0.1") {
  27. addrArr := strings.Split(sAddr, "/")
  28. ip = addrArr[0]
  29. break
  30. }
  31. }
  32. c.Assert(ip, checker.Not(checker.Equals), "")
  33. s.d.Start(c, "-H", "tcp://"+ip+":2375")
  34. icmd.RunCmd(icmd.Cmd{
  35. Command: []string{dockerBinary, "info"},
  36. Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"},
  37. }).Assert(c, icmd.Expected{Error: "exit status 1", ExitCode: 1})
  38. // Test with no_proxy
  39. icmd.RunCmd(icmd.Cmd{
  40. Command: []string{dockerBinary, "info"},
  41. Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999", "NO_PROXY=" + ip},
  42. }).Assert(c, icmd.Success)
  43. }