|
| 1 | +package config_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "code.cloudfoundry.org/cfdev/config" |
| 5 | + . "github.com/onsi/ginkgo" |
| 6 | + . "github.com/onsi/gomega" |
| 7 | + "os" |
| 8 | +) |
| 9 | + |
| 10 | +var _ = Describe("BuildProxyConfig", func() { |
| 11 | + var ( |
| 12 | + cfg = config.Config{ |
| 13 | + BoshDirectorIP: "bosh-ip", |
| 14 | + CFRouterIP: "router-ip", |
| 15 | + HostIP: "host-ip", |
| 16 | + } |
| 17 | + ) |
| 18 | + |
| 19 | + Context("when proxy env vars are set", func() { |
| 20 | + BeforeEach(func() { |
| 21 | + os.Setenv("HTTP_PROXY", "some-http-proxy") |
| 22 | + os.Setenv("HTTPS_PROXY", "some-https-proxy") |
| 23 | + os.Setenv("NO_PROXY", "some-no-proxy") |
| 24 | + }) |
| 25 | + |
| 26 | + AfterEach(func() { |
| 27 | + os.Unsetenv("HTTP_PROXY") |
| 28 | + os.Unsetenv("HTTPS_PROXY") |
| 29 | + os.Unsetenv("NO_PROXY") |
| 30 | + }) |
| 31 | + |
| 32 | + It("returns the http config", func() { |
| 33 | + proxyConfig := cfg.BuildProxyConfig() |
| 34 | + Expect(proxyConfig.Http).To(Equal("some-http-proxy")) |
| 35 | + Expect(proxyConfig.Https).To(Equal("some-https-proxy")) |
| 36 | + Expect(proxyConfig.NoProxy).To(Equal("some-no-proxy,bosh-ip,router-ip,host-ip")) |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + Context("when multiple mixed case proxy envs prioritize uppercase", func() { |
| 41 | + BeforeEach(func() { |
| 42 | + os.Setenv("http_proxy", "lower-case-http-proxy") |
| 43 | + os.Setenv("HTTP_PROXY", "upper-some-http-proxy") |
| 44 | + os.Setenv("https_proxy", "lower-case-https-proxy") |
| 45 | + os.Setenv("HTTPS_PROXY", "upper-some-https-proxy") |
| 46 | + os.Setenv("no_proxy", "lower-some-no-proxy") |
| 47 | + os.Setenv("NO_PROXY", "upper-some-no-proxy,bosh-ip,router-ip") |
| 48 | + }) |
| 49 | + |
| 50 | + AfterEach(func() { |
| 51 | + os.Unsetenv("http_proxy") |
| 52 | + os.Unsetenv("HTTP_PROXY") |
| 53 | + os.Unsetenv("https_proxy") |
| 54 | + os.Unsetenv("HTTPS_PROXY") |
| 55 | + os.Unsetenv("no_proxy") |
| 56 | + os.Unsetenv("NO_PROXY") |
| 57 | + }) |
| 58 | + |
| 59 | + It("returns the http config", func() { |
| 60 | + proxyConfig := cfg.BuildProxyConfig() |
| 61 | + Expect(proxyConfig.Http).To(Equal("upper-some-http-proxy")) |
| 62 | + Expect(proxyConfig.Https).To(Equal("upper-some-https-proxy")) |
| 63 | + Expect(proxyConfig.NoProxy).To(Equal("upper-some-no-proxy,bosh-ip,router-ip,host-ip")) |
| 64 | + }) |
| 65 | + }) |
| 66 | +}) |
0 commit comments