diff --git a/container-test/example-webapp/pom.xml b/container-test/example-webapp/pom.xml index 24455639..348233d9 100644 --- a/container-test/example-webapp/pom.xml +++ b/container-test/example-webapp/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.tuckey example-webapp - jar + war 5.0.0-SNAPSHOT Example Webapp http://www.tuckey.org/urlrewrite/ diff --git a/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml index dfcff1da..782e6fe3 100644 --- a/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml +++ b/container-test/example-webapp/src/main/webapp/WEB-INF/urlrewrite.xml @@ -46,7 +46,6 @@ hello! none-fool $1 - DELETE /settest.jsp @@ -62,7 +61,7 @@ 1970 - 2020 + 2045 /time/year/current /echo.jsp?echo=yearisbetween1970and3000 diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java index b2f38d09..c0b7b688 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java @@ -37,7 +37,8 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.containers.output.OutputFrame; +import org.testcontainers.containers.output.ToStringConsumer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; @@ -45,6 +46,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Paths; +import java.time.Duration; @Testcontainers @@ -63,9 +65,14 @@ public abstract class ContainerTestBase { .withExposedPorts(8080) .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/webapp.war"); + ToStringConsumer toStringConsumer = new ToStringConsumer(); public void setUp() throws Exception { container.start(); + + container.followOutput(toStringConsumer, OutputFrame.OutputType.STDOUT); + container.followOutput(toStringConsumer, OutputFrame.OutputType.STDERR); + System.out.println(container.getContainerId()); System.out.println("HOST " + container.getHost()); System.out.println("PORT " + container.getFirstMappedPort()); @@ -90,12 +97,19 @@ public void setUp() throws Exception { client.executeMethod(method); } + public void tearDown() throws InterruptedException { + Thread.sleep(1); + // useful for debugging + //Thread.sleep(5 * 60 * 1000); + // go to tomcat container then files /usr/local/tomcat/logs + } + protected String getBaseUrl() { return "http://" + container.getHost() + ":" + container.getFirstMappedPort() + "/" + getApp(); } protected void recordRewriteStatus() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/" + getApp() + "/rewrite-status"); + GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status"); method.setFollowRedirects(false); client.executeMethod(method); File statusFile = new File(containerId + "-" + getApp() + "-" + getConf() + "-rewrite-status.html"); diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java index 86bfbed8..dde69967 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneITTest.java @@ -48,16 +48,6 @@ public void testTestUtf() throws ServletException, IOException { assertEquals("/" + getApp() + "/utf-redir/done/" + encodedStr + "/", method.getResponseHeader("Location").getValue()); } - @Test - public void testNoDecode() throws IOException { - if ( "orion2.0.5".equals(getContainerId())) return; // jsp's with % in path not supported - if ( "tomcat-4.1.31".equals(getContainerId())) return; // jsp's with % in path not supported - - GetMethod method = new GetMethod(getBaseUrl() + "/no-decode-test/D%25%2cD"); - client.executeMethod(method); - assertEquals("this is no-decode-test target jsp", method.getResponseBodyAsString()); - } - @Test public void testQueryStringNoDecode() throws IOException { if ( "orion2.0.5".equals(getContainerId())) return; // orion cannot correctly encode & into %26 diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java index f720c420..601bb5ab 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8ITTest.java @@ -56,10 +56,8 @@ public void testTestUtf() throws ServletException, IOException { method.setRequestHeader("Accept-Encoding", "utf8"); method.setFollowRedirects(false); client.executeMethod(method); - assertEquals(getBaseUrl() + "/utf-redir/done/", method.getResponseHeader("Location").getValue()); + assertEquals("/" + getApp() + "/utf-redir/done/", method.getResponseHeader("Location").getValue()); } - - } diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java index 201c7dd1..0e9cc12e 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpITTest.java @@ -3,11 +3,11 @@ * All rights reserved. * ==================================================================== * Licensed under the BSD License. Text as follows. - * + *

* Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + *

* - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above @@ -17,7 +17,7 @@ * - Neither the name tuckey.org nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. - * + *

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -34,13 +34,12 @@ */ package org.tuckey.web.filters.urlrewriteviacontainer; -import jakarta.servlet.ServletException; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.methods.GetMethod; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.tuckey.web.filters.urlrewrite.utils.StringUtils; -import org.xml.sax.SAXException; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -68,8 +67,13 @@ public void beforeEach() throws Exception { super.recordRewriteStatus(); } + @AfterEach + public void afterEach() throws InterruptedException { + super.tearDown(); + } + @Test - public void testProduct() throws IOException, SAXException, InterruptedException { + public void testProduct() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/products/987"); client.executeMethod(method); assertEquals("product 987", method.getResponseBodyAsString()); @@ -77,32 +81,32 @@ public void testProduct() throws IOException, SAXException, InterruptedException @Test - public void testSimpleDistEx() throws ServletException, IOException, SAXException { + public void testSimpleDistEx() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/test/status/"); method.setFollowRedirects(false); client.executeMethod(method); - assertEquals(getBaseUrl() + "/rewrite-status", method.getResponseHeader("Location").getValue()); + assertEquals("/" + getApp() + "/rewrite-status", method.getResponseHeader("Location").getValue()); } @Test - public void testBasicSets() throws ServletException, IOException, SAXException { + public void testBasicSets() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/settest/674"); client.executeMethod(method); assertNotNull(method.getResponseHeader("cache-control")); assertEquals("testsession: hello!, " + "param.settest1: 674, " + - "method: DELETE", method.getResponseBodyAsString()); + "method: GET", method.getResponseBodyAsString()); } @Test - public void testMultipleProduct() throws ServletException, IOException, SAXException { + public void testMultipleProduct() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/multiple/products/987"); client.executeMethod(method); assertEquals("product 987", method.getResponseBodyAsString()); } @Test - public void testNullTo() throws ServletException, IOException { + public void testNullTo() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/hideme/anb.jsp;dsaddd?asdasds#sdsfd"); client.executeMethod(method); assertEquals(403, method.getStatusCode()); // "should have status set", @@ -111,14 +115,14 @@ public void testNullTo() throws ServletException, IOException { } @Test - public void testYear() throws ServletException, IOException { + public void testYear() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/time/year/current"); client.executeMethod(method); assertEquals("echo yearisbetween1970and3000", method.getResponseBodyAsString()); } @Test - public void testTestAxis() throws ServletException, IOException { + public void testTestAxis() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/services/blah?qwerty"); method.setFollowRedirects(false); client.executeMethod(method); @@ -126,7 +130,7 @@ public void testTestAxis() throws ServletException, IOException { } @Test - public void testTestErik() throws ServletException, IOException { + public void testTestErik() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/eriktest/hi.ho"); method.setFollowRedirects(false); method.addRequestHeader(new Header("host", "blah.com")); @@ -135,15 +139,15 @@ public void testTestErik() throws ServletException, IOException { } @Test - public void testTestEncode() throws ServletException, IOException { + public void testTestEncode() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/went%20to%20bahamas/"); method.setFollowRedirects(false); client.executeMethod(method); - assertEquals(getBaseUrl() + "/jamaica/", method.getResponseHeader("Location").getValue()); + assertEquals("/" + getApp() + "/jamaica/", method.getResponseHeader("Location").getValue()); } @Test - public void testSimpleRun() throws ServletException, IOException { + public void testSimpleRun() throws IOException { GetMethod method = new GetMethod(getBaseUrl() + "/run/test/test1"); client.executeMethod(method); assertEquals("this is " + TestRunObj.class.getName(), method.getResponseBodyAsString()); @@ -181,11 +185,4 @@ private String inflateGzipToString(InputStream is) throws IOException { return os.toString(); } - @Test - public void testSampleAnnotation() throws IOException { - GetMethod method = new GetMethod(getBaseUrl() + "/do-something/7"); - client.executeMethod(method); - assertEquals(method.getResponseBodyAsString(), "AnnotatedClassSample id=7"); - } - } diff --git a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java index 1c44bb29..c6a512aa 100644 --- a/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java +++ b/container-test/test-with-testcontainers/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpITTest.java @@ -35,6 +35,7 @@ package org.tuckey.web.filters.urlrewriteviacontainer; import org.apache.commons.httpclient.methods.GetMethod; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; @@ -51,7 +52,7 @@ public class WebappModStyleHttpITTest extends ContainerTestBase { protected String getApp() { - return "webapp/mod"; + return "webapp"; } @BeforeEach @@ -60,25 +61,30 @@ public void beforeEach() throws Exception { super.recordRewriteStatus(); } + @AfterEach + public void afterEach() throws InterruptedException { + super.tearDown(); + } + @Test - public void testSimpleTest() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/index.jsp"); + public void testSimpleTest() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/mod/index.jsp"); method.setFollowRedirects(false); client.executeMethod(method); assertEquals("this is index.jsp", method.getResponseBodyAsString()); } @Test - public void testSimpleTestRewrite() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/simple/test"); + public void testSimpleTestRewrite() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/mod/simple/test"); method.setFollowRedirects(false); client.executeMethod(method); assertEquals("this is index.jsp", method.getResponseBodyAsString()); } @Test - public void testStatus1() throws ServletException, IOException, SAXException { - GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status"); + public void testStatus1() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/mod/rewrite-status"); method.setFollowRedirects(false); client.executeMethod(method); assertTrue(method.getResponseBodyAsString().contains("Running Status"));