-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a1d92f
commit 2b10e16
Showing
8 changed files
with
528 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...inters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ContainerTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/** | ||
* Copyright (c) 2005-2007, Paul Tuckey | ||
* All rights reserved. | ||
* ==================================================================== | ||
* Licensed under the BSD License. Text as follows. | ||
* <p> | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* <p> | ||
* - 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. | ||
* <p> | ||
* 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; | ||
} | ||
} |
56 changes: 0 additions & 56 deletions
56
...tcontainters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/ExampleTest.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...nters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeNoneIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...nters/src/test/java/org/tuckey/web/filters/urlrewriteviacontainer/WebappDecodeUtf8IT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
* <p/> | ||
* 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? | ||
* <p/> | ||
* <p/> | ||
* don't decode anything - null | ||
* browser then utf then default - default browser,utf | ||
* browser then don't decode - default browser,null | ||
* always utf - utf | ||
* <p/> | ||
* <p/> | ||
* 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()); | ||
} | ||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.