use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestRewriteValve method doTestRewrite.
private void doTestRewrite(String config, String request, String expectedURI, String expectedQueryString, String expectedAttributeValue) throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
RewriteValve rewriteValve = new RewriteValve();
ctx.getPipeline().addValve(rewriteValve);
rewriteValve.setConfiguration(config);
Tomcat.addServlet(ctx, "snoop", new SnoopServlet());
ctx.addServletMappingDecoded("/a/%5A", "snoop");
ctx.addServletMappingDecoded("/c/*", "snoop");
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
tomcat.start();
ByteChunk res = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + request, res, null);
res.setCharset(StandardCharsets.UTF_8);
if (expectedURI == null) {
// Rewrite is expected to fail. Probably because invalid characters
// were written into the request target
Assert.assertEquals(400, rc);
} else {
String body = res.toString();
RequestDescriptor requestDesc = SnoopResult.parse(body);
String requestURI = requestDesc.getRequestInfo("REQUEST-URI");
Assert.assertEquals(expectedURI, requestURI);
if (expectedQueryString != null) {
String queryString = requestDesc.getRequestInfo("REQUEST-QUERY-STRING");
Assert.assertEquals(expectedQueryString, queryString);
}
if (expectedAttributeValue != null) {
String attributeValue = requestDesc.getAttribute("X-Test");
Assert.assertEquals(expectedAttributeValue, attributeValue);
}
}
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestFileResource method testGetCodePath.
@Test
public void testGetCodePath() throws Exception {
getTomcatInstanceTestWebapp(false, true);
ByteChunk out = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug58096.jsp", out, null);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
// Build the expected location the same way the webapp base dir is built
File f = new File("test/webapp/WEB-INF/classes");
Assert.assertEquals(f.toURI().toURL().toString(), out.toString().trim());
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestValidator method testTldVersions31.
@Test
public void testTldVersions31() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.1");
// app dir is relative to server home
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/tld-versions.jsp");
String result = res.toString();
assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>02-hello world</p>") > 0);
assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>04-hello world</p>") > 0);
assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>06-hello world</p>") > 0);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestValidator method testTldVersions30.
@Test
public void testTldVersions30() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0");
// app dir is relative to server home
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/tld-versions.jsp");
String result = res.toString();
assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>02-hello world</p>") > 0);
assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>04-hello world</p>") > 0);
assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>06-hello world</p>") > 0);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestValidator method testTldVersions22.
@Test
public void testTldVersions22() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-2.2");
// app dir is relative to server home
tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/tld-versions.jsp");
String result = res.toString();
assertTrue(result.indexOf("<p>${'00-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>${'02-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>${'04-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0);
assertTrue(result.indexOf("<p>${'06-hello world'}</p>") > 0);
}
Aggregations