2015-02-12 16:38:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-07-14 18:02:38 +00:00
|
|
|
"context"
|
2015-02-12 16:38:52 +00:00
|
|
|
"net"
|
|
|
|
"strings"
|
2019-09-09 21:06:12 +00:00
|
|
|
"testing"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/icmd"
|
2015-02-12 16:38:52 +00:00
|
|
|
)
|
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
type DockerCLIProxySuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
}
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
func (s *DockerCLIProxySuite) TearDownTest(ctx context.Context, c *testing.T) {
|
|
|
|
s.ds.TearDownTest(ctx, c)
|
2022-06-16 21:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLIProxySuite) OnTimeout(c *testing.T) {
|
|
|
|
s.ds.OnTimeout(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLIProxySuite) TestCLIProxyDisableProxyUnixSock(c *testing.T) {
|
2018-12-24 12:25:53 +00:00
|
|
|
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon)
|
2015-02-12 16:38:52 +00:00
|
|
|
|
2017-01-05 18:08:24 +00:00
|
|
|
icmd.RunCmd(icmd.Cmd{
|
2017-01-05 11:38:34 +00:00
|
|
|
Command: []string{dockerBinary, "info"},
|
2017-01-05 18:08:24 +00:00
|
|
|
Env: appendBaseEnv(false, "HTTP_PROXY=http://127.0.0.1:9999"),
|
2017-01-05 11:38:34 +00:00
|
|
|
}).Assert(c, icmd.Success)
|
2015-02-12 16:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Can't use localhost here since go has a special case to not use proxy if connecting to localhost
|
2015-04-11 17:31:34 +00:00
|
|
|
// See https://golang.org/pkg/net/http/#ProxyFromEnvironment
|
2019-09-09 21:05:55 +00:00
|
|
|
func (s *DockerDaemonSuite) TestCLIProxyProxyTCPSock(c *testing.T) {
|
2015-02-12 16:38:52 +00:00
|
|
|
// get the IP to use to connect since we can't use localhost
|
|
|
|
addrs, err := net.InterfaceAddrs()
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2015-02-12 16:38:52 +00: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 13:23:19 +00:00
|
|
|
assert.Assert(c, ip != "")
|
2015-10-09 06:53:56 +00:00
|
|
|
|
2016-12-09 22:20:14 +00:00
|
|
|
s.d.Start(c, "-H", "tcp://"+ip+":2375")
|
2017-01-05 11:38:34 +00:00
|
|
|
|
|
|
|
icmd.RunCmd(icmd.Cmd{
|
|
|
|
Command: []string{dockerBinary, "info"},
|
2017-01-05 18:08:24 +00: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-12 16:38:52 +00:00
|
|
|
// Test with no_proxy
|
2017-01-05 18:08:24 +00:00
|
|
|
icmd.RunCmd(icmd.Cmd{
|
2017-01-05 11:38:34 +00:00
|
|
|
Command: []string{dockerBinary, "info"},
|
2017-01-05 18:08:24 +00:00
|
|
|
Env: []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999", "NO_PROXY=" + ip},
|
2017-01-05 11:38:34 +00:00
|
|
|
}).Assert(c, icmd.Success)
|
2015-02-12 16:38:52 +00:00
|
|
|
}
|