diff options
author | 2018-02-01 09:23:13 -0800 | |
---|---|---|
committer | 2018-02-01 09:25:16 -0800 | |
commit | 34af6459d873dc066c5d90d9f8755a24eeec1827 (patch) | |
tree | 6544482e2c7e71a2ec5acc30cd1195e8e92112db /src/test/java | |
parent | a7831cc0aa606a312bd4f6f8a7e3a4c83f6dcbd4 (diff) |
Add NO_PROXY environment variable support to downloader
Check the no_proxy and NO_PROXY environment variables for a list of URLs that
should not use a proxy. If the requested URL matches the no_proxy list, don't
proxy the download.
Fixes #4299
Closes #4307.
PiperOrigin-RevId: 184149118
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java index 5aa7d107cf..49e38a3d1e 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java @@ -61,6 +61,97 @@ public class ProxyHelperTest { } @Test + public void testCreateIfNeededNoProxyLowerCase() throws Exception { + ProxyHelper helper = + new ProxyHelper( + ImmutableMap.of( + "no_proxy", + "something.com,example.com,localhost", + "HTTPS_PROXY", + "https://my.example.com")); + Proxy proxy = helper.createProxyIfNeeded(new URL("https://www.example.com")); + assertThat(proxy).isEqualTo(Proxy.NO_PROXY); + } + + @Test + public void testCreateIfNeededNoProxyUpperCase() throws Exception { + ProxyHelper helper = + new ProxyHelper( + ImmutableMap.of( + "NO_PROXY", + "something.com,example.com,localhost", + "HTTPS_PROXY", + "https://my.example.com")); + Proxy proxy = helper.createProxyIfNeeded(new URL("https://www.example.com")); + assertThat(proxy).isEqualTo(Proxy.NO_PROXY); + } + + @Test + public void testCreateIfNeededMultipleNoProxyLowerCase() throws Exception { + ProxyHelper helper = + new ProxyHelper( + ImmutableMap.of( + "no_proxy", + "something.com,example.com,localhost", + "HTTPS_PROXY", + "https://my.example.com")); + Proxy proxy = helper.createProxyIfNeeded(new URL("https://www.example.com")); + assertThat(proxy).isEqualTo(Proxy.NO_PROXY); + } + + @Test + public void testCreateIfNeededMultipleNoProxyUpperCase() throws Exception { + ProxyHelper helper = + new ProxyHelper( + ImmutableMap.of( + "NO_PROXY", + "something.com,example.com,localhost", + "HTTPS_PROXY", + "https://my.example.com")); + Proxy proxy = helper.createProxyIfNeeded(new URL("https://www.example.com")); + assertThat(proxy).isEqualTo(Proxy.NO_PROXY); + } + + @Test + public void testCreateIfNeededNoProxyNoMatchSubstring() throws Exception { + ProxyHelper helper = + new ProxyHelper( + ImmutableMap.of( + "NO_PROXY", + "something.com,example.com,localhost", + "HTTPS_PROXY", + "https://my.example.com")); + Proxy proxy = helper.createProxyIfNeeded(new URL("https://www.not-example.com")); + assertThat(proxy.toString()).endsWith("my.example.com:443"); + } + + @Test + public void testCreateIfNeededNoProxyMatchSubdomainInNoProxy() throws Exception { + ProxyHelper helper = + new ProxyHelper( + ImmutableMap.of( + "NO_PROXY", + ".something.com,example.com,localhost", + "HTTPS_PROXY", + "https://my.example.com")); + Proxy proxy = helper.createProxyIfNeeded(new URL("https://www.my.something.com")); + assertThat(proxy).isEqualTo(Proxy.NO_PROXY); + } + + @Test + public void testCreateIfNeededNoProxyMatchSubdomainInURL() throws Exception { + ProxyHelper helper = + new ProxyHelper( + ImmutableMap.of( + "NO_PROXY", + "something.com,example.com,localhost", + "HTTPS_PROXY", + "https://my.example.com")); + Proxy proxy = helper.createProxyIfNeeded(new URL("https://www.my.subdomain.something.com")); + assertThat(proxy).isEqualTo(Proxy.NO_PROXY); + } + + @Test public void testNoProxy() throws Exception { // Empty address. Proxy proxy = ProxyHelper.createProxy(null); |