Search in sources :

Example 71 with Proxy

use of java.net.Proxy in project bazel by bazelbuild.

the class ProxyHelperTest method testProxyAuth.

@Test
public void testProxyAuth() throws Exception {
    Proxy proxy = ProxyHelper.createProxy("http://foo:barbaz@my.example.com");
    assertEquals(Proxy.Type.HTTP, proxy.type());
    assertThat(proxy.toString()).endsWith(":80");
    assertEquals(System.getProperty("http.proxyHost"), "my.example.com");
    assertEquals(System.getProperty("http.proxyPort"), "80");
    assertEquals(System.getProperty("http.proxyUser"), "foo");
    assertEquals(System.getProperty("http.proxyPassword"), "barbaz");
    proxy = ProxyHelper.createProxy("https://biz:bat@my.example.com");
    assertThat(proxy.toString()).endsWith(":443");
    assertEquals(System.getProperty("https.proxyHost"), "my.example.com");
    assertEquals(System.getProperty("https.proxyPort"), "443");
    assertEquals(System.getProperty("https.proxyUser"), "biz");
    assertEquals(System.getProperty("https.proxyPassword"), "bat");
}
Also used : Proxy(java.net.Proxy) Test(org.junit.Test)

Example 72 with Proxy

use of java.net.Proxy in project bazel by bazelbuild.

the class ProxyHelperTest method testProxyDefaultPort.

@Test
public void testProxyDefaultPort() throws Exception {
    Proxy proxy = ProxyHelper.createProxy("http://my.example.com");
    assertEquals(Proxy.Type.HTTP, proxy.type());
    assertThat(proxy.toString()).endsWith(":80");
    assertEquals(System.getProperty("http.proxyHost"), "my.example.com");
    assertEquals(System.getProperty("http.proxyPort"), "80");
    proxy = ProxyHelper.createProxy("https://my.example.com");
    assertThat(proxy.toString()).endsWith(":443");
    assertEquals(System.getProperty("https.proxyHost"), "my.example.com");
    assertEquals(System.getProperty("https.proxyPort"), "443");
}
Also used : Proxy(java.net.Proxy) Test(org.junit.Test)

Example 73 with Proxy

use of java.net.Proxy in project bazel by bazelbuild.

the class ProxyHelperTest method testCreateIfNeededHttpsUpperCase.

@Test
public void testCreateIfNeededHttpsUpperCase() throws Exception {
    ProxyHelper helper = new ProxyHelper(ImmutableMap.of("HTTPS_PROXY", "https://my.example.com"));
    Proxy proxy = helper.createProxyIfNeeded(new URL("https://www.something.com"));
    assertThat(proxy.toString()).endsWith("my.example.com:443");
}
Also used : Proxy(java.net.Proxy) URL(java.net.URL) Test(org.junit.Test)

Example 74 with Proxy

use of java.net.Proxy in project bazel by bazelbuild.

the class ProxyHelperTest method testCreateIfNeededHttpLowerCase.

@Test
public void testCreateIfNeededHttpLowerCase() throws Exception {
    ProxyHelper helper = new ProxyHelper(ImmutableMap.of("http_proxy", "http://my.example.com"));
    Proxy proxy = helper.createProxyIfNeeded(new URL("http://www.something.com"));
    assertThat(proxy.toString()).endsWith("my.example.com:80");
}
Also used : Proxy(java.net.Proxy) URL(java.net.URL) Test(org.junit.Test)

Example 75 with Proxy

use of java.net.Proxy in project bazel by bazelbuild.

the class ProxyHelperTest method testEncodedProxyAuth.

@Test
public void testEncodedProxyAuth() throws Exception {
    Proxy proxy = ProxyHelper.createProxy("http://foo:b%40rb%40z@my.example.com");
    assertEquals(Proxy.Type.HTTP, proxy.type());
    assertThat(proxy.toString()).endsWith(":80");
    assertEquals(System.getProperty("http.proxyHost"), "my.example.com");
    assertEquals(System.getProperty("http.proxyPort"), "80");
    assertEquals(System.getProperty("http.proxyUser"), "foo");
    assertEquals(System.getProperty("http.proxyPassword"), "b@rb@z");
}
Also used : Proxy(java.net.Proxy) Test(org.junit.Test)

Aggregations

Proxy (java.net.Proxy)132 InetSocketAddress (java.net.InetSocketAddress)71 URL (java.net.URL)44 IOException (java.io.IOException)35 Test (org.junit.Test)22 URI (java.net.URI)21 ProxySelector (java.net.ProxySelector)20 HttpURLConnection (java.net.HttpURLConnection)19 SocketAddress (java.net.SocketAddress)19 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)13 URISyntaxException (java.net.URISyntaxException)11 ServerSocket (java.net.ServerSocket)10 Socket (java.net.Socket)9 PasswordAuthentication (java.net.PasswordAuthentication)8 InterruptedIOException (java.io.InterruptedIOException)6 URLConnection (java.net.URLConnection)6 SSLServerSocket (javax.net.ssl.SSLServerSocket)6 List (java.util.List)5 SSLSocket (javax.net.ssl.SSLSocket)5 OkHttpClient (okhttp3.OkHttpClient)5