Search in sources :

Example 11 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestResponse method doTestEncodeRedirectURL.

private void doTestEncodeRedirectURL(String location, String expected) {
    Request req = new TesterRequest(true);
    req.setRequestedSessionId("1234");
    req.setRequestedSessionURL(true);
    Response resp = new Response();
    resp.setRequest(req);
    String result = resp.encodeRedirectURL(location);
    Assert.assertEquals(expected, result);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) TesterRequest(org.apache.tomcat.unittest.TesterRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) TesterRequest(org.apache.tomcat.unittest.TesterRequest)

Example 12 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestResponse method testBug53062n.

@Test
public void testBug53062n() throws Exception {
    Request req = new TesterRequest();
    Response resp = new Response();
    resp.setRequest(req);
    String result = resp.toAbsolute("./.#/../../");
    Assert.assertEquals("http://localhost:8080/level1/level2/#/../../", result);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) TesterRequest(org.apache.tomcat.unittest.TesterRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) TesterRequest(org.apache.tomcat.unittest.TesterRequest) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 13 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestResponse method testBug53469a.

@Test
public void testBug53469a() throws Exception {
    Request req = new TesterRequest();
    Response resp = new Response();
    resp.setRequest(req);
    String result = resp.encodeURL("../bar.html");
    Assert.assertEquals("../bar.html", result);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) TesterRequest(org.apache.tomcat.unittest.TesterRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) TesterRequest(org.apache.tomcat.unittest.TesterRequest) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 14 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestResponse method testBug53062e.

@Test(expected = IllegalArgumentException.class)
public void testBug53062e() throws Exception {
    Request req = new TesterRequest();
    Response resp = new Response();
    resp.setRequest(req);
    resp.toAbsolute("../../..");
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) TesterRequest(org.apache.tomcat.unittest.TesterRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) TesterRequest(org.apache.tomcat.unittest.TesterRequest) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 15 with TesterRequest

use of org.apache.tomcat.unittest.TesterRequest in project tomcat by apache.

the class TestResponsePerformance method testToAbsolutePerformance.

@Test
public void testToAbsolutePerformance() throws Exception {
    Request req = new TesterRequest();
    Response resp = new Response();
    resp.setRequest(req);
    // Warm up
    doHomebrew(resp);
    doUri();
    // Note: Java 9 on my OSX laptop consistently shows doUri() is faster
    //       than doHomebrew(). Worth a closer look for Tomcat 10 on the
    //       assumption it will require java 9
    // To allow for timing differences between runs, a "best of n" approach
    // is taken for this test
    final int bestOf = 5;
    final int winTarget = (bestOf + 1) / 2;
    int homebrewWin = 0;
    int count = 0;
    while (count < bestOf && homebrewWin < winTarget) {
        long homebrew = doHomebrew(resp);
        long uri = doUri();
        log.info("Current 'home-brew': " + homebrew + "ms, Using URI: " + uri + "ms");
        if (homebrew < uri) {
            homebrewWin++;
        }
        count++;
    }
    Assert.assertTrue(homebrewWin == winTarget);
}
Also used : TesterRequest(org.apache.tomcat.unittest.TesterRequest) TesterRequest(org.apache.tomcat.unittest.TesterRequest) Test(org.junit.Test) LoggingBaseTest(org.apache.catalina.startup.LoggingBaseTest)

Aggregations

TesterRequest (org.apache.tomcat.unittest.TesterRequest)26 Test (org.junit.Test)24 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)20 Locale (java.util.Locale)2 TesterContext (org.apache.tomcat.unittest.TesterContext)2 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ServletSecurityElement (javax.servlet.ServletSecurityElement)1 ServletSecurity (javax.servlet.annotation.ServletSecurity)1 Context (org.apache.catalina.Context)1 Request (org.apache.catalina.connector.Request)1 Response (org.apache.catalina.connector.Response)1 LoggingBaseTest (org.apache.catalina.startup.LoggingBaseTest)1 TesterMapRealm (org.apache.catalina.startup.TesterMapRealm)1 TesterResponse (org.apache.tomcat.unittest.TesterResponse)1 TesterServletContext (org.apache.tomcat.unittest.TesterServletContext)1 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)1