2015-02-12 16:38:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2015-02-12 16:38:52 +00:00
|
|
|
)
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCliProxyDisableProxyUnixSock(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon) // test is valid when DOCKER_HOST=unix://..
|
2015-03-06 22:45:26 +00:00
|
|
|
|
2015-02-12 16:38:52 +00:00
|
|
|
cmd := exec.Command(dockerBinary, "info")
|
2015-03-07 09:03:44 +00:00
|
|
|
cmd.Env = appendBaseEnv([]string{"HTTP_PROXY=http://127.0.0.1:9999"})
|
2015-02-12 16:38:52 +00:00
|
|
|
|
|
|
|
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(err, out)
|
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
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestCliProxyProxyTCPSock(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon)
|
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()
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ip == "" {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("could not find ip to connect to")
|
2015-02-12 16:38:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
d := NewDaemon(c)
|
2015-02-12 16:38:52 +00:00
|
|
|
if err := d.Start("-H", "tcp://"+ip+":2375"); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(err)
|
2015-02-12 16:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd := exec.Command(dockerBinary, "info")
|
|
|
|
cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"}
|
|
|
|
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(err, out)
|
2015-02-12 16:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test with no_proxy
|
|
|
|
cmd.Env = append(cmd.Env, "NO_PROXY="+ip)
|
|
|
|
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "info")); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(err, out)
|
2015-02-12 16:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|