Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
paultuckey committed Jun 9, 2023
1 parent 2b10e16 commit 7eabfb3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2005-2007, Paul Tuckey
* Copyright (c) 2005-2023, Paul Tuckey
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
Expand Down Expand Up @@ -36,7 +36,6 @@

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;
Expand Down Expand Up @@ -67,7 +66,6 @@ public abstract class ContainerTestBase {
.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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.io.IOException;
import java.net.URLEncoder;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
*
Expand All @@ -28,7 +28,7 @@ protected String getConf() {
}

@BeforeEach
public void testSetup() throws Exception {
public void beforeEach() throws Exception {
super.setUp();
super.recordRewriteStatus();
}
Expand All @@ -44,10 +44,11 @@ public void testTestUtf() throws ServletException, IOException {
method.setRequestHeader("Accept-Encoding", "utf8");
method.setFollowRedirects(false);
client.executeMethod(method);
assertNotNull("no location header", method.getResponseHeader("Location"));
assertNotNull(method.getResponseHeader("Location"), "no location header");
assertEquals(getBaseUrl() + "/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
Expand All @@ -57,6 +58,7 @@ public void testNoDecode() throws IOException {
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import org.apache.commons.httpclient.methods.GetMethod;

import jakarta.servlet.ServletException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URLEncoder;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;


/**
* todo: need to do a few tests
Expand Down Expand Up @@ -36,14 +40,16 @@ protected String getConf() {
return "urlrewrite-decode-utf8.xml";
}

public void testSetup() throws IOException {
@BeforeEach
public void beforeEach() throws Exception {
super.setUp();
super.recordRewriteStatus();
}


/**
*
*/
@Test
public void testTestUtf() throws ServletException, IOException {
String utfSampleString = "m\u0101ori";
GetMethod method = new GetMethod(getBaseUrl() + "/utf/" + URLEncoder.encode(utfSampleString, "UTF8") + "/");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2005-2007, Paul Tuckey
* Copyright (c) 2005-2023, Paul Tuckey
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
Expand Down Expand Up @@ -34,18 +34,22 @@
*/
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.BeforeEach;
import org.junit.jupiter.api.Test;
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.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertFalse;


/**
Expand All @@ -58,24 +62,29 @@ protected String getApp() {
return "webapp";
}

public void testStatusRecord() throws IOException {
@BeforeEach
public void beforeEach() throws Exception {
super.setUp();
super.recordRewriteStatus();
}

@Test
public void testProduct() throws IOException, SAXException, InterruptedException {
GetMethod method = new GetMethod(getBaseUrl() + "/products/987");
client.executeMethod(method);
assertEquals("product 987", method.getResponseBodyAsString());
}


@Test
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());
}

@Test
public void testBasicSets() throws ServletException, IOException, SAXException {
GetMethod method = new GetMethod(getBaseUrl() + "/settest/674");
client.executeMethod(method);
Expand All @@ -85,33 +94,38 @@ public void testBasicSets() throws ServletException, IOException, SAXException {
"method: DELETE", method.getResponseBodyAsString());
}

@Test
public void testMultipleProduct() throws ServletException, IOException, SAXException {
GetMethod method = new GetMethod(getBaseUrl() + "/multiple/products/987");
client.executeMethod(method);
assertEquals("product 987", method.getResponseBodyAsString());
}

@Test
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());
assertEquals(403, method.getStatusCode()); // "should have status set",
String CONTENT = "<p>some content</p>";
assertFalse("should not output above content", CONTENT.equals(StringUtils.trim(method.getResponseBodyAsString())));
assertFalse(CONTENT.equals(StringUtils.trim(method.getResponseBodyAsString()))); // "should not output above content"
}

@Test
public void testYear() throws ServletException, IOException {
GetMethod method = new GetMethod(getBaseUrl() + "/time/year/current");
client.executeMethod(method);
assertEquals("echo yearisbetween1970and3000", method.getResponseBodyAsString());
}

@Test
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());
assertEquals("/" + getApp() + "/axis/services/blah", method.getResponseHeader("Location").getValue());
}

@Test
public void testTestErik() throws ServletException, IOException {
GetMethod method = new GetMethod(getBaseUrl() + "/eriktest/hi.ho");
method.setFollowRedirects(false);
Expand All @@ -120,26 +134,30 @@ public void testTestErik() throws ServletException, IOException {
assertEquals("http://www.example.com/context/hi.ho", method.getResponseHeader("Location").getValue());
}

@Test
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());
}

@Test
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());
}

@Test
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());
}

@Test
public void testGzip() throws IOException {
GetMethod method = new GetMethod(getBaseUrl() + "/gzip-me.jsp");
method.addRequestHeader("accept-encoding", "gzip");
Expand All @@ -163,6 +181,7 @@ 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2005-2007, Paul Tuckey
* Copyright (c) 2005-2023, Paul Tuckey
* All rights reserved.
* ====================================================================
* Licensed under the BSD License. Text as follows.
Expand Down Expand Up @@ -35,13 +35,14 @@
package org.tuckey.web.filters.urlrewriteviacontainer;

import org.apache.commons.httpclient.methods.GetMethod;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import jakarta.servlet.ServletException;
import java.io.IOException;

import static org.junit.Assert.*;

import static org.junit.jupiter.api.Assertions.*;

/**
* @author Paul Tuckey
Expand All @@ -53,24 +54,29 @@ protected String getApp() {
return "webapp/mod";
}

public void testStatusRecord() throws IOException {
@BeforeEach
public void beforeEach() throws Exception {
super.setUp();
super.recordRewriteStatus();
}

@Test
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());
}

@Test
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());
}

@Test
public void testStatus1() throws ServletException, IOException, SAXException {
GetMethod method = new GetMethod(getBaseUrl() + "/rewrite-status");
method.setFollowRedirects(false);
Expand Down

0 comments on commit 7eabfb3

Please sign in to comment.