docker_cli_proxy_test.go 1.5 KB

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