From 2b10e16eb5485cd45cbd5596ccd7787f77530f16 Mon Sep 17 00:00:00 2001 From: Paul Tuckey Date: Fri, 9 Jun 2023 20:36:40 +1200 Subject: [PATCH] progress --- container-test2/example-webapp/pom.xml | 2 +- .../test-with-testcontainters/pom.xml | 20 +- .../ContainerTestBase.java | 127 +++++++++++++ .../urlrewriteviacontainer/ExampleTest.java | 56 ------ .../WebappDecodeNoneIT.java | 70 +++++++ .../WebappDecodeUtf8IT.java | 59 ++++++ .../urlrewriteviacontainer/WebappHttpIT.java | 172 ++++++++++++++++++ .../WebappModStyleHttpIT.java | 82 +++++++++ 8 files changed, 528 insertions(+), 60 deletions(-) create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java delete mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java create mode 100644 container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java diff --git a/container-test2/example-webapp/pom.xml b/container-test2/example-webapp/pom.xml index 20d500b3..2d9fc1e1 100644 --- a/container-test2/example-webapp/pom.xml +++ b/container-test2/example-webapp/pom.xml @@ -28,7 +28,7 @@ - example-webapp + webapp maven-compiler-plugin diff --git a/container-test2/test-with-testcontainters/pom.xml b/container-test2/test-with-testcontainters/pom.xml index f17728ef..e2afa6bf 100644 --- a/container-test2/test-with-testcontainters/pom.xml +++ b/container-test2/test-with-testcontainters/pom.xml @@ -39,9 +39,17 @@ 5.0.0-SNAPSHOT - org.apache.httpcomponents.client5 - httpclient5 - 5.2.1 + + org.tuckey + example-webapp + 5.0.0 + test + + + commons-httpclient + commons-httpclient + 3.1 + test org.junit.jupiter @@ -71,6 +79,12 @@ slf4j-simple 1.7.5 + + jakarta.servlet + jakarta.servlet-api + 6.0.0 + test + diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java new file mode 100644 index 00000000..7ffdb3d1 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java @@ -0,0 +1,127 @@ +/** + * Copyright (c) 2005-2007, Paul Tuckey + * 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 + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - 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 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; +import org.junit.jupiter.api.BeforeEach; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Paths; + + +@Testcontainers +public abstract class ContainerTestBase { + + private int mappedPort = 0; + + protected HttpClient client = new HttpClient(); + private File systemPropBaseReportsDir = new File("container-test", "reports"); + private String containerId = "test"; + + String webappPath = Paths.get("..", "example-webapp", "target", "webapp.war") + .toAbsolutePath().toString(); + + @Container + public GenericContainer container = new GenericContainer<>("tomcat:10.1.9") + .withReuse(true) + .withExposedPorts(8080) + .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/webapp.war") + .waitingFor(Wait.forHttp("/webapp/test/test.jsp").forStatusCode(200)); + + //@BeforeEach + public void setUp() throws Exception { + container.start(); + System.out.println(container.getContainerId()); + System.out.println("PORT " + container.getFirstMappedPort()); + this.mappedPort = container.getFirstMappedPort(); + assert (container.isRunning()); + + String containerId = System.getProperty("test.container.id"); + if (containerId != null) { + this.containerId = containerId; + } +// String systemPropBaseUrl = System.getProperty("test.base.url"); +// if (systemPropBaseUrl != null) { +// baseUrl = systemPropBaseUrl; +// } + String systemPropBaseReports = System.getProperty("test.base.reports"); + if (systemPropBaseReports != null) { + systemPropBaseReportsDir = new File(systemPropBaseReports); + } + System.err.println("systemPropBaseReportsDir: " + systemPropBaseReportsDir); + + GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status/?conf=/WEB-INF/" + getConf()); + client.executeMethod(method); + } + + protected String getBaseUrl() { + return "http://localhost:" + this.mappedPort + "/" + getApp(); + } + + protected void recordRewriteStatus() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/" + getApp() + "/rewrite-status"); + method.setFollowRedirects(false); + client.executeMethod(method); + File statusFile = new File(containerId + "-" + getApp() + "-" + getConf() + "-rewrite-status.html"); + if (statusFile.exists() && !statusFile.delete()) { + System.out.println("could not remove status at " + statusFile.getAbsolutePath()); + } else + if (!statusFile.createNewFile()) { // some containers don't let us do this + System.out.println("could not create status at " + statusFile.getAbsolutePath()); + } else { + PrintWriter pw = new PrintWriter(statusFile); + pw.print(method.getResponseBodyAsString()); + pw.close(); + System.out.println("status saved to " + statusFile.getAbsolutePath()); + } + } + + abstract protected String getApp(); + + protected String getConf() { + return "urlrewrite.xml"; + } + + public String getContainerId() { + return containerId; + } +} diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java deleted file mode 100644 index c81325cf..00000000 --- a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.tuckey.web.filters.urlrewriteviacontainer; - -import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.HttpClients; -import org.apache.hc.core5.http.ClassicHttpRequest; -import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; - - -import java.io.IOException; -import java.nio.file.Paths; - - -@Testcontainers -public class ExampleTest { - - String webappPath = Paths.get("..", "example-webapp", "target", "example-webapp.war") - .toAbsolutePath().toString(); - - @Container - public GenericContainer container = new GenericContainer<>("tomcat:10.1.9") - .withReuse(true) - .withExposedPorts(8080) - .withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/example-webapp.war") - .waitingFor(Wait.forHttp("/example-webapp/test/test.jsp").forStatusCode(200)); - - @BeforeEach - public void setUp() { - System.out.println("War: " + webappPath); - } - - @Test - public void checkContainerIsRunning() { - System.out.println(container.getContainerId()); - assert (container.isRunning()); - } - - @Test - public void testSimplePutAndGet() throws IOException { - System.out.println("Container ID" + container.getContainerId()); - - try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - ClassicHttpRequest httpGet = ClassicRequestBuilder.get("http://localhost:8080/example-webapp/test/test.jsp") - .build(); - httpClient.execute(httpGet, response -> { - System.out.println(response.getCode() + " " + response.getReasonPhrase()); - return null; - }); - } - } -} \ No newline at end of file diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java new file mode 100644 index 00000000..e6652294 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java @@ -0,0 +1,70 @@ +package org.tuckey.web.filters.urlrewriteviacontainer; + + +import org.apache.commons.httpclient.methods.GetMethod; + +import jakarta.servlet.ServletException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; + + +import java.io.IOException; +import java.net.URLEncoder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * + */ +public class WebappDecodeNoneIT extends ContainerTestBase { + + protected String getApp() { + return "webapp"; + } + + protected String getConf() { + return "urlrewrite-decode-none.xml"; + } + + @BeforeEach + public void testSetup() throws Exception { + super.setUp(); + super.recordRewriteStatus(); + } + + /** + * note, had trouble keeping true utf (multi byte) chars as cvs buggers them up! + */ + @Test + public void testTestUtf() throws ServletException, IOException { + if ( "orion2.0.5".equals(getContainerId())) return; // orion not supported + String encodedStr = URLEncoder.encode("m\u0101ori", "UTF8"); + GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + encodedStr + "/"); + method.setRequestHeader("Accept-Encoding", "utf8"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertNotNull("no location header", method.getResponseHeader("Location")); + assertEquals(getBaseUrl() + "/utf-redir/done/" + encodedStr + "/", method.getResponseHeader("Location").getValue()); + } + + 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()); + } + + public void testQueryStringNoDecode() throws IOException { + if ( "orion2.0.5".equals(getContainerId())) return; // orion cannot correctly encode & into %26 + + GetMethod method = new GetMethod(getBaseUrl() + "/query-string-no-decode/jack+%26+jones"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals("http://query-string-no-decode-result.com/?q=jack+%26+jones&another=jack & jones", method.getResponseHeader("Location").getValue()); + } + + +} \ No newline at end of file diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java new file mode 100644 index 00000000..555d3d33 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java @@ -0,0 +1,59 @@ +package org.tuckey.web.filters.urlrewriteviacontainer; + + +import org.apache.commons.httpclient.methods.GetMethod; + +import jakarta.servlet.ServletException; +import java.io.IOException; +import java.net.URLEncoder; + +import static org.junit.Assert.assertEquals; + +/** + * todo: need to do a few tests + *

+ * with eocode-using not set (ie, browser encoding used, step down to utf8) + * with eocode-using set to utf (force always with a specific decoding) + * with eocode-using not set to null (never decode) + * accept-encoding header? + *

+ *

+ * don't decode anything - null + * browser then utf then default - default browser,utf + * browser then don't decode - default browser,null + * always utf - utf + *

+ *

+ * options: browser (may fail), enc (unlikely fail) + */ +public class WebappDecodeUtf8IT extends ContainerTestBase { + + protected String getApp() { + return "webapp"; + } + + protected String getConf() { + return "urlrewrite-decode-utf8.xml"; + } + + public void testSetup() throws IOException { + super.recordRewriteStatus(); + } + + + /** + * + */ + public void testTestUtf() throws ServletException, IOException { + String utfSampleString = "m\u0101ori"; + GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + URLEncoder.encode(utfSampleString, "UTF8") + "/"); + method.setRequestHeader("Accept-Encoding", "utf8"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals(getBaseUrl() + "/utf-redir/done/", method.getResponseHeader("Location").getValue()); + } + + + + +} diff --git a/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java new file mode 100644 index 00000000..58df2c30 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappHttpIT.java @@ -0,0 +1,172 @@ +/** + * Copyright (c) 2005-2007, Paul Tuckey + * 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 + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - 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 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.methods.GetMethod; +import org.tuckey.web.filters.urlrewrite.utils.StringUtils; +import org.xml.sax.SAXException; + +import jakarta.servlet.ServletException; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.GZIPInputStream; + +import static org.junit.Assert.*; + + +/** + * @author Paul Tuckey + * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ + */ +public class WebappHttpIT extends ContainerTestBase { + + protected String getApp() { + return "webapp"; + } + + public void testStatusRecord() throws IOException { + super.recordRewriteStatus(); + } + + public void testProduct() throws IOException, SAXException, InterruptedException { + GetMethod method = new GetMethod(getBaseUrl() + "/products/987"); + client.executeMethod(method); + assertEquals("product 987", method.getResponseBodyAsString()); + } + + + public void testSimpleDistEx() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/test/status/"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals(getBaseUrl() + "/rewrite-status", method.getResponseHeader("Location").getValue()); + } + + public void testBasicSets() throws ServletException, IOException, SAXException { + 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()); + } + + public void testMultipleProduct() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/multiple/products/987"); + client.executeMethod(method); + assertEquals("product 987", method.getResponseBodyAsString()); + } + + public void testNullTo() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/hideme/anb.jsp;dsaddd?asdasds#sdsfd"); + client.executeMethod(method); + assertEquals("should have status set", 403, method.getStatusCode()); + String CONTENT = "

some content

"; + assertFalse("should not output above content", CONTENT.equals(StringUtils.trim(method.getResponseBodyAsString()))); + } + + public void testYear() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/time/year/current"); + client.executeMethod(method); + assertEquals("echo yearisbetween1970and3000", method.getResponseBodyAsString()); + } + + public void testTestAxis() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/services/blah?qwerty"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals(getBaseUrl() + "/axis/services/blah", method.getResponseHeader("Location").getValue()); + } + + public void testTestErik() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/eriktest/hi.ho"); + method.setFollowRedirects(false); + method.addRequestHeader(new Header("host", "blah.com")); + client.executeMethod(method); + assertEquals("http://www.example.com/context/hi.ho", method.getResponseHeader("Location").getValue()); + } + + public void testTestEncode() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/went%20to%20bahamas/"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals(getBaseUrl() + "/jamaica/", method.getResponseHeader("Location").getValue()); + } + + public void testSimpleRun() throws ServletException, IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/run/test/test1"); + client.executeMethod(method); + assertEquals("this is " + TestRunObj.class.getName(), method.getResponseBodyAsString()); + } + + public void testQueryStringEscape() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/query-string-escape/jack+%26+jones"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals("http://query-string-escape-result.com/?q=jack%2B%26%2Bjones&another=jack+&+jones", method.getResponseHeader("Location").getValue()); + } + + public void testGzip() throws IOException { + GetMethod method = new GetMethod(getBaseUrl() + "/gzip-me.jsp"); + method.addRequestHeader("accept-encoding", "gzip"); + client.executeMethod(method); + assertEquals("gzip", method.getResponseHeader("Content-Encoding").getValue()); + assertEquals("hello world hello world hello world", inflateGzipToString(method.getResponseBodyAsStream())); + } + + /** + * inflate a gzipped inputstream and return it as a string. + */ + private String inflateGzipToString(InputStream is) throws IOException { + GZIPInputStream gis = new GZIPInputStream(is); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + while (true) { + int bytesRead = gis.read(buffer); + if (bytesRead == -1) break; + os.write(buffer, 0, bytesRead); + } + return os.toString(); + } + + 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-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java new file mode 100644 index 00000000..7d6ea9a3 --- /dev/null +++ b/container-test2/test-with-testcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappModStyleHttpIT.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2005-2007, Paul Tuckey + * 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 + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * - 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 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ +package org.tuckey.web.filters.urlrewriteviacontainer; + +import org.apache.commons.httpclient.methods.GetMethod; +import org.xml.sax.SAXException; + +import jakarta.servlet.ServletException; +import java.io.IOException; + +import static org.junit.Assert.*; + + +/** + * @author Paul Tuckey + * @version $Revision: 33 $ $Date: 2006-09-12 16:41:56 +1200 (Tue, 12 Sep 2006) $ + */ +public class WebappModStyleHttpIT extends ContainerTestBase { + + protected String getApp() { + return "webapp/mod"; + } + + public void testStatusRecord() throws IOException { + super.recordRewriteStatus(); + } + + public void testSimpleTest() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/index.jsp"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals("this is index.jsp", method.getResponseBodyAsString()); + } + + public void testSimpleTestRewrite() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/simple/test"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertEquals("this is index.jsp", method.getResponseBodyAsString()); + } + + public void testStatus1() throws ServletException, IOException, SAXException { + GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status"); + method.setFollowRedirects(false); + client.executeMethod(method); + assertTrue(method.getResponseBodyAsString().contains("Running Status")); + assertFalse(method.getResponseBodyAsString().contains("Error")); + } + +}