diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 3977c4cb4..cf82c05a1 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -16,27 +16,43 @@ name: Java CI - Code tests on: [pull_request] env: - MAVEN_OPTS: -Dmaven.artifact.threads=4 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dmaven.wagon.httpconnectionManager.ttlSeconds=25 -Dmaven.wagon.http.retryHandler.count=3 + MAVEN_OPTS: >- + -Dmaven.artifact.threads=4 + -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + -Dmaven.wagon.httpconnectionManager.ttlSeconds=25 + -Dmaven.wagon.http.retryHandler.count=3 + MAVEN_CLI_OPTS: >- + --batch-mode + -Pproduction + -Dmaven.test.redirectTestOutputToFile=true + -Dsurefire.rerunFailingTestsCount=3 + --update-snapshots +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: build: runs-on: ubuntu-latest steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.6.0 - with: - access_token: ${{ github.token }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: 'Set up JDK 17' - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: - java-version: '17.0.3' + java-version: '17' + distribution: 'temurin' - name: 'Cache Maven packages' - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.m2 key: 'cache' restore-keys: 'cache' - - name: 'Build with Maven' - run: mvn verify -Pproduction -Dmaven.test.redirectTestOutputToFile=true -Dsurefire.rerunFailingTestsCount=3 - - name: 'Remove Snapshots Before Caching' - run: find ~/.m2 -name '*SNAPSHOT' | xargs rm -Rf + - name: 'Build and test with Maven' + run: mvn verify + - name: 'Report test results' + uses: dorny/test-reporter@v1 + if: always() + with: + name: Maven Tests + path: carapace-*/target/surefire-reports/*.xml + reporter: java-junit + fail-on-error: true diff --git a/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java b/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java index 0f2142add..cfa66b107 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java @@ -363,9 +363,13 @@ public void testServerRequestContinue() throws Exception { failed.set(true); return; } - resp = consumeHttpResponseInput(socket.getInputStream()).getBodyString(); - System.out.println("### RESP client1: " + resp); - if (!resp.contains("resp=client1")) { + int count = 0; + do { + Thread.sleep(5_000); + resp = consumeHttpResponseInput(socket.getInputStream()).getBodyString(); + System.out.println("### RESP client1: " + resp); + } while (!resp.contains("resp=client1") && count++ < 10); + if (count >= 10) { failed.set(true); } } catch (Exception e) { @@ -661,9 +665,13 @@ public void testMaxConnectionsAndBorrowTimeout() throws Exception { failed.set(true); return; } - resp = consumeHttpResponseInput(socket.getInputStream()).getBodyString(); - System.out.println("### RESP client1: " + resp); - if (!resp.contains("resp=client1")) { + int count = 0; + do { + Thread.sleep(5_000); + resp = consumeHttpResponseInput(socket.getInputStream()).getBodyString(); + System.out.println("### RESP client1: " + resp); + } while (!resp.contains("resp=client1") && count++ < 10); + if (count >= 10) { failed.set(true); } } catch (Exception e) { diff --git a/carapace-server/src/test/java/org/carapaceproxy/backends/ConnectionPoolTest.java b/carapace-server/src/test/java/org/carapaceproxy/backends/ConnectionPoolTest.java index 8517f1ec6..c12f40ad9 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/backends/ConnectionPoolTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/backends/ConnectionPoolTest.java @@ -23,8 +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.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.*; @@ -70,8 +72,6 @@ public class ConnectionPoolTest extends UseAdminServer { @Rule public WireMockRule wireMockRule = new WireMockRule(0); - private Properties config; - private void configureAndStartServer() throws Exception { HttpTestUtils.overrideJvmWideHttpsVerifier(); @@ -80,10 +80,10 @@ private void configureAndStartServer() throws Exception { .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "text/html") - .withHeader("Content-Length", "it works !!".length() + "") + .withHeader("Content-Length", String.valueOf("it works !!".length())) .withBody("it works !!"))); - config = new Properties(HTTP_ADMIN_SERVER_CONFIG); + final Properties config = new Properties(HTTP_ADMIN_SERVER_CONFIG); config.put("config.type", "database"); config.put("db.jdbc.url", "jdbc:herddb:localhost"); config.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath()); @@ -107,12 +107,12 @@ private void configureAndStartServer() throws Exception { config.put("backend.1.id", "localhost"); config.put("backend.1.enabled", "true"); config.put("backend.1.host", "localhost"); - config.put("backend.1.port", wireMockRule.port() + ""); + config.put("backend.1.port", String.valueOf(wireMockRule.port())); config.put("backend.2.id", "localhost2"); config.put("backend.2.enabled", "true"); config.put("backend.2.host", "localhost2"); - config.put("backend.2.port", wireMockRule.port() + ""); + config.put("backend.2.port", String.valueOf(wireMockRule.port())); // Default director config.put("director.1.id", "*"); @@ -172,55 +172,55 @@ public void hostHeaderTest() throws Exception { //No Http header host String response = sendRequest(false, hostname, port, path, null); - assertTrue(response.contains("Bad request")); + assertThat(response, containsString("Bad request")); //Add Http header host String response2 = sendRequest(true, hostname, port, path, "localhost"); - assertTrue(response2.contains("it works !!")); + assertThat(response2, containsString("it works !!")); //Empty header host String response3 = sendRequest(true, hostname, port, path, ""); - assertTrue(response3.contains("Bad request")); + assertThat(response3, containsString("Bad request")); //Empty header host String response4 = sendRequest(true, hostname, port, path, " "); - assertTrue(response4.contains("Bad request")); + assertThat(response4, containsString("Bad request")); //Header host with special character String response5 = sendRequest(true, hostname, port, path, "local%&&host"); - assertTrue(response5.contains("Bad request")); + assertThat(response5, containsString("Bad request")); //Header host with multiple domain String response6 = sendRequest(true, hostname, port, path, "localhost1,localhost2"); - assertTrue(response6.contains("Bad request")); + assertThat(response6, containsString("Bad request")); //Ip address as host header String response7 = sendRequest(true, hostname, port, path, "127.0.0.1"); - assertTrue(response7.contains("it works !!")); + assertThat(response7, containsString("it works !!")); //Invalid ip address String response8 = sendRequest(true, hostname, port, path, "256.0.0.0"); - assertTrue(response8.contains("Bad request")); + assertThat(response8, containsString("Bad request")); //Ip address as host header with port String response9 = sendRequest(true, hostname, port, path, "127.0.0.1:8080"); - assertTrue(response9.contains("it works !!")); + assertThat(response9, containsString("it works !!")); //Hostname as host header with port String response10 = sendRequest(true, hostname, port, path, "localhost:8080"); - assertTrue(response10.contains("it works !!")); + assertThat(response10, containsString("it works !!")); //Hostname as host header with port String response11 = sendRequest(true, hostname, port, path, "localhost:8080&"); - assertTrue(response11.contains("Bad request")); + assertThat(response11, containsString("Bad Request")); //Invalid hostname String response12 = sendRequest(true, hostname, port, path, "::::8080::9999"); - assertTrue(response12.contains("Bad request")); + assertThat(response12, containsString("Bad Request")); //Add Http header host String response13 = sendRequest(true, hostname, port, path, "localhost3"); - assertTrue(response13.contains("it works !!")); + assertThat(response13, containsString("it works !!")); } public String sendRequest(boolean addHeaderHost, String hostname, int port, String path, String headerHost) throws IOException { @@ -271,8 +271,9 @@ public void test() throws Exception { ConnectionProvider provider = connectionPools.get(defaultPool); assertThat(provider, not(nullValue())); Map maxConnectionsPerHost = provider.maxConnectionsPerHost(); + assertThat(maxConnectionsPerHost, is(notNullValue(Map.class))); assertThat(maxConnectionsPerHost.size(), is(2)); - maxConnectionsPerHost.values().stream().allMatch(e -> e == 10); + assertTrue(maxConnectionsPerHost.values().stream().allMatch(e -> e == 10)); } // pool with defaults @@ -283,8 +284,9 @@ public void test() throws Exception { ConnectionProvider provider = connectionPools.get(poolWithDefaults); assertThat(provider, not(nullValue())); Map maxConnectionsPerHost = provider.maxConnectionsPerHost(); + assertThat(maxConnectionsPerHost, is(notNullValue(Map.class))); assertThat(maxConnectionsPerHost.size(), is(2)); - maxConnectionsPerHost.values().stream().allMatch(e -> e == 10); + assertTrue(maxConnectionsPerHost.values().stream().allMatch(e -> e == 10)); } // custom pool @@ -295,8 +297,9 @@ public void test() throws Exception { ConnectionProvider provider = connectionPools.get(customPool); assertThat(provider, not(nullValue())); Map maxConnectionsPerHost = provider.maxConnectionsPerHost(); + assertThat(maxConnectionsPerHost, is(notNullValue(Map.class))); assertThat(maxConnectionsPerHost.size(), is(2)); - maxConnectionsPerHost.values().stream().allMatch(e -> e == 20); + assertTrue(maxConnectionsPerHost.values().stream().allMatch(e -> e == 20)); } // connection pool selection @@ -313,8 +316,9 @@ public void test() throws Exception { assertThat(res.getKey(), is(defaultPool)); ConnectionProvider provider = res.getValue(); Map maxConnectionsPerHost = provider.maxConnectionsPerHost(); + assertThat(maxConnectionsPerHost, is(notNullValue(Map.class))); assertThat(maxConnectionsPerHost.size(), is(2)); - maxConnectionsPerHost.values().stream().allMatch(e -> e == 10); + assertTrue(maxConnectionsPerHost.values().stream().allMatch(e -> e == 10)); try (RawHttpClient client = new RawHttpClient("localhost", port)) { RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\n" + HttpHeaderNames.HOST + ": localhostx" + "\r\n\r\n"); @@ -337,8 +341,9 @@ public void test() throws Exception { assertThat(res.getKey(), is(poolWithDefaults)); ConnectionProvider provider = res.getValue(); Map maxConnectionsPerHost = provider.maxConnectionsPerHost(); + assertThat(maxConnectionsPerHost, is(notNullValue(Map.class))); assertThat(maxConnectionsPerHost.size(), is(2)); - maxConnectionsPerHost.values().stream().allMatch(e -> e == 10); + assertTrue(maxConnectionsPerHost.values().stream().allMatch(e -> e == 10)); try (RawHttpClient client = new RawHttpClient("localhost", port)) { RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\n" + HttpHeaderNames.HOST + ": localhost" + "\r\n\r\n"); @@ -361,8 +366,9 @@ public void test() throws Exception { assertThat(res.getKey(), is(customPool)); ConnectionProvider provider = res.getValue(); Map maxConnectionsPerHost = provider.maxConnectionsPerHost(); + assertThat(maxConnectionsPerHost, is(notNullValue(Map.class))); assertThat(maxConnectionsPerHost.size(), is(2)); - maxConnectionsPerHost.values().stream().allMatch(e -> e == 20); + assertTrue(maxConnectionsPerHost.values().stream().allMatch(e -> e == 20)); try (RawHttpClient client = new RawHttpClient("localhost", port)) { RawHttpClient.HttpResponse resp = client.executeRequest("GET /index.html HTTP/1.1\r\n" + HttpHeaderNames.HOST + ": localhost3" + "\r\n\r\n"); diff --git a/carapace-server/src/test/java/org/carapaceproxy/core/MaxHeaderSizeTest.java b/carapace-server/src/test/java/org/carapaceproxy/core/MaxHeaderSizeTest.java index d4e4ce228..77a5a5a69 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/core/MaxHeaderSizeTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/core/MaxHeaderSizeTest.java @@ -99,6 +99,6 @@ public void test() throws Exception { HttpResponse response2 = httpClient2.send(request, HttpResponse.BodyHandlers.ofString()); - assertEquals(413, response2.statusCode()); + assertEquals(431, response2.statusCode()); } } 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 2c25504a9..566249bf5 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 @@ -51,7 +51,7 @@ public class CacheContentLengthLimitTest { public TemporaryFolder tmpDir = new TemporaryFolder(); @Test - public void testWithContentLenghtHeader() throws Exception { + public void testWithContentLengthHeader() throws Exception { String body = "01234567890123456789"; @@ -59,14 +59,14 @@ public void testWithContentLenghtHeader() throws Exception { .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "text/html") - .withHeader("Content-Length", body.length() + "") + .withHeader("Content-Length", String.valueOf(body.length())) .withBody(body))); testFileSizeCache(body, false); } @Test - public void testWithoutContentLenghtHeader() throws Exception { + public void testWithoutContentLengthHeader() throws Exception { String body = "01234567890123456789"; @@ -86,7 +86,7 @@ private void testFileSizeCache(String body, boolean chunked) throws Exception { // No size checking { - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.getCurrentConfiguration().setCacheMaxFileSize(0); server.getCurrentConfiguration().setRequestCompressionEnabled(false); server.getCache().reloadConfiguration(server.getCurrentConfiguration()); @@ -102,7 +102,7 @@ private void testFileSizeCache(String body, boolean chunked) throws Exception { // Max size set to current content size { - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.getCurrentConfiguration().setCacheMaxFileSize(body.length()); server.getCurrentConfiguration().setRequestCompressionEnabled(false); server.getCache().reloadConfiguration(server.getCurrentConfiguration()); @@ -118,7 +118,7 @@ private void testFileSizeCache(String body, boolean chunked) throws Exception { // Max size set to drop current content { - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.getCurrentConfiguration().setCacheMaxFileSize(body.length() - 1); server.getCurrentConfiguration().setRequestCompressionEnabled(false); server.getCache().reloadConfiguration(server.getCurrentConfiguration()); diff --git a/carapace-server/src/test/java/org/carapaceproxy/server/mapper/BasicStandardEndpointMapperTest.java b/carapace-server/src/test/java/org/carapaceproxy/server/mapper/BasicStandardEndpointMapperTest.java index db4d2e899..c2bf9e4a1 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/server/mapper/BasicStandardEndpointMapperTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/server/mapper/BasicStandardEndpointMapperTest.java @@ -41,6 +41,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.util.Properties; import org.apache.commons.io.IOUtils; import org.carapaceproxy.configstore.PropertiesConfigurationStore; @@ -96,7 +97,7 @@ public void test() throws Exception { mapper.addBackend(new BackendConfiguration("backend-b", "localhost", backendPort, "/")); mapper.addDirector(new DirectorConfiguration("director-1").addBackend("backend-a")); mapper.addDirector(new DirectorConfiguration("director-2").addBackend("backend-b")); - mapper.addDirector(new DirectorConfiguration("director-all").addBackend("*")); // all of the known backends + mapper.addDirector(new DirectorConfiguration("director-all").addBackend("*")); // all the known backends mapper.addAction(new ActionConfiguration("proxy-1", ActionConfiguration.TYPE_PROXY, "director-1", null, -1)); mapper.addAction(new ActionConfiguration("cache-1", ActionConfiguration.TYPE_CACHE, "director-2", null, -1)); mapper.addAction(new ActionConfiguration("all-1", ActionConfiguration.TYPE_CACHE, "director-all", null, -1)); @@ -111,50 +112,50 @@ public void test() throws Exception { mapper.addRoute(new RouteConfiguration("route-2-not-found", "not-found-custom", true, new RegexpRequestMatcher(PROPERTY_URI, ".*notfound.html.*"))); mapper.addRoute(new RouteConfiguration("route-3-error", "error-custom", true, new RegexpRequestMatcher(PROPERTY_URI, ".*error.html.*"))); mapper.addRoute(new RouteConfiguration("route-4-static", "static-custom", true, new RegexpRequestMatcher(PROPERTY_URI, ".*static.html.*"))); - 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(); { // proxy on director 1 - String s = IOUtils.toString(new URL("http://localhost:" + port + "/index.html").toURI(), "utf-8"); + String s = IOUtils.toString(new URL("http://localhost:" + port + "/index.html").toURI(), StandardCharsets.UTF_8); assertEquals("it works !!", s); } { // cache on director 2 - String s = IOUtils.toString(new URL("http://localhost:" + port + "/index2.html").toURI(), "utf-8"); + String s = IOUtils.toString(new URL("http://localhost:" + port + "/index2.html").toURI(), StandardCharsets.UTF_8); assertEquals("it works !!", s); } { // director "all" - String s = IOUtils.toString(new URL("http://localhost:" + port + "/index3.html").toURI(), "utf-8"); + String s = IOUtils.toString(new URL("http://localhost:" + port + "/index3.html").toURI(), StandardCharsets.UTF_8); assertEquals("it works !!", s); } try { - IOUtils.toString(new URL("http://localhost:" + port + "/notfound.html").toURI(), "utf-8"); + IOUtils.toString(new URL("http://localhost:" + port + "/notfound.html").toURI(), StandardCharsets.UTF_8); fail("expected 404"); } catch (FileNotFoundException ok) { } { - String staticContent = IOUtils.toString(new URL("http://localhost:" + port + "/static.html").toURI(), "utf-8"); + String staticContent = IOUtils.toString(new URL("http://localhost:" + port + "/static.html").toURI(), StandardCharsets.UTF_8); assertEquals("Test static page", staticContent); } { - String staticContent = IOUtils.toString(new URL("http://localhost:" + port + "/static.html").toURI(), "utf-8"); + String staticContent = IOUtils.toString(new URL("http://localhost:" + port + "/static.html").toURI(), StandardCharsets.UTF_8); assertEquals("Test static page", staticContent); } try { - IOUtils.toString(new URL("http://localhost:" + port + "/error.html").toURI(), "utf-8"); + IOUtils.toString(new URL("http://localhost:" + port + "/error.html").toURI(), StandardCharsets.UTF_8); fail("expected 500"); } catch (IOException ok) { } try { - IOUtils.toString(new URL("http://localhost:" + port + "/notmapped.html").toURI(), "utf-8"); + IOUtils.toString(new URL("http://localhost:" + port + "/notmapped.html").toURI(), StandardCharsets.UTF_8); fail("expected 404"); } catch (FileNotFoundException ok) { } @@ -169,7 +170,7 @@ public void testRouteErrors() throws Exception { .withHeader("Content-Type", "text/html") .withBody("it works !!"))); - try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) { + try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder())) { Properties configuration = new Properties(); configuration.put("listener.1.host", "0.0.0.0"); @@ -179,7 +180,7 @@ public void testRouteErrors() throws Exception { configuration.put("backend.1.id", "backend"); configuration.put("backend.1.host", "localhost"); - configuration.put("backend.1.port", backend1.port() + ""); + configuration.put("backend.1.port", String.valueOf(backend1.port())); configuration.put("backend.1.enabled", "true"); configuration.put("director.1.id", "director"); @@ -189,7 +190,7 @@ public void testRouteErrors() throws Exception { // unreachable backend -> expected Internal Error configuration.put("backend.2.id", "backend-down"); configuration.put("backend.2.host", "localhost-down"); - configuration.put("backend.2.port", backend1.port() + ""); + configuration.put("backend.2.port", String.valueOf(backend1.port())); configuration.put("backend.2.enabled", "true"); configuration.put("director.2.id", "director-down"); @@ -321,23 +322,23 @@ public void testDefaultRoute() throws Exception { when(bhMan.isAvailable(eq("localhost:" + backendPort))).thenReturn(true); when(bhMan.isAvailable(eq("localhost-down:" + backendPort))).thenReturn(false); // simulate unreachable backend -> expected 500 error - try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { + try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.setBackendHealthManager(bhMan); server.start(); int port = server.getLocalPort(); // index.html matches with route { - String s = IOUtils.toString(new URL("http://localhost:" + port + "/index.html").toURI(), "utf-8"); + String s = IOUtils.toString(new URL("http://localhost:" + port + "/index.html").toURI(), StandardCharsets.UTF_8); assertEquals("it works !!", s); } // notmapped.html matches with route-default { - String s = IOUtils.toString(new URL("http://localhost:" + port + "/notmapped.html").toURI(), "utf-8"); + String s = IOUtils.toString(new URL("http://localhost:" + port + "/notmapped.html").toURI(), StandardCharsets.UTF_8); assertEquals("it works !!", s); } // down.html (request to unreachable backend) has NOT to match to route-deafult BUT get internal-error try { - IOUtils.toString(new URL("http://localhost:" + port + "/down.html").toURI(), "utf-8"); + IOUtils.toString(new URL("http://localhost:" + port + "/down.html").toURI(), StandardCharsets.UTF_8); fail("expected 500"); } catch (IOException ok) { } @@ -353,13 +354,13 @@ public void testAlwaysServeStaticContent() throws Exception { .withHeader("Content-Type", "text/html") .withBody("it works !!"))); - try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) { + try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder())) { { Properties configuration = new Properties(); configuration.put("backend.1.id", "foo"); configuration.put("backend.1.host", "localhost"); - configuration.put("backend.1.port", backend1.port() + ""); + configuration.put("backend.1.port", String.valueOf(backend1.port())); configuration.put("backend.1.enabled", "true"); configuration.put("director.1.id", "*"); @@ -404,20 +405,20 @@ public void testAlwaysServeStaticContent() throws Exception { { String url = "http://localhost:" + server.getLocalPort() + "/index.html"; - String s = IOUtils.toString(new URL(url).toURI(), "utf-8"); + String s = IOUtils.toString(new URL(url).toURI(), StandardCharsets.UTF_8); assertEquals("Test static page", s); } { String url = "http://localhost:" + server.getLocalPort() + "/seconda.html"; - String s = IOUtils.toString(new URL(url).toURI(), "utf-8"); + String s = IOUtils.toString(new URL(url).toURI(), StandardCharsets.UTF_8); assertEquals("it works !!", s); } // resource not esists > Not Found try { String url = "http://localhost:" + server.getLocalPort() + "/not-exists.html"; - String s = IOUtils.toString(new URL(url).toURI(), "utf-8"); - fail("Expected Not Found"); + String s = IOUtils.toString(new URL(url).toURI(), StandardCharsets.UTF_8); + fail("Expected Not Found, received " + s + " instead"); } catch (Exception ex) { assertTrue(ex instanceof FileNotFoundException); } @@ -436,7 +437,7 @@ public void testServeACMEChallengeToken() throws Exception { Properties configuration = new Properties(); configuration.put("backend.1.id", "foo"); configuration.put("backend.1.host", "localhost"); - configuration.put("backend.1.port", backend1.port() + ""); + configuration.put("backend.1.port", String.valueOf(backend1.port())); configuration.put("backend.1.enabled", "true"); configuration.put("director.1.id", "*"); @@ -471,13 +472,13 @@ public void testServeACMEChallengeToken() throws Exception { // Test existent token String url = "http://localhost:" + server.getLocalPort() + "/.well-known/acme-challenge/" + tokenName; - String s = IOUtils.toString(new URL(url).toURI(), "utf-8"); + String s = IOUtils.toString(new URL(url).toURI(), StandardCharsets.UTF_8); assertEquals(tokenData, s); // Test not existent token try { url = "http://localhost:" + server.getLocalPort() + "/.well-known/acme-challenge/not-existent-token"; - IOUtils.toString(new URL(url).toURI(), "utf-8"); + IOUtils.toString(new URL(url).toURI(), StandardCharsets.UTF_8); fail(); } catch (Throwable t) { assertTrue(t instanceof FileNotFoundException); @@ -510,11 +511,11 @@ public void testCustomAndDebuggingHeaders() throws Exception { Properties configuration = new Properties(); configuration.put("backend.1.id", "b1"); configuration.put("backend.1.host", "localhost"); - configuration.put("backend.1.port", backend1.port() + ""); + configuration.put("backend.1.port", String.valueOf(backend1.port())); configuration.put("backend.1.enabled", "true"); configuration.put("backend.2.id", "b2"); configuration.put("backend.2.host", "localhost"); - configuration.put("backend.2.port", backend1.port() + ""); + configuration.put("backend.2.port", String.valueOf(backend1.port())); configuration.put("backend.2.enabled", "true"); configuration.put("director.1.id", "d1"); diff --git a/pom.xml b/pom.xml index ed4857706..bce289a2c 100644 --- a/pom.xml +++ b/pom.xml @@ -108,8 +108,8 @@ 17 2.4 - 2020.0.23 - 2.0.54.Final + 2022.0.7 + 2.0.61.Final 2.12 1.70 2.17.113 @@ -120,7 +120,7 @@ 5.2.0 0.14.1 4.14.4 - 1.8.2 + 1.11.0 0.26.1 3.12.0