use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestStandardWrapper method testSecurityAnnotationsNoWebXmlConstraints.
@Test
public void testSecurityAnnotationsNoWebXmlConstraints() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-servletsecurity");
tomcat.addWebapp(null, "", appDir.getAbsolutePath());
tomcat.start();
ByteChunk bc = new ByteChunk();
int rc;
rc = getUrl("http://localhost:" + getPort() + "/", bc, null, null);
assertTrue(bc.getLength() > 0);
assertEquals(403, rc);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestStandardWrapper method testSecurityAnnotationsMetaDataPriority.
@Test
public void testSecurityAnnotationsMetaDataPriority() throws Exception {
getTomcatInstanceTestWebapp(false, true);
ByteChunk bc = new ByteChunk();
int rc;
rc = getUrl("http://localhost:" + getPort() + "/test/testStandardWrapper/securityAnnotationsMetaDataPriority", bc, null, null);
assertEquals("OK", bc.toString());
assertEquals(200, rc);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestStandardContext method testWebappLoaderStartFail.
@Test
public void testWebappLoaderStartFail() throws Exception {
// Test that if WebappLoader start() fails and if the cause of
// the failure is gone, the context can be started without
// a need to redeploy it.
// Set up a container
Tomcat tomcat = getTomcatInstance();
tomcat.start();
// To not start Context automatically, as we have to configure it first
((ContainerBase) tomcat.getHost()).setStartChildren(false);
FailingWebappLoader loader = new FailingWebappLoader();
File root = new File("test/webapp");
Context context = tomcat.addWebapp("", root.getAbsolutePath());
context.setLoader(loader);
try {
context.start();
fail();
} catch (LifecycleException ex) {
// As expected
}
assertEquals(LifecycleState.FAILED, context.getState());
// The second attempt
loader.setFail(false);
context.start();
assertEquals(LifecycleState.STARTED, context.getState());
// Using a test from testBug49922() to check that the webapp is running
ByteChunk result = getUrl("http://localhost:" + getPort() + "/bug49922/target");
assertEquals("Target", result.toString());
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestStandardContext method testBug49922.
@Test
public void testBug49922() throws Exception {
// Test that filter mapping works. Test that the same filter is
// called only once, even if is selected by several mapping
// url-patterns or by both a url-pattern and a servlet-name.
getTomcatInstanceTestWebapp(false, true);
ByteChunk result = new ByteChunk();
// Check filter and servlet aren't called
int rc = getUrl("http://localhost:" + getPort() + "/test/bug49922/foo", result, null);
assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
assertTrue(result.getLength() > 0);
// Check extension mapping works
result = getUrl("http://localhost:" + getPort() + "/test/foo.do");
assertEquals("FilterServlet", result.toString());
// Check path mapping works
result = getUrl("http://localhost:" + getPort() + "/test/bug49922/servlet");
assertEquals("FilterServlet", result.toString());
// Check servlet name mapping works
result = getUrl("http://localhost:" + getPort() + "/test/foo.od");
assertEquals("FilterServlet", result.toString());
// Check filter is only called once
result = getUrl("http://localhost:" + getPort() + "/test/bug49922/servlet/foo.do");
assertEquals("FilterServlet", result.toString());
result = getUrl("http://localhost:" + getPort() + "/test/bug49922/servlet/foo.od");
assertEquals("FilterServlet", result.toString());
// Check dispatcher mapping
result = getUrl("http://localhost:" + getPort() + "/test/bug49922/target");
assertEquals("Target", result.toString());
result = getUrl("http://localhost:" + getPort() + "/test/bug49922/forward");
assertEquals("FilterTarget", result.toString());
result = getUrl("http://localhost:" + getPort() + "/test/bug49922/include");
assertEquals("IncludeFilterTarget", result.toString());
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestStandardContext method testWebappListenerConfigureFail.
@Test
public void testWebappListenerConfigureFail() throws Exception {
// Test that if LifecycleListener on webapp fails during
// configure_start event and if the cause of the failure is gone,
// the context can be started without a need to redeploy it.
// Set up a container
Tomcat tomcat = getTomcatInstance();
tomcat.start();
// To not start Context automatically, as we have to configure it first
((ContainerBase) tomcat.getHost()).setStartChildren(false);
FailingLifecycleListener listener = new FailingLifecycleListener();
File root = new File("test/webapp");
Context context = tomcat.addWebapp("", root.getAbsolutePath());
context.addLifecycleListener(listener);
try {
context.start();
fail();
} catch (LifecycleException ex) {
// As expected
}
assertEquals(LifecycleState.FAILED, context.getState());
// The second attempt
listener.setFail(false);
context.start();
assertEquals(LifecycleState.STARTED, context.getState());
// Using a test from testBug49922() to check that the webapp is running
ByteChunk result = getUrl("http://localhost:" + getPort() + "/bug49922/target");
assertEquals("Target", result.toString());
}
Aggregations