diff options
author | 2016-01-08 18:44:20 +0000 | |
---|---|---|
committer | 2016-01-11 09:42:01 +0000 | |
commit | 92beaeeace4c32b9cda19b39581ec823202fcf1f (patch) | |
tree | efc587deb69aacee66a967f536a57dfec6e130dc /src/test/java/com/google/devtools | |
parent | 90a8d6c04f35a5f2ea1417bc9cf7517c400ecfc8 (diff) |
Add auth support for proxy downloads
Should fix #587.
RELNOTES: Support for downloading remote resources through proxies by setting HTTP_PROXY (or HTTPS_PROXY).
--
Change-Id: I4ae18c4f1a9e911e538efd446323e279e9776eec
Reviewed-on: https://github.com/bazelbuild/bazel/pull/759
MOS_MIGRATED_REVID=111708438
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/bazel/repository/HttpDownloaderTest.java | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/HttpDownloaderTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/HttpDownloaderTest.java index 93afe43516..c30ec580ab 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/HttpDownloaderTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/HttpDownloaderTest.java @@ -64,7 +64,7 @@ public class HttpDownloaderTest { HttpDownloader.createProxy("my.example.com"); fail("Expected protocol error"); } catch (IOException e) { - assertThat(e.getMessage()).contains("No proxy protocol found"); + assertThat(e.getMessage()).contains("Proxy address my.example.com is not a valid URL"); } } @@ -74,7 +74,7 @@ public class HttpDownloaderTest { HttpDownloader.createProxy("my.example.com:12345"); fail("Expected protocol error"); } catch (IOException e) { - assertThat(e.getMessage()).contains("Invalid proxy protocol"); + assertThat(e.getMessage()).contains("Proxy address my.example.com:12345 is not a valid URL"); } } @@ -84,7 +84,32 @@ public class HttpDownloaderTest { HttpDownloader.createProxy("http://my.example.com:foo"); fail("Should have thrown an error for invalid port"); } catch (IOException e) { - assertThat(e.getMessage()).contains("Error parsing proxy port"); + assertThat(e.getMessage()) + .contains("Proxy address http://my.example.com:foo is not a valid URL"); + } + } + + @Test + public void testProxyAuth() throws Exception { + Proxy proxy = HttpDownloader.createProxy("http://foo:barbaz@my.example.com"); + assertEquals(Proxy.Type.HTTP, proxy.type()); + assertThat(proxy.toString()).endsWith(":80"); + assertEquals(System.getProperty("http.proxyUser"), "foo"); + assertEquals(System.getProperty("http.proxyPassword"), "barbaz"); + + proxy = HttpDownloader.createProxy("https://biz:bat@my.example.com"); + assertThat(proxy.toString()).endsWith(":443"); + assertEquals(System.getProperty("https.proxyUser"), "biz"); + assertEquals(System.getProperty("https.proxyPassword"), "bat"); + } + + @Test + public void testInvalidAuth() throws Exception { + try { + HttpDownloader.createProxy("http://foo@my.example.com"); + fail("Should have thrown an error for invalid auth"); + } catch (IOException e) { + assertThat(e.getMessage()).contains("No password given for proxy"); } } |