Search in sources :

Example 6 with ProxiedSocketAddress

use of io.grpc.ProxiedSocketAddress in project grpc-java by grpc.

the class ProxyDetectorImplTest method detectProxyForResolvedDestination.

@Test
public void detectProxyForResolvedDestination() throws Exception {
    InetSocketAddress resolved = new InetSocketAddress(InetAddress.getByName("10.1.2.3"), 10);
    assertFalse(resolved.isUnresolved());
    Proxy proxy = new Proxy(Proxy.Type.HTTP, unresolvedProxy);
    when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy));
    ProxiedSocketAddress detected = proxyDetector.proxyFor(resolved);
    assertNotNull(detected);
    HttpConnectProxiedSocketAddress expected = HttpConnectProxiedSocketAddress.newBuilder().setTargetAddress(resolved).setProxyAddress(new InetSocketAddress(InetAddress.getByName(unresolvedProxy.getHostName()), proxyPort)).build();
    assertEquals(expected, detected);
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) ProxiedSocketAddress(io.grpc.ProxiedSocketAddress) URI(java.net.URI) Test(org.junit.Test)

Example 7 with ProxiedSocketAddress

use of io.grpc.ProxiedSocketAddress in project grpc-java by grpc.

the class ProxyDetectorImplTest method authRequired.

@Test
public void authRequired() throws Exception {
    Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.HTTP, unresolvedProxy);
    final String proxyUser = "testuser";
    final String proxyPassword = "testpassword";
    PasswordAuthentication auth = new PasswordAuthentication(proxyUser, proxyPassword.toCharArray());
    when(authenticator.requestPasswordAuthentication(anyString(), ArgumentMatchers.<InetAddress>any(), anyInt(), anyString(), anyString(), AdditionalMatchers.or(anyString(), ArgumentMatchers.<String>any()))).thenReturn(auth);
    when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy));
    ProxiedSocketAddress detected = proxyDetector.proxyFor(destination);
    assertEquals(HttpConnectProxiedSocketAddress.newBuilder().setTargetAddress(destination).setProxyAddress(new InetSocketAddress(InetAddress.getByName(unresolvedProxy.getHostName()), unresolvedProxy.getPort())).setUsername(proxyUser).setPassword(proxyPassword).build(), detected);
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) ProxiedSocketAddress(io.grpc.ProxiedSocketAddress) URI(java.net.URI) PasswordAuthentication(java.net.PasswordAuthentication) Test(org.junit.Test)

Example 8 with ProxiedSocketAddress

use of io.grpc.ProxiedSocketAddress in project grpc-java by grpc.

the class ProxyDetectorImplTest method pickFirstHttpProxy.

@Test
public void pickFirstHttpProxy() throws Exception {
    InetSocketAddress otherProxy = InetSocketAddress.createUnresolved("10.0.0.2", 11111);
    assertNotEquals(unresolvedProxy, otherProxy);
    Proxy proxy1 = new java.net.Proxy(java.net.Proxy.Type.HTTP, unresolvedProxy);
    Proxy proxy2 = new java.net.Proxy(java.net.Proxy.Type.HTTP, otherProxy);
    when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy1, proxy2));
    ProxiedSocketAddress detected = proxyDetector.proxyFor(destination);
    assertNotNull(detected);
    assertEquals(proxySocketAddress, detected);
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) ProxiedSocketAddress(io.grpc.ProxiedSocketAddress) URI(java.net.URI) Test(org.junit.Test)

Aggregations

ProxiedSocketAddress (io.grpc.ProxiedSocketAddress)8 Test (org.junit.Test)7 HttpConnectProxiedSocketAddress (io.grpc.HttpConnectProxiedSocketAddress)6 InetSocketAddress (java.net.InetSocketAddress)6 URI (java.net.URI)5 Proxy (java.net.Proxy)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)1 CreateSubchannelArgs (io.grpc.LoadBalancer.CreateSubchannelArgs)1 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)1 NameResolver (io.grpc.NameResolver)1 ProxyDetector (io.grpc.ProxyDetector)1 PasswordAuthentication (java.net.PasswordAuthentication)1 SocketAddress (java.net.SocketAddress)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Nullable (javax.annotation.Nullable)1