docker_cli_proxy_test.go 1.6 KB

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