Search in sources :

Example 1 with HAProxy

use of io.vertx.test.proxy.HAProxy in project vert.x by eclipse.

the class WebSocketTest method testHAProxy.

@Test
public void testHAProxy() throws Exception {
    waitFor(2);
    SocketAddress remote = SocketAddress.inetSocketAddress(56324, "192.168.0.1");
    SocketAddress local = SocketAddress.inetSocketAddress(443, "192.168.0.11");
    Buffer header = HAProxy.createVersion1TCP4ProtocolHeader(remote, local);
    HAProxy proxy = new HAProxy(DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT, header);
    proxy.start(vertx);
    server = vertx.createHttpServer(new HttpServerOptions().setUseProxyProtocol(true)).webSocketHandler(ws -> {
        assertEquals(remote, ws.remoteAddress());
        assertEquals(local, ws.localAddress());
        ws.handler(buff -> {
            complete();
        });
    }).listen(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(v1 -> {
        client = vertx.createHttpClient();
        client.webSocket(proxy.getPort(), proxy.getHost(), "/someuri", onSuccess(ws -> {
            ws.write(Buffer.buffer("foo"), onSuccess(v -> {
                complete();
            }));
        }));
    }));
    try {
        await();
    } finally {
        proxy.stop();
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) WebSocketInternal(io.vertx.core.http.impl.WebSocketInternal) MultiMap(io.vertx.core.MultiMap) Context(io.vertx.core.Context) Matcher(java.util.regex.Matcher) PlatformDependent(io.netty.util.internal.PlatformDependent) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DEFAULT_HTTP_HOST(io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST) ReadStream(io.vertx.core.streams.ReadStream) HAProxy(io.vertx.test.proxy.HAProxy) WebSocketFrameImpl(io.vertx.core.http.impl.ws.WebSocketFrameImpl) CheckingSender(io.vertx.test.core.CheckingSender) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VertxOptions(io.vertx.core.VertxOptions) Trust(io.vertx.test.tls.Trust) BlockingQueue(java.util.concurrent.BlockingQueue) Future(io.vertx.core.Future) StandardCharsets(java.nio.charset.StandardCharsets) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Certificate(java.security.cert.Certificate) Buffer(io.vertx.core.buffer.Buffer) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) AbstractVerticle(io.vertx.core.AbstractVerticle) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Cert(io.vertx.test.tls.Cert) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NetSocketInternal(io.vertx.core.net.impl.NetSocketInternal) NetSocket(io.vertx.core.net.NetSocket) java.util(java.util) MessageDigest(java.security.MessageDigest) DEFAULT_HTTP_PORT(io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_PORT) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) DEFAULT_HTTPS_HOST(io.vertx.core.http.HttpTestBase.DEFAULT_HTTPS_HOST) BiConsumer(java.util.function.BiConsumer) CloseWebSocketFrame(io.netty.handler.codec.http.websocketx.CloseWebSocketFrame) WebSocket13FrameDecoder(io.netty.handler.codec.http.websocketx.WebSocket13FrameDecoder) AsyncResult(io.vertx.core.AsyncResult) SocketAddress(io.vertx.core.net.SocketAddress) DEFAULT_TEST_URI(io.vertx.core.http.HttpTestBase.DEFAULT_TEST_URI) ConcurrentHashSet(io.vertx.core.impl.ConcurrentHashSet) Promise(io.vertx.core.Promise) TestUtils.randomAlphaString(io.vertx.test.core.TestUtils.randomAlphaString) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) IOException(java.io.IOException) Http1xServerConnection(io.vertx.core.http.impl.Http1xServerConnection) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) WebSocket13FrameEncoder(io.netty.handler.codec.http.websocketx.WebSocket13FrameEncoder) DeploymentOptions(io.vertx.core.DeploymentOptions) NetServer(io.vertx.core.net.NetServer) DEFAULT_HTTPS_PORT(io.vertx.core.http.HttpTestBase.DEFAULT_HTTPS_PORT) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Handler(io.vertx.core.Handler) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) Http1xClientConnection(io.vertx.core.http.impl.Http1xClientConnection) SocketAddress(io.vertx.core.net.SocketAddress) HAProxy(io.vertx.test.proxy.HAProxy) Test(org.junit.Test)

Example 2 with HAProxy

use of io.vertx.test.proxy.HAProxy in project vert.x by eclipse.

the class HttpTest method testHAProxyProtocolIdleTimeoutNotHappened.

@Test
public void testHAProxyProtocolIdleTimeoutNotHappened() throws Exception {
    waitFor(2);
    SocketAddress remote = SocketAddress.inetSocketAddress(56324, "192.168.0.1");
    SocketAddress local = SocketAddress.inetSocketAddress(443, "192.168.0.11");
    Buffer header = HAProxy.createVersion1TCP4ProtocolHeader(remote, local);
    HAProxy proxy = new HAProxy(testAddress, header);
    proxy.start(vertx);
    server.close();
    server = vertx.createHttpServer(createBaseServerOptions().setProxyProtocolTimeout(100).setProxyProtocolTimeoutUnit(TimeUnit.MILLISECONDS).setUseProxyProtocol(true));
    server.requestHandler(req -> {
        req.response().end();
        complete();
    });
    startServer(testAddress);
    client.request(HttpMethod.GET, proxy.getPort(), proxy.getHost(), DEFAULT_TEST_URI).compose(HttpClientRequest::send).onComplete(onSuccess(v -> complete()));
    try {
        await();
    } finally {
        proxy.stop();
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) HAProxyMessageCompletionHandler(io.vertx.core.net.impl.HAProxyMessageCompletionHandler) IntStream(java.util.stream.IntStream) java.util(java.util) DecompressionException(io.netty.handler.codec.compression.DecompressionException) io.vertx.core(io.vertx.core) SimpleDateFormat(java.text.SimpleDateFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) Utils(io.vertx.core.impl.Utils) Collections.singletonList(java.util.Collections.singletonList) ServerSocket(java.net.ServerSocket) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) ReadStream(io.vertx.core.streams.ReadStream) HAProxy(io.vertx.test.proxy.HAProxy) Pump(io.vertx.core.streams.Pump) Assume(org.junit.Assume) DetectFileDescriptorLeaks(io.vertx.test.core.DetectFileDescriptorLeaks) DateFormat(java.text.DateFormat) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) java.util.concurrent(java.util.concurrent) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Future(io.vertx.core.Future) io.vertx.core.net(io.vertx.core.net) Nullable(io.vertx.codegen.annotations.Nullable) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) AtomicLong(java.util.concurrent.atomic.AtomicLong) Repeat(io.vertx.test.core.Repeat) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) java.io(java.io) PUT(io.vertx.core.http.HttpMethod.PUT) java.util.function(java.util.function) FakeStream(io.vertx.test.fakestream.FakeStream) TemporaryFolder(org.junit.rules.TemporaryFolder) ServerCookie(io.vertx.core.http.impl.ServerCookie) HAProxy(io.vertx.test.proxy.HAProxy) Test(org.junit.Test)

Example 3 with HAProxy

use of io.vertx.test.proxy.HAProxy in project vert.x by eclipse.

the class HttpTest method testHAProxyProtocolIllegal.

private void testHAProxyProtocolIllegal(Buffer header) throws Exception {
    waitFor(2);
    HAProxy proxy = new HAProxy(testAddress, header);
    proxy.start(vertx);
    server.close();
    server = vertx.createHttpServer(createBaseServerOptions().setUseProxyProtocol(true)).exceptionHandler(ex -> {
        if (ex instanceof io.netty.handler.codec.haproxy.HAProxyProtocolException)
            complete();
    }).requestHandler(req -> fail());
    startServer(testAddress);
    client.request(new RequestOptions().setPort(proxy.getPort()).setHost(proxy.getHost()).setURI(DEFAULT_TEST_URI)).compose(HttpClientRequest::send).onComplete(onFailure(ex -> complete()));
    await();
    proxy.stop();
}
Also used : HAProxyMessageCompletionHandler(io.vertx.core.net.impl.HAProxyMessageCompletionHandler) IntStream(java.util.stream.IntStream) java.util(java.util) DecompressionException(io.netty.handler.codec.compression.DecompressionException) io.vertx.core(io.vertx.core) SimpleDateFormat(java.text.SimpleDateFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) Utils(io.vertx.core.impl.Utils) Collections.singletonList(java.util.Collections.singletonList) ServerSocket(java.net.ServerSocket) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) ReadStream(io.vertx.core.streams.ReadStream) HAProxy(io.vertx.test.proxy.HAProxy) Pump(io.vertx.core.streams.Pump) Assume(org.junit.Assume) DetectFileDescriptorLeaks(io.vertx.test.core.DetectFileDescriptorLeaks) DateFormat(java.text.DateFormat) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) java.util.concurrent(java.util.concurrent) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Future(io.vertx.core.Future) io.vertx.core.net(io.vertx.core.net) Nullable(io.vertx.codegen.annotations.Nullable) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) AtomicLong(java.util.concurrent.atomic.AtomicLong) Repeat(io.vertx.test.core.Repeat) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) java.io(java.io) PUT(io.vertx.core.http.HttpMethod.PUT) java.util.function(java.util.function) FakeStream(io.vertx.test.fakestream.FakeStream) TemporaryFolder(org.junit.rules.TemporaryFolder) ServerCookie(io.vertx.core.http.impl.ServerCookie) HAProxy(io.vertx.test.proxy.HAProxy)

Example 4 with HAProxy

use of io.vertx.test.proxy.HAProxy in project vert.x by eclipse.

the class HttpTest method testHAProxyProtocolRejected.

private void testHAProxyProtocolRejected(Buffer header) throws Exception {
    waitFor(2);
    HAProxy proxy = new HAProxy(testAddress, header);
    proxy.start(vertx);
    server.close();
    server = vertx.createHttpServer(createBaseServerOptions().setUseProxyProtocol(true)).exceptionHandler(ex -> {
        if (ex.equals(HAProxyMessageCompletionHandler.UNSUPPORTED_PROTOCOL_EXCEPTION))
            complete();
    }).requestHandler(req -> fail());
    startServer(testAddress);
    client.request(new RequestOptions().setPort(proxy.getPort()).setHost(proxy.getHost()).setURI(DEFAULT_TEST_URI)).compose(HttpClientRequest::send).onComplete(onFailure(req -> complete()));
    try {
        await();
    } finally {
        proxy.stop();
    }
}
Also used : HAProxyMessageCompletionHandler(io.vertx.core.net.impl.HAProxyMessageCompletionHandler) IntStream(java.util.stream.IntStream) java.util(java.util) DecompressionException(io.netty.handler.codec.compression.DecompressionException) io.vertx.core(io.vertx.core) SimpleDateFormat(java.text.SimpleDateFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) Utils(io.vertx.core.impl.Utils) Collections.singletonList(java.util.Collections.singletonList) ServerSocket(java.net.ServerSocket) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) ReadStream(io.vertx.core.streams.ReadStream) HAProxy(io.vertx.test.proxy.HAProxy) Pump(io.vertx.core.streams.Pump) Assume(org.junit.Assume) DetectFileDescriptorLeaks(io.vertx.test.core.DetectFileDescriptorLeaks) DateFormat(java.text.DateFormat) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) java.util.concurrent(java.util.concurrent) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Future(io.vertx.core.Future) io.vertx.core.net(io.vertx.core.net) Nullable(io.vertx.codegen.annotations.Nullable) HttpServerRequestInternal(io.vertx.core.http.impl.HttpServerRequestInternal) AtomicLong(java.util.concurrent.atomic.AtomicLong) Repeat(io.vertx.test.core.Repeat) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) java.io(java.io) PUT(io.vertx.core.http.HttpMethod.PUT) java.util.function(java.util.function) FakeStream(io.vertx.test.fakestream.FakeStream) TemporaryFolder(org.junit.rules.TemporaryFolder) ServerCookie(io.vertx.core.http.impl.ServerCookie) HAProxy(io.vertx.test.proxy.HAProxy)

Example 5 with HAProxy

use of io.vertx.test.proxy.HAProxy in project vert.x by eclipse.

the class HttpTLSTest method testHAProxy.

@Test
public void testHAProxy() throws Exception {
    SocketAddress remote = SocketAddress.inetSocketAddress(56324, "192.168.0.1");
    SocketAddress local = SocketAddress.inetSocketAddress(443, "192.168.0.11");
    Buffer header = HAProxy.createVersion1TCP4ProtocolHeader(remote, local);
    HAProxy proxy = new HAProxy("localhost", 4043, header);
    proxy.start(vertx);
    try {
        testTLS(Cert.NONE, Trust.SERVER_JKS, Cert.SERVER_JKS, Trust.NONE).serverUsesProxyProtocol().connectHostname(proxy.getHost()).connectPort(proxy.getPort()).pass();
    } finally {
        proxy.stop();
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) HAProxy(io.vertx.test.proxy.HAProxy) Test(org.junit.Test)

Aggregations

HAProxy (io.vertx.test.proxy.HAProxy)7 Test (org.junit.Test)7 Buffer (io.vertx.core.buffer.Buffer)6 Future (io.vertx.core.Future)5 ReadStream (io.vertx.core.streams.ReadStream)5 TestUtils (io.vertx.test.core.TestUtils)5 java.util (java.util)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 ConnectTimeoutException (io.netty.channel.ConnectTimeoutException)4 DecompressionException (io.netty.handler.codec.compression.DecompressionException)4 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)4 Http2Exception (io.netty.handler.codec.http2.Http2Exception)4 Nullable (io.vertx.codegen.annotations.Nullable)4 io.vertx.core (io.vertx.core)4 AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)4 PUT (io.vertx.core.http.HttpMethod.PUT)4 HttpServerRequestInternal (io.vertx.core.http.impl.HttpServerRequestInternal)4 ServerCookie (io.vertx.core.http.impl.ServerCookie)4