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);
}
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);
}
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);
}
Aggregations