Example #1
0
func (s *proxySuite) TestSetEnvironmentValues(c *gc.C) {
	s.PatchEnvironment("http_proxy", "initial")
	s.PatchEnvironment("HTTP_PROXY", "initial")
	s.PatchEnvironment("https_proxy", "initial")
	s.PatchEnvironment("HTTPS_PROXY", "initial")
	s.PatchEnvironment("ftp_proxy", "initial")
	s.PatchEnvironment("FTP_PROXY", "initial")
	s.PatchEnvironment("no_proxy", "initial")
	s.PatchEnvironment("NO_PROXY", "initial")

	proxy := osenv.ProxySettings{
		Http:  "http proxy",
		Https: "https proxy",
		// Ftp left blank to show clearing env.
		NoProxy: "10.0.3.1,localhost",
	}
	proxy.SetEnvironmentValues()

	obtained := osenv.DetectProxies()

	c.Assert(obtained, gc.DeepEquals, proxy)

	c.Assert(os.Getenv("http_proxy"), gc.Equals, "http proxy")
	c.Assert(os.Getenv("HTTP_PROXY"), gc.Equals, "http proxy")
	c.Assert(os.Getenv("https_proxy"), gc.Equals, "https proxy")
	c.Assert(os.Getenv("HTTPS_PROXY"), gc.Equals, "https proxy")
	c.Assert(os.Getenv("ftp_proxy"), gc.Equals, "")
	c.Assert(os.Getenv("FTP_PROXY"), gc.Equals, "")
	c.Assert(os.Getenv("no_proxy"), gc.Equals, "10.0.3.1,localhost")
	c.Assert(os.Getenv("NO_PROXY"), gc.Equals, "10.0.3.1,localhost")
}
Example #2
0
func (s *proxySuite) TestAsScriptEnvironmentOneValue(c *gc.C) {
	proxies := osenv.ProxySettings{
		Http: "some-value",
	}
	expected := `
export http_proxy=some-value
export HTTP_PROXY=some-value`[1:]
	c.Assert(proxies.AsScriptEnvironment(), gc.Equals, expected)
}
Example #3
0
func (s *proxySuite) TestAsEnvironmentValuesOneValue(c *gc.C) {
	proxies := osenv.ProxySettings{
		Http: "some-value",
	}
	expected := []string{
		"http_proxy=some-value",
		"HTTP_PROXY=some-value",
	}
	c.Assert(proxies.AsEnvironmentValues(), gc.DeepEquals, expected)
}
Example #4
0
func (*ConfigSuite) TestProxyConfigMap(c *gc.C) {
	defer makeFakeHome(c).Restore()

	cfg := newTestConfig(c, testing.Attrs{})
	proxy := osenv.ProxySettings{
		Http:    "http proxy",
		Https:   "https proxy",
		Ftp:     "ftp proxy",
		NoProxy: "no proxy",
	}
	cfg, err := cfg.Apply(config.ProxyConfigMap(proxy))
	c.Assert(err, gc.IsNil)
	c.Assert(cfg.ProxySettings(), gc.DeepEquals, proxy)
	// Apt proxy and proxy differ by the content of the no-proxy values.
	proxy.NoProxy = ""
	c.Assert(cfg.AptProxySettings(), gc.DeepEquals, proxy)
}
Example #5
0
func (s *proxySuite) TestAsScriptEnvironmentAllValue(c *gc.C) {
	proxies := osenv.ProxySettings{
		Http:    "some-value",
		Https:   "special",
		Ftp:     "who uses this?",
		NoProxy: "10.0.3.1,localhost",
	}
	expected := `
export http_proxy=some-value
export HTTP_PROXY=some-value
export https_proxy=special
export HTTPS_PROXY=special
export ftp_proxy=who uses this?
export FTP_PROXY=who uses this?
export no_proxy=10.0.3.1,localhost
export NO_PROXY=10.0.3.1,localhost`[1:]
	c.Assert(proxies.AsScriptEnvironment(), gc.Equals, expected)
}
Example #6
0
func (s *proxySuite) TestAsEnvironmentValuesAllValue(c *gc.C) {
	proxies := osenv.ProxySettings{
		Http:    "some-value",
		Https:   "special",
		Ftp:     "who uses this?",
		NoProxy: "10.0.3.1,localhost",
	}
	expected := []string{
		"http_proxy=some-value",
		"HTTP_PROXY=some-value",
		"https_proxy=special",
		"HTTPS_PROXY=special",
		"ftp_proxy=who uses this?",
		"FTP_PROXY=who uses this?",
		"no_proxy=10.0.3.1,localhost",
		"NO_PROXY=10.0.3.1,localhost",
	}
	c.Assert(proxies.AsEnvironmentValues(), gc.DeepEquals, expected)
}
Example #7
0
func (s *proxySuite) TestAsEnvironmentValuesEmpty(c *gc.C) {
	proxies := osenv.ProxySettings{}
	c.Assert(proxies.AsEnvironmentValues(), gc.HasLen, 0)
}
Example #8
0
func (s *proxySuite) TestAsScriptEnvironmentEmpty(c *gc.C) {
	proxies := osenv.ProxySettings{}
	c.Assert(proxies.AsScriptEnvironment(), gc.Equals, "")
}