Search in sources :

Example 1 with ProxiedSocketAddress

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

the class ProxyDetectorImplTest method override_hostOnly.

@Test
public void override_hostOnly() throws Exception {
    final String overrideHostWithoutPort = "10.99.99.99";
    final int defaultPort = 80;
    ProxyDetectorImpl proxyDetector = new ProxyDetectorImpl(proxySelectorSupplier, authenticator, overrideHostWithoutPort);
    ProxiedSocketAddress detected = proxyDetector.proxyFor(destination);
    assertNotNull(detected);
    assertEquals(HttpConnectProxiedSocketAddress.newBuilder().setTargetAddress(destination).setProxyAddress(new InetSocketAddress(InetAddress.getByName(overrideHostWithoutPort), defaultPort)).build(), detected);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) ProxiedSocketAddress(io.grpc.ProxiedSocketAddress) Test(org.junit.Test)

Example 2 with ProxiedSocketAddress

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

the class ProxyDetectorImplTest method override_hostPort.

@Test
public void override_hostPort() throws Exception {
    final String overrideHost = "10.99.99.99";
    final int overridePort = 1234;
    final String overrideHostWithPort = overrideHost + ":" + overridePort;
    ProxyDetectorImpl proxyDetector = new ProxyDetectorImpl(proxySelectorSupplier, authenticator, overrideHostWithPort);
    ProxiedSocketAddress detected = proxyDetector.proxyFor(destination);
    assertNotNull(detected);
    assertEquals(HttpConnectProxiedSocketAddress.newBuilder().setTargetAddress(destination).setProxyAddress(new InetSocketAddress(InetAddress.getByName(overrideHost), overridePort)).build(), detected);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HttpConnectProxiedSocketAddress(io.grpc.HttpConnectProxiedSocketAddress) ProxiedSocketAddress(io.grpc.ProxiedSocketAddress) Test(org.junit.Test)

Example 3 with ProxiedSocketAddress

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

the class ManagedChannelImplTest method nameResolverArgsPropagation.

@Test
public void nameResolverArgsPropagation() {
    final AtomicReference<NameResolver.Args> capturedArgs = new AtomicReference<>();
    final NameResolver noopResolver = new NameResolver() {

        @Override
        public String getServiceAuthority() {
            return "fake-authority";
        }

        @Override
        public void start(Listener2 listener) {
        }

        @Override
        public void shutdown() {
        }
    };
    ProxyDetector neverProxy = new ProxyDetector() {

        @Override
        public ProxiedSocketAddress proxyFor(SocketAddress targetAddress) {
            return null;
        }
    };
    NameResolver.Factory factory = new NameResolver.Factory() {

        @Override
        public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
            capturedArgs.set(args);
            return noopResolver;
        }

        @Override
        public String getDefaultScheme() {
            return "fakescheme";
        }
    };
    channelBuilder.nameResolverFactory(factory).proxyDetector(neverProxy);
    createChannel();
    NameResolver.Args args = capturedArgs.get();
    assertThat(args).isNotNull();
    assertThat(args.getDefaultPort()).isEqualTo(DEFAULT_PORT);
    assertThat(args.getProxyDetector()).isSameInstanceAs(neverProxy);
    verify(offloadExecutor, never()).execute(any(Runnable.class));
    args.getOffloadExecutor().execute(new Runnable() {

        @Override
        public void run() {
        }
    });
    verify(offloadExecutor, times(1)).execute(any(Runnable.class));
}
Also used : PickSubchannelArgs(io.grpc.LoadBalancer.PickSubchannelArgs) CreateSubchannelArgs(io.grpc.LoadBalancer.CreateSubchannelArgs) ProxyDetector(io.grpc.ProxyDetector) AtomicReference(java.util.concurrent.atomic.AtomicReference) URI(java.net.URI) ProxiedSocketAddress(io.grpc.ProxiedSocketAddress) SocketAddress(java.net.SocketAddress) NameResolver(io.grpc.NameResolver) Test(org.junit.Test)

Example 4 with ProxiedSocketAddress

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

the class DnsNameResolver method detectProxy.

@Nullable
private EquivalentAddressGroup detectProxy() throws IOException {
    InetSocketAddress destination = InetSocketAddress.createUnresolved(host, port);
    ProxiedSocketAddress proxiedAddr = proxyDetector.proxyFor(destination);
    if (proxiedAddr != null) {
        return new EquivalentAddressGroup(proxiedAddr);
    }
    return null;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) ProxiedSocketAddress(io.grpc.ProxiedSocketAddress) Nullable(javax.annotation.Nullable)

Example 5 with ProxiedSocketAddress

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

the class ProxyDetectorImplTest method detectProxyForUnresolvedDestination.

@Test
public void detectProxyForUnresolvedDestination() throws Exception {
    Proxy proxy = new Proxy(Proxy.Type.HTTP, unresolvedProxy);
    when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy));
    ProxiedSocketAddress detected = proxyDetector.proxyFor(destination);
    assertNotNull(detected);
    assertEquals(proxySocketAddress, detected);
}
Also used : Proxy(java.net.Proxy) 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