aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelper.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelperTest.java28
2 files changed, 24 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelper.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelper.java
index 19e072dfbe..fd0936989c 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/ProxyHelper.java
@@ -15,7 +15,6 @@
package com.google.devtools.build.lib.bazel.repository.downloader;
import com.google.common.base.Strings;
-
import java.io.IOException;
import java.net.Authenticator;
import java.net.InetSocketAddress;
@@ -75,7 +74,7 @@ public class ProxyHelper {
// Here there be dragons.
Pattern urlPattern =
- Pattern.compile("^(https?)://(([^:@]+?)(?::([^@]+?))?@)?([^:]+)(?::(\\d+))?$");
+ Pattern.compile("^(https?)://(([^:@]+?)(?::([^@]+?))?@)?([^:]+)(?::(\\d+))?/?$");
Matcher matcher = urlPattern.matcher(proxyAddress);
if (!matcher.matches()) {
throw new IOException("Proxy address " + proxyAddress + " is not a valid URL");
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 bec3dd01dd..2a725c195a 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
@@ -19,14 +19,12 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableMap;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.io.IOException;
import java.net.Proxy;
import java.util.Map;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests for @{link ProxyHelper}.
@@ -174,4 +172,24 @@ public class ProxyHelperTest {
assertThat(e.getMessage()).contains("No password given for proxy");
}
}
+
+ @Test
+ public void testNoProxyAuth() throws Exception {
+ Proxy proxy = ProxyHelper.createProxy("http://127.0.0.1:3128/");
+ assertEquals(Proxy.Type.HTTP, proxy.type());
+ assertThat(proxy.toString()).endsWith(":3128");
+ assertEquals(System.getProperty("http.proxyHost"), "127.0.0.1");
+ assertEquals(System.getProperty("http.proxyPort"), "3128");
+ }
+
+ @Test
+ public void testTrailingSlash() throws Exception {
+ Proxy proxy = ProxyHelper.createProxy("http://foo:bar@example.com:8000/");
+ assertEquals(Proxy.Type.HTTP, proxy.type());
+ assertThat(proxy.toString()).endsWith(":8000");
+ assertEquals(System.getProperty("http.proxyHost"), "example.com");
+ assertEquals(System.getProperty("http.proxyPort"), "8000");
+ assertEquals(System.getProperty("http.proxyUser"), "foo");
+ assertEquals(System.getProperty("http.proxyPassword"), "bar");
+ }
}