diff --git a/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java b/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java index 0fd29a378..3d1fe24ef 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java @@ -19,6 +19,8 @@ */ package org.carapaceproxy; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -35,11 +37,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.io.IOUtils; -import org.carapaceproxy.core.EndpointKey; import org.carapaceproxy.core.HttpProxyServer; import org.carapaceproxy.utils.TestEndpointMapper; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -172,7 +171,6 @@ public void testConnectionResetByPeerDuringWriteToEndpoint() throws Exception { mockServer.start(); TestEndpointMapper mapper = new TestEndpointMapper("localhost", mockServer.getPort()); - EndpointKey key = new EndpointKey("localhost", mockServer.getPort()); int size = 20_000_000; @@ -203,16 +201,16 @@ public void testConnectionResetByPeerDuringWriteToEndpoint() throws Exception { @Test public void testBlockingServerWorks() throws Exception { - - try (SimpleBlockingTcpServer mockServer = - new SimpleBlockingTcpServer(() -> { - return new StaticResponseHandler("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nit works!\r\n".getBytes(StandardCharsets.US_ASCII)); - })) { - + SimpleBlockingTcpServer mockServer = new SimpleBlockingTcpServer(() -> new StaticResponseHandler(""" + HTTP/1.1 200 OK\r + Content-Type: text/plain\r + \r + it works!\r + """.getBytes(StandardCharsets.US_ASCII))); + try (mockServer) { mockServer.start(); TestEndpointMapper mapper = new TestEndpointMapper("localhost", mockServer.getPort()); - EndpointKey key = new EndpointKey("localhost", mockServer.getPort()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java b/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java index 53682fd45..207161a3b 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java @@ -23,6 +23,9 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import com.github.tomakehurst.wiremock.junit.WireMockRule; import java.net.URI; import java.nio.charset.StandardCharsets; @@ -32,12 +35,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.io.IOUtils; -import org.carapaceproxy.core.EndpointKey; import org.carapaceproxy.core.HttpProxyServer; import org.carapaceproxy.utils.TestEndpointMapper; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -64,11 +63,10 @@ public void test() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); int size = 100; int concurrentClients = 4; - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java b/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java index 7b3d35033..130fa5c28 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java @@ -19,17 +19,18 @@ under the License. */ + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.File; -import org.carapaceproxy.core.HttpProxyServer; import java.util.Properties; import org.carapaceproxy.configstore.HerdDBConfigurationStore; import org.carapaceproxy.configstore.PropertiesConfigurationStore; +import org.carapaceproxy.core.HttpProxyServer; import org.carapaceproxy.server.filters.RegexpMapUserIdFilter; import org.carapaceproxy.server.filters.XForwardedForRequestFilter; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; diff --git a/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java b/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java index fa98b5ea6..c7628d480 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java @@ -71,7 +71,6 @@ import java.io.OutputStream; import java.io.PrintWriter; import java.net.Socket; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -148,7 +147,7 @@ public void clientsKeepAliveSimpleTest() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); try (RawHttpClient client = new RawHttpClient("localhost", port)) { @@ -194,9 +193,8 @@ public void downloadSmallPayloadsTest() throws Exception { .withBody("a"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); @@ -235,7 +233,7 @@ public void testManyInflightRequests() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); assertTrue(port > 0); @@ -247,68 +245,68 @@ public void testManyInflightRequests() throws Exception { clients.add(client); } - int i = 0; for (RawHttpClient client : clients) { client.close(); - i++; } } } @Test public void testKeepAliveTimeout() throws Exception { - RawHttpServer httpServer = new RawHttpServer(new HttpServlet() { + final RawHttpServer httpServer = new RawHttpServer(new HttpServlet() { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("it works !!"); } }); - httpServer.setIdleTimeout(5); - int httpServerPort = httpServer.start(); - - TestEndpointMapper mapper = new TestEndpointMapper("localhost", httpServerPort); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { - server.start(); - int port = server.getLocalPort(); - assertTrue(port > 0); + try (httpServer) { + httpServer.setIdleTimeout(5); + int httpServerPort = httpServer.start(); + + TestEndpointMapper mapper = new TestEndpointMapper("localhost", httpServerPort); + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { + server.start(); + int port = server.getLocalPort(); + assertTrue(port > 0); - try (RawHttpClient client = new RawHttpClient("localhost", port)) { - for (int j = 0; j < 2; j++) { - RawHttpClient.HttpResponse res = client.get("/index.html"); - String resp = res.getBodyString(); - System.out.println("RESP: " + resp + "; HEADERS: " + String.join("; ", res.getHeaderLines())); - Thread.sleep(10_000); + try (RawHttpClient client = new RawHttpClient("localhost", port)) { + for (int j = 0; j < 2; j++) { + RawHttpClient.HttpResponse res = client.get("/index.html"); + String resp = res.getBodyString(); + System.out.println("RESP: " + resp + "; HEADERS: " + String.join("; ", res.getHeaderLines())); + Thread.sleep(10_000); + } + } catch (Exception e) { + System.out.println("EXCEPTION: " + e); } - } catch (Exception e) { - System.out.println("EXCEPTION: " + e); } } } @Test public void testEmptyDataFromServer() throws Exception { - - RawHttpServer httpServer = new RawHttpServer(new HttpServlet() { + final RawHttpServer httpServer = new RawHttpServer(new HttpServlet() { public void doGet(HttpServletRequest request, HttpServletResponse response) { } }); - int httpServerPort = httpServer.start(); - - TestEndpointMapper mapper = new TestEndpointMapper("localhost", httpServerPort); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { - server.start(); - int port = server.getLocalPort(); - assertTrue(port > 0); + try (httpServer) { + int httpServerPort = httpServer.start(); + TestEndpointMapper mapper = new TestEndpointMapper("localhost", httpServerPort); + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { + server.start(); + int port = server.getLocalPort(); + assertTrue(port > 0); - try (RawHttpClient client = new RawHttpClient("localhost", port)) { - for (int j = 0; j < 2; j++) { - RawHttpClient.HttpResponse res = client.get("/index.html"); - String resp = res.getBodyString(); - System.out.println("RESP: " + resp + "; HEADERS: " + String.join("; ", res.getHeaderLines())); + try (RawHttpClient client = new RawHttpClient("localhost", port)) { + for (int j = 0; j < 2; j++) { + RawHttpClient.HttpResponse res = client.get("/index.html"); + String resp = res.getBodyString(); + System.out.println("RESP: " + resp + "; HEADERS: " + String.join("; ", res.getHeaderLines())); + } + } catch (Exception e) { + System.out.println("EXCEPTION: " + e); } - } catch (Exception e) { - System.out.println("EXCEPTION: " + e); } } } @@ -316,12 +314,13 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) { @Test public void testServerRequestContinue() throws Exception { AtomicBoolean responseEnabled = new AtomicBoolean(); - try (DummyServer server = new DummyServer("localhost", 8086, responseEnabled)) { + final int dummyServerPort = 8086; + try (DummyServer server = new DummyServer("localhost", dummyServerPort, responseEnabled)) { - TestEndpointMapper mapper = new TestEndpointMapper("localhost", 8086); + TestEndpointMapper mapper = new TestEndpointMapper("localhost", dummyServerPort); ExecutorService ex = Executors.newFixedThreadPool(2); - List futures = new ArrayList<>(); + List> futures = new ArrayList<>(); CarapaceLogger.setLoggingDebugEnabled(true); @@ -399,7 +398,7 @@ public void testServerRequestContinue() throws Exception { } })); } finally { - for (Future future : futures) { + for (Future future : futures) { try { future.get(); } catch (InterruptedException | ExecutionException e) { @@ -437,15 +436,14 @@ public DummyServer(String host, int port, AtomicBoolean responseEnabled) throws public void initChannel(SocketChannel channel) { channel.pipeline().addLast(new HttpRequestDecoder()); channel.pipeline().addLast(new HttpResponseEncoder()); - channel.pipeline().addLast(new SimpleChannelInboundHandler() { + channel.pipeline().addLast(new SimpleChannelInboundHandler<>() { private boolean keepAlive; private boolean continueRequest; @Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) { - if (msg instanceof HttpRequest) { - HttpRequest request = (HttpRequest) msg; + if (msg instanceof final HttpRequest request) { System.out.println("[DummyServer] HttpRequest: " + request); keepAlive = HttpUtil.isKeepAlive(request); continueRequest = HttpUtil.is100ContinueExpected(request); @@ -456,7 +454,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) { ); ctx.write(response); } - } else if (msg instanceof LastHttpContent) { + } else if (msg instanceof final LastHttpContent lastContent) { try { while (!responseEnabled.get()) { Thread.sleep(1_000); @@ -465,13 +463,12 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) { } - LastHttpContent lastContent = (LastHttpContent) msg; - String trailer = lastContent.content().asReadOnly().readCharSequence(lastContent.content().readableBytes(), Charset.forName("utf-8")).toString(); + String trailer = lastContent.content().asReadOnly().readCharSequence(lastContent.content().readableBytes(), StandardCharsets.UTF_8).toString(); System.out.println("[DummyServer] LastHttpContent: " + trailer); DefaultFullHttpResponse response = new DefaultFullHttpResponse( HTTP_1_1, HttpResponseStatus.OK, - Unpooled.copiedBuffer("resp=" + (continueRequest ? "client1" : "client2"), Charset.forName("utf-8")) + Unpooled.copiedBuffer("resp=" + (continueRequest ? "client1" : "client2"), StandardCharsets.UTF_8) ); response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8"); response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()); @@ -482,9 +479,8 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) { if (!keepAlive) { ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } - } else if (msg instanceof HttpContent) { - HttpContent content = (HttpContent) msg; - String httpContent = content.content().asReadOnly().readCharSequence(content.content().readableBytes(), Charset.forName("utf-8")).toString(); + } else if (msg instanceof final HttpContent content) { + String httpContent = content.content().asReadOnly().readCharSequence(content.content().readableBytes(), StandardCharsets.UTF_8).toString(); System.out.println("[DummyServer] HttpContent: " + httpContent); } } @@ -534,10 +530,8 @@ public void testMultiClientTimeout() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); - ExecutorService ex = Executors.newFixedThreadPool(2); - List futures = new ArrayList<>(); + List> futures = new ArrayList<>(); CarapaceLogger.setLoggingDebugEnabled(true); @@ -602,7 +596,7 @@ public void testMultiClientTimeout() throws Exception { } })); } finally { - for (Future future : futures) { + for (Future future : futures) { try { future.get(); } catch (InterruptedException | ExecutionException e) { @@ -621,7 +615,7 @@ public void testMultiClientTimeout() throws Exception { public void testMaxConnectionsAndBorrowTimeout() throws Exception { CarapaceLogger.setLoggingDebugEnabled(true); ExecutorService ex = Executors.newFixedThreadPool(2); - List futures = new ArrayList<>(); + List> futures = new ArrayList<>(); AtomicBoolean responseEnabled = new AtomicBoolean(); try (DummyServer server = new DummyServer("localhost", 8086, responseEnabled)) { @@ -727,7 +721,7 @@ public void testInvalidUriChars() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); try (RawHttpClient client = new RawHttpClient("localhost", port)) { @@ -741,13 +735,12 @@ public void testInvalidUriChars() throws Exception { @Test @Parameters({"http", "https"}) public void testClosedProxy(String scheme) throws Exception { - String certificate = TestUtils.deployResource("localhost.p12", tmpDir.getRoot()); + TestUtils.deployResource("localhost.p12", tmpDir.getRoot()); // Proxy requests have to use "localhost:port" as endpoint instead of the one in the url (ex yahoo.com) // in order to avoid open proxy vulnerability TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); - try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot());) { + try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot())) { server.addCertificate(new SSLCertificateConfiguration("localhost", null, "localhost.p12", "testproxy", STATIC)); server.addListener(new NetworkListenerConfiguration("localhost", 0, scheme.equals("https"), null, "localhost", DEFAULT_SSL_PROTOCOLS, 128, true, 300, 60, 8, 100, DEFAULT_FORWARDED_STRATEGY, Set.of(), Set.of(HTTP11.name()))); @@ -819,7 +812,7 @@ public void testCookies() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); try (RawHttpClient client = new RawHttpClient("localhost", port)) { diff --git a/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java b/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java index 179fb2dc6..72ebd31e4 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java @@ -46,34 +46,30 @@ public class RealBackendsTest { private static RawHttpClient.HttpResponse doGet(RawHttpClient client, String host, String uri) throws IOException { - RawHttpClient.HttpResponse response = - client.executeRequest("GET " + uri + " HTTP/1.1" - + "\r\nHost: " + host - + "\r\nAccept-Encoding: gzip, deflate, br" - + "\r\nCache-Control: no-cache" - + "\r\nPragma: no-cache" - + "\r\nConnection: keep-alive" - + "\r\n\r\n" - ); - return response; + return client.executeRequest("GET " + uri + " HTTP/1.1" + + "\r\nHost: " + host + + "\r\nAccept-Encoding: gzip, deflate, br" + + "\r\nCache-Control: no-cache" + + "\r\nPragma: no-cache" + + "\r\nConnection: keep-alive" + + "\r\n\r\n" + ); } private static RawHttpClient.HttpResponse doPost(RawHttpClient client, String host, String auth, String uri, String body) throws IOException { - RawHttpClient.HttpResponse response = - client.executeRequest("POST " + uri + " HTTP/1.1" - + "\r\nHost: " + host - + "\r\nAuthorization: Bearer " + auth - + "\r\nAccept: application/json" - + "\r\nAccept-Encoding: gzip, deflate, br" - + "\r\nCache-Control: no-cache" - + "\r\nConnection: keep-alive" - + "\r\nContent-Type: application/json" - + "\r\nContent-Length: " + body.length() - + "\r\n\r\n" - + body - ); - return response; + return client.executeRequest("POST " + uri + " HTTP/1.1" + + "\r\nHost: " + host + + "\r\nAuthorization: Bearer " + auth + + "\r\nAccept: application/json" + + "\r\nAccept-Encoding: gzip, deflate, br" + + "\r\nCache-Control: no-cache" + + "\r\nConnection: keep-alive" + + "\r\nContent-Type: application/json" + + "\r\nContent-Length: " + body.length() + + "\r\n\r\n" + + body + ); } @@ -90,23 +86,18 @@ public void testRequestsRealBackend() throws Exception { final int requestsPerClient = 1000; TestEndpointMapper mapper = new TestEndpointMapper(host, 8443); ExecutorService ex = Executors.newFixedThreadPool(threads); - List futures = new ArrayList<>(); + List> futures = new ArrayList<>(); AtomicInteger countOk = new AtomicInteger(); AtomicInteger countError = new AtomicInteger(); AtomicBoolean stop = new AtomicBoolean(); final String carapaceHost = "localhost"; - int port = 443; - boolean isLocal = carapaceHost.equals("localhost"); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { RuntimeServerConfiguration config = new RuntimeServerConfiguration(); config.setMaxConnectionsPerEndpoint(1); server.getProxyRequestsManager().reloadConfiguration(config, mapper.getBackends().values()); server.start(); - if (isLocal) { - port = server.getLocalPort(); - } - final int carapaceport = port; + final int carapaceport = server.getLocalPort(); try { @@ -114,7 +105,7 @@ public void testRequestsRealBackend() throws Exception { futures.add(ex.submit(() -> { try { - try (RawHttpClient client = new RawHttpClient(carapaceHost, carapaceport, !isLocal)) { + try (RawHttpClient client = new RawHttpClient(carapaceHost, carapaceport, false)) { client.getSocket().setKeepAlive(true); client.getSocket().setSoTimeout(1000 * 30); for (int rq = 0; rq < requestsPerClient; rq++) { @@ -145,7 +136,7 @@ public void testRequestsRealBackend() throws Exception { } } finally { - for (Future future : futures) { + for (Future future : futures) { try { future.get(); } catch (Throwable e) { diff --git a/carapace-server/src/test/java/org/carapaceproxy/api/UseAdminServer.java b/carapace-server/src/test/java/org/carapaceproxy/api/UseAdminServer.java index 87086681f..91cc6dd66 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/api/UseAdminServer.java +++ b/carapace-server/src/test/java/org/carapaceproxy/api/UseAdminServer.java @@ -19,18 +19,17 @@ */ package org.carapaceproxy.api; +import static org.carapaceproxy.core.HttpProxyServer.buildForTests; +import static org.junit.Assert.assertNull; import java.io.File; import java.io.IOException; import java.util.Properties; import org.carapaceproxy.configstore.PropertiesConfigurationStore; import org.carapaceproxy.core.HttpProxyServer; -import static org.carapaceproxy.core.HttpProxyServer.buildForTests; import org.carapaceproxy.server.config.ConfigurationChangeInProgressException; -import org.carapaceproxy.server.config.ConfigurationNotValidException; import org.carapaceproxy.utils.RawHttpClient; import org.carapaceproxy.utils.TestEndpointMapper; import org.junit.After; -import static org.junit.Assert.assertNull; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TemporaryFolder; @@ -67,7 +66,7 @@ public void buildNewServer() throws Exception { } @After - public void stopServer() throws Exception { + public void stopServer() { if (server != null) { server.close(); server = null; @@ -94,7 +93,7 @@ public void startAdmin() throws Exception { startServer(new Properties(HTTP_ADMIN_SERVER_CONFIG)); } - public void changeDynamicConfiguration(Properties configuration) throws ConfigurationNotValidException, ConfigurationChangeInProgressException, InterruptedException, IOException { + public void changeDynamicConfiguration(Properties configuration) throws ConfigurationChangeInProgressException, InterruptedException, IOException { if (server != null) { fixAccessLogFileConfiguration(configuration); PropertiesConfigurationStore config = new PropertiesConfigurationStore(configuration); diff --git a/carapace-server/src/test/java/org/carapaceproxy/backends/ChunckedEncodingRequestsTest.java b/carapace-server/src/test/java/org/carapaceproxy/backends/ChunckedEncodingRequestsTest.java index 1e7ef8abc..8cee0ba66 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/backends/ChunckedEncodingRequestsTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/backends/ChunckedEncodingRequestsTest.java @@ -19,16 +19,15 @@ */ package org.carapaceproxy.backends; -import org.carapaceproxy.utils.TestEndpointMapper; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.junit.Assert.assertTrue; import com.github.tomakehurst.wiremock.junit.WireMockRule; -import org.carapaceproxy.core.EndpointKey; import org.carapaceproxy.core.HttpProxyServer; import org.carapaceproxy.utils.RawHttpClient; -import static org.junit.Assert.assertTrue; +import org.carapaceproxy.utils.TestEndpointMapper; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -70,9 +69,8 @@ public void testSimple() throws Exception { ); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); - - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); @@ -100,9 +98,8 @@ public void testClientAbortsUpload() throws Exception { ); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/backends/RestartEndpointTest.java b/carapace-server/src/test/java/org/carapaceproxy/backends/RestartEndpointTest.java index e23a53de5..5381a0fd0 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/backends/RestartEndpointTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/backends/RestartEndpointTest.java @@ -46,7 +46,7 @@ public class RestartEndpointTest { // in order to be restartable this must be fixed private static int tryDiscoverEmptyPort() { - try (ServerSocket s = new ServerSocket();) { + try (ServerSocket s = new ServerSocket()) { s.bind(null); return s.getLocalPort(); } catch (IOException err) { @@ -75,7 +75,7 @@ public void testClientsSendsRequestOnDownBackendAtSendRequest() throws Exception )); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); @@ -110,7 +110,7 @@ public void testClientsSendsRequestOnDownBackendAtSendRequestWithCache() throws )); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); @@ -151,7 +151,7 @@ public void testClientsSendsRequestBackendRestart() throws Exception { TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); CarapaceLogger.setLoggingDebugEnabled(true); - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/core/RequestsLoggerTest.java b/carapace-server/src/test/java/org/carapaceproxy/core/RequestsLoggerTest.java index 2b45aecd7..488c8e32e 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/core/RequestsLoggerTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/core/RequestsLoggerTest.java @@ -23,11 +23,18 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.common.io.Files; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpVersion; import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; @@ -37,21 +44,13 @@ import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.util.List; - -import io.netty.handler.codec.http.HttpVersion; import org.carapaceproxy.server.mapper.MapResult; import org.carapaceproxy.utils.RawHttpClient; import org.carapaceproxy.utils.TestEndpointMapper; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import reactor.netty.http.server.HttpServerRequest; /** @@ -512,7 +511,6 @@ public void test() throws Exception { @Test public void testWithServer() throws Exception { - stubFor(get(urlEqualTo("/index.html")) .willReturn(aResponse() .withStatus(200) @@ -521,7 +519,6 @@ public void testWithServer() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.getCurrentConfiguration().setAccessLogPath(tmpDir.getRoot().getAbsolutePath() + "/access.log"); @@ -565,7 +562,6 @@ public void testAccessLogRotation() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.getCurrentConfiguration().setAccessLogPath(tmpDir.getRoot().getAbsolutePath() + "/access.log"); @@ -574,39 +570,39 @@ public void testAccessLogRotation() throws Exception { server.start(); int port = server.getLocalPort(); System.out.println("CurrentAccessLogPath " + currentAccessLogPath); - FileChannel logFileChannel = FileChannel.open(currentAccessLogPath); - - while (logFileChannel.size() < 1024) { - try (RawHttpClient client = new RawHttpClient("localhost", port)) { - RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); - String s = resp.toString(); - assertTrue(s.contains("it works !!")); - } - - try (RawHttpClient client = new RawHttpClient("localhost", port)) { - { - RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n"); + try (FileChannel logFileChannel = FileChannel.open(currentAccessLogPath)) { + while (logFileChannel.size() < 1024) { + try (RawHttpClient client = new RawHttpClient("localhost", port)) { + RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); String s = resp.toString(); assertTrue(s.contains("it works !!")); } - { - RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n"); - String s = resp.toString(); - assertTrue(s.contains("it works !!")); + try (RawHttpClient client = new RawHttpClient("localhost", port)) { + { + RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n"); + String s = resp.toString(); + assertTrue(s.contains("it works !!")); + } + + { + RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n"); + String s = resp.toString(); + assertTrue(s.contains("it works !!")); + } } } + Thread.sleep(3000); + //check if gzip file exist + File[] f = new File(tmpDir.getRoot().getAbsolutePath()).listFiles((dir, name) -> name.startsWith("access") && name.contains(".gzip")); + assertTrue(f.length == 1); + try (RawHttpClient client = new RawHttpClient("localhost", port)) { + RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); + String s = resp.toString(); + assertTrue(s.contains("it works !!")); + } + assertTrue(logFileChannel.size() > 0); } - Thread.sleep(3000); - //check if gzip file exist - File[] f = new File(tmpDir.getRoot().getAbsolutePath()).listFiles((dir, name) -> name.startsWith("access") && name.contains(".gzip")); - assertTrue(f.length == 1); - try (RawHttpClient client = new RawHttpClient("localhost", port)) { - RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"); - String s = resp.toString(); - assertTrue(s.contains("it works !!")); - } - assertTrue(logFileChannel.size() > 0); } } diff --git a/carapace-server/src/test/java/org/carapaceproxy/listeners/ListenerConfigurationTest.java b/carapace-server/src/test/java/org/carapaceproxy/listeners/ListenerConfigurationTest.java index a4c21fe34..d34c096f5 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/listeners/ListenerConfigurationTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/listeners/ListenerConfigurationTest.java @@ -6,10 +6,10 @@ import java.util.Map; import java.util.Properties; import org.carapaceproxy.configstore.PropertiesConfigurationStore; +import org.carapaceproxy.core.EndpointKey; import org.carapaceproxy.core.HttpProxyServer; import org.carapaceproxy.core.Listeners; import org.carapaceproxy.server.config.ConfigurationChangeInProgressException; -import org.carapaceproxy.core.EndpointKey; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; diff --git a/carapace-server/src/test/java/org/carapaceproxy/listeners/SSLSNITest.java b/carapace-server/src/test/java/org/carapaceproxy/listeners/SSLSNITest.java index 41067a718..685e1e88b 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/listeners/SSLSNITest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/listeners/SSLSNITest.java @@ -35,7 +35,6 @@ import java.security.cert.X509Certificate; import java.util.Set; import javax.net.ssl.SSLSession; -import org.carapaceproxy.core.EndpointKey; import org.carapaceproxy.core.HttpProxyServer; import org.carapaceproxy.server.config.ConfigurationNotValidException; import org.carapaceproxy.server.config.NetworkListenerConfiguration; @@ -70,9 +69,8 @@ public void testSelectCertWithoutSNI() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); - - try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot());) { + + try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot())) { server.addCertificate(new SSLCertificateConfiguration(nonLocalhost, null, certificate, "testproxy", STATIC)); server.addListener(new NetworkListenerConfiguration(nonLocalhost, 0, true, null, nonLocalhost /* default */, DEFAULT_SSL_PROTOCOLS, 128, true, 300, 60, 8, 1000, DEFAULT_FORWARDED_STRATEGY, Set.of(), Set.of(HTTP11.name()))); server.start(); @@ -91,7 +89,7 @@ public void testSelectCertWithoutSNI() throws Exception { public void testChooseCertificate() throws Exception { TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot());) { + try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot())) { server.addCertificate(new SSLCertificateConfiguration("other", null, "cert", "pwd", STATIC)); server.addCertificate(new SSLCertificateConfiguration("*.example.com", Set.of("example.com", "*.example2.com"), "cert", "pwd", STATIC)); @@ -135,7 +133,7 @@ public void testChooseCertificate() throws Exception { assertEquals("*.example.com", server.getListeners().chooseCertificate("test.example2.com", "no-default").getId()); } - try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot());) { + try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot())) { // full wildcard server.addCertificate(new SSLCertificateConfiguration("*", null, "cert", "pwd", STATIC)); diff --git a/carapace-server/src/test/java/org/carapaceproxy/server/cache/CacheContentLengthLimitTest.java b/carapace-server/src/test/java/org/carapaceproxy/server/cache/CacheContentLengthLimitTest.java index 54af84804..6f60ebd9f 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/server/cache/CacheContentLengthLimitTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/server/cache/CacheContentLengthLimitTest.java @@ -23,6 +23,10 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import com.github.tomakehurst.wiremock.junit.WireMockRule; import java.io.IOException; import org.carapaceproxy.EndpointStats; @@ -30,10 +34,6 @@ import org.carapaceproxy.core.HttpProxyServer; import org.carapaceproxy.utils.RawHttpClient; import org.carapaceproxy.utils.TestEndpointMapper; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -80,7 +80,6 @@ public void testWithoutContentLengthHeader() throws Exception { } private void testFileSizeCache(String body, boolean chunked) throws Exception { - TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); diff --git a/carapace-server/src/test/java/org/carapaceproxy/server/cache/CacheTest.java b/carapace-server/src/test/java/org/carapaceproxy/server/cache/CacheTest.java index 3a41a2fff..1164a5d3b 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/server/cache/CacheTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/server/cache/CacheTest.java @@ -76,7 +76,6 @@ public void testServeFromCache() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); @@ -146,7 +145,6 @@ public void testNotServeFromCacheIfCachableButClientsDisablesCache() throws Exce .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); @@ -203,9 +201,7 @@ public void testBootSslRelativeCertificatePath() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); - EndpointStats stats; try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot());) { server.addCertificate(new SSLCertificateConfiguration("localhost", null, "localhost.p12", "testproxy", STATIC)); server.addListener(new NetworkListenerConfiguration("localhost", 0, true, null, "localhost", @@ -229,7 +225,6 @@ public void testServeFromCacheSsl(boolean cacheDisabledForSecureRequestsWithoutP .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot());) { server.addCertificate(new SSLCertificateConfiguration("localhost", null, "localhost.p12", "testproxy", STATIC)); @@ -359,7 +354,6 @@ public void testServeFromCacheWithRequestProtocol() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); int httpPort = 1234; int httpsPort = 1235; @@ -473,7 +467,6 @@ public void testServeFromCacheChunked() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); @@ -531,7 +524,6 @@ public void testServeFromCacheWithConnectionClose() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); @@ -589,7 +581,6 @@ public void testNotCachableResourceWithQueryString() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); @@ -624,7 +615,6 @@ public void testImagesCachableWithQueryString() throws Exception { .withBody("it works !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); @@ -652,7 +642,6 @@ public void testImagesCachableWithQueryString() throws Exception { @Test public void testNoCacheResponse() throws Exception { TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/server/cache/NotModifiedTest.java b/carapace-server/src/test/java/org/carapaceproxy/server/cache/NotModifiedTest.java index 6e305e4bb..1b42ecf5f 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/server/cache/NotModifiedTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/server/cache/NotModifiedTest.java @@ -19,19 +19,20 @@ under the License. */ -import org.carapaceproxy.utils.HttpUtils; -import org.carapaceproxy.utils.TestEndpointMapper; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import org.carapaceproxy.core.HttpProxyServer; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import org.carapaceproxy.core.EndpointKey; -import org.carapaceproxy.utils.RawHttpClient; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import org.carapaceproxy.core.EndpointKey; +import org.carapaceproxy.core.HttpProxyServer; +import org.carapaceproxy.utils.HttpUtils; +import org.carapaceproxy.utils.RawHttpClient; +import org.carapaceproxy.utils.TestEndpointMapper; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -57,7 +58,6 @@ public void testServeFromCacheAnswer304() throws Exception { )); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); @@ -80,7 +80,7 @@ public void testServeFromCacheAnswer304() throws Exception { + "Host: localhost\r\n" + "If-Modified-Since: " + HttpUtils.formatDateHeader(new java.util.Date(System.currentTimeMillis())) + "\r\n" + "\r\n"); - assertTrue(resp.getStatusLine().trim().equals("HTTP/1.1 304 Not Modified")); + assertEquals("HTTP/1.1 304 Not Modified", resp.getStatusLine().trim()); resp.getHeaderLines().forEach(h -> { System.out.println("HEADER LINE :" + h); }); diff --git a/carapace-server/src/test/java/org/carapaceproxy/server/filters/XForwardedForFilterTest.java b/carapace-server/src/test/java/org/carapaceproxy/server/filters/XForwardedForFilterTest.java index 5b5bbad31..8a6b94efb 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/server/filters/XForwardedForFilterTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/server/filters/XForwardedForFilterTest.java @@ -102,7 +102,6 @@ public void testNoXForwardedForFilter() throws Exception { .withBody("No X-Forwarded-For"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/server/filters/XTlsCipherFilterTest.java b/carapace-server/src/test/java/org/carapaceproxy/server/filters/XTlsCipherFilterTest.java index f1a65a0a1..e8bcd2281 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/server/filters/XTlsCipherFilterTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/server/filters/XTlsCipherFilterTest.java @@ -53,7 +53,6 @@ public void TestXTlsProtocol() throws Exception { .withBody("it absent !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.addCertificate(new SSLCertificateConfiguration("*", null, certificate, "testproxy", STATIC)); diff --git a/carapace-server/src/test/java/org/carapaceproxy/server/filters/XTlsProtocolFilterTest.java b/carapace-server/src/test/java/org/carapaceproxy/server/filters/XTlsProtocolFilterTest.java index 1d62390a5..82921f79e 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/server/filters/XTlsProtocolFilterTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/server/filters/XTlsProtocolFilterTest.java @@ -13,7 +13,6 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule; import java.util.Collections; import java.util.Set; -import org.carapaceproxy.core.EndpointKey; import org.carapaceproxy.core.HttpProxyServer; import org.carapaceproxy.server.config.NetworkListenerConfiguration; import org.carapaceproxy.server.config.RequestFilterConfiguration; @@ -52,7 +51,6 @@ public void TestXTlsProtocol() throws Exception { .withBody("it absent !!"))); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - EndpointKey key = new EndpointKey("localhost", wireMockRule.port()); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.addCertificate(new SSLCertificateConfiguration("*", null, certificate, "testproxy", STATIC)); diff --git a/carapace-server/src/test/java/org/carapaceproxy/users/FileUserRealmTest.java b/carapace-server/src/test/java/org/carapaceproxy/users/FileUserRealmTest.java index efa83b82c..de197517a 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/users/FileUserRealmTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/users/FileUserRealmTest.java @@ -19,6 +19,11 @@ */ package org.carapaceproxy.users; +import static org.carapaceproxy.core.HttpProxyServer.buildForTests; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; @@ -29,14 +34,9 @@ import org.carapaceproxy.configstore.ConfigurationStore; import org.carapaceproxy.configstore.PropertiesConfigurationStore; import org.carapaceproxy.core.HttpProxyServer; -import static org.carapaceproxy.core.HttpProxyServer.buildForTests; import org.carapaceproxy.user.FileUserRealm; import org.carapaceproxy.user.UserRealm; import org.carapaceproxy.utils.TestEndpointMapper; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder;