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