2015-02-13 00:38:52 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net"
|
|
|
|
|
"strings"
|
2015-04-19 00:46:47 +08:00
|
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2019-04-04 21:23:19 +08:00
|
|
|
"gotest.tools/assert"
|
2018-06-11 21:32:11 +08:00
|
|
|
"gotest.tools/icmd"
|
2015-02-13 00:38:52 +08:00
|
|
|
)
|
|
|
|
|
|
2019-09-10 05:05:55 +08:00
|
|
|
func (s *DockerSuite) TestCLIProxyDisableProxyUnixSock(c *testing.T) {
|
2018-12-24 20:25:53 +08:00
|
|
|
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
2015-02-13 00:38:52 +08:00
|
|
|
|
2017-01-06 02:08:24 +08:00
|
|
|
icmd.RunCmd(icmd.Cmd{
|
2017-01-05 19:38:34 +08:00
|
|
|
Command: []string{dockerBinary, "info"},
|
2017-01-06 02:08:24 +08:00
|
|
|
Env: appendBaseEnv(false, "HTTP_PROXY=http://127.0.0.1:9999"),
|
2017-01-05 19:38:34 +08:00
|
|
|
}).Assert(c, icmd.Success)
|
2015-02-13 00:38:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Can't use localhost here since go has a special case to not use proxy if connecting to localhost
|
2015-04-12 01:31:34 +08:00
|
|
|
// See https://golang.org/pkg/net/http/#ProxyFromEnvironment
|
2019-09-10 05:05:55 +08:00
|
|
|
func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *testing.T) {
|
2015-02-13 00:38:52 +08:00
|
|
|
// get the IP to use to connect since we can't use localhost
|
|
|
|
|
addrs, err := net.InterfaceAddrs()
|
2019-04-04 21:23:19 +08:00
|
|
|
assert.NilError(c, err)
|
2015-02-13 00:38:52 +08:00
|
|
|
var ip string
|
|
|
|
|
for _, addr := range addrs {
|
|
|
|
|
sAddr := addr.String()
|
|
|
|
|
if !strings.Contains(sAddr, "127.0.0.1") {
|
|
|
|
|
addrArr := strings.Split(sAddr, "/")
|
|
|
|
|
ip = addrArr[0]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-04 21:23:19 +08:00
|
|
|
assert.Assert(c, ip != "")
|
2015-10-09 14:53:56 +08:00
|
|
|
|
2016-12-10 06:20:14 +08:00
|
|
|
s.d.Start(c, "-H", "tcp://"+ip+":2375")
|
2017-01-05 19:38:34 +08:00
|
|
|
|
|
|
|
|
icmd.RunCmd(icmd.Cmd{
|
|
|
|
|
Command: []string{dockerBinary, "info"},
|
2017-01-06 02:08:24 +08:00
|
|
|
Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"},
|
|
|
|
|
}).Assert(c, icmd.Expected{Error: "exit status 1", ExitCode: 1})
|
2015-02-13 00:38:52 +08:00
|
|
|
// Test with no_proxy
|
2017-01-06 02:08:24 +08:00
|
|
|
icmd.RunCmd(icmd.Cmd{
|
2017-01-05 19:38:34 +08:00
|
|
|
Command: []string{dockerBinary, "info"},
|
2017-01-06 02:08:24 +08:00
|
|
|
Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999", "NO_PROXY=" + ip},
|
2017-01-05 19:38:34 +08:00
|
|
|
}).Assert(c, icmd.Success)
|
2015-02-13 00:38:52 +08:00
|
|
|
}
|