Search in sources :

Example 1 with TesterLogValidationFilter

use of org.apache.tomcat.unittest.TesterLogValidationFilter in project tomcat70 by apache.

the class TestSSLValve method testClientCertProviderNotFound.

@Test
public void testClientCertProviderNotFound() throws Exception {
    EasyMock.expect(mockRequest.getConnector().getProperty("clientCertProvider")).andStubReturn("wontBeFound");
    EasyMock.replay(mockRequest.getConnector());
    mockRequest.setHeader(valve.getSslClientCertHeader(), certificateSingleLine(" "));
    TesterLogValidationFilter f = TesterLogValidationFilter.add(Level.SEVERE, null, "java.security.NoSuchProviderException", "org.apache.catalina.valves.SSLValve");
    valve.invoke(mockRequest, null);
    Assert.assertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
    Assert.assertEquals(1, f.getMessageCount());
}
Also used : TesterLogValidationFilter(org.apache.tomcat.unittest.TesterLogValidationFilter) Test(org.junit.Test)

Example 2 with TesterLogValidationFilter

use of org.apache.tomcat.unittest.TesterLogValidationFilter in project tomcat70 by apache.

the class TestSSLValve method testSslClientCertBadFormat.

@Test
public void testSslClientCertBadFormat() throws Exception {
    String[] linesDeleted = Arrays.copyOf(CERTIFICATE_LINES, CERTIFICATE_LINES.length / 2);
    String deleted = certificateSingleLine(linesDeleted, " ");
    mockRequest.setHeader(valve.getSslClientCertHeader(), deleted);
    TesterLogValidationFilter f = TesterLogValidationFilter.add(Level.WARNING, null, "java.security.cert.CertificateException", "org.apache.catalina.valves.SSLValve");
    valve.invoke(mockRequest, null);
    EasyMock.verify(mockNext);
    Assert.assertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
    Assert.assertEquals(1, f.getMessageCount());
}
Also used : TesterLogValidationFilter(org.apache.tomcat.unittest.TesterLogValidationFilter) Test(org.junit.Test)

Example 3 with TesterLogValidationFilter

use of org.apache.tomcat.unittest.TesterLogValidationFilter in project tomcat70 by apache.

the class TestWebappClassLoaderThreadLocalMemoryLeak method testThreadLocalLeak2.

@Test
public void testThreadLocalLeak2() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // Need to make sure we see a leak for the right reasons
    tomcat.getServer().addLifecycleListener(new JreMemoryLeakPreventionListener());
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    Tomcat.addServlet(ctx, "leakServlet2", "org.apache.tomcat.unittest.TesterLeakingServlet2");
    ctx.addServletMapping("/leak2", "leakServlet2");
    tomcat.start();
    Executor executor = tomcat.getConnector().getProtocolHandler().getExecutor();
    ((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1);
    // Configure logging filter to check leak message appears
    TesterLogValidationFilter f = TesterLogValidationFilter.add(null, "The web application [] created a ThreadLocal with key of", null, "org.apache.catalina.loader.WebappClassLoaderBase");
    // Need to force loading of all web application classes via the web
    // application class loader
    loadClass("TesterCounter", (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
    loadClass("TesterThreadScopedHolder", (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
    loadClass("TesterLeakingServlet2", (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
    // This will trigger the ThreadLocal creation
    int rc = getUrl("http://localhost:" + getPort() + "/leak2", new ByteChunk(), null);
    // Make sure request is OK
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    // Destroy the context
    ctx.stop();
    tomcat.getHost().removeChild(ctx);
    ctx = null;
    // Make sure we have a memory leak
    String[] leaks = ((StandardHost) tomcat.getHost()).findReloadedContextMemoryLeaks();
    Assert.assertNotNull(leaks);
    Assert.assertTrue(leaks.length > 0);
    // Make sure the message was logged
    Assert.assertEquals(1, f.getMessageCount());
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) Executor(java.util.concurrent.Executor) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) TesterLogValidationFilter(org.apache.tomcat.unittest.TesterLogValidationFilter) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) StandardHost(org.apache.catalina.core.StandardHost) JreMemoryLeakPreventionListener(org.apache.catalina.core.JreMemoryLeakPreventionListener) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 4 with TesterLogValidationFilter

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

the class TestSSLValve method testClientCertProviderNotFound.

@Test
public void testClientCertProviderNotFound() throws Exception {
    EasyMock.expect(mockRequest.getConnector().getProperty("clientCertProvider")).andStubReturn("wontBeFound");
    EasyMock.replay(mockRequest.getConnector());
    mockRequest.setHeader(valve.getSslClientCertHeader(), certificateSingleLine(" "));
    TesterLogValidationFilter f = TesterLogValidationFilter.add(Level.SEVERE, null, "java.security.NoSuchProviderException", "org.apache.catalina.valves.SSLValve");
    valve.invoke(mockRequest, null);
    Assert.assertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
    Assert.assertEquals(1, f.getMessageCount());
}
Also used : TesterLogValidationFilter(org.apache.tomcat.unittest.TesterLogValidationFilter) Test(org.junit.Test)

Example 5 with TesterLogValidationFilter

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

the class TestSSLValve method testSslClientCertNull.

@Test
public void testSslClientCertNull() throws Exception {
    TesterLogValidationFilter f = TesterLogValidationFilter.add(null, "", null, "org.apache.catalina.valves.SSLValve");
    valve.invoke(mockRequest, null);
    EasyMock.verify(mockNext);
    Assert.assertNull(mockRequest.getAttribute(Globals.CERTIFICATES_ATTR));
    Assert.assertEquals(0, f.getMessageCount());
}
Also used : TesterLogValidationFilter(org.apache.tomcat.unittest.TesterLogValidationFilter) Test(org.junit.Test)

Aggregations

TesterLogValidationFilter (org.apache.tomcat.unittest.TesterLogValidationFilter)14 Test (org.junit.Test)12 Executor (java.util.concurrent.Executor)4 Context (org.apache.catalina.Context)4 JreMemoryLeakPreventionListener (org.apache.catalina.core.JreMemoryLeakPreventionListener)4 StandardHost (org.apache.catalina.core.StandardHost)4 Tomcat (org.apache.catalina.startup.Tomcat)4 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)4 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)4 ThreadPoolExecutor (org.apache.tomcat.util.threads.ThreadPoolExecutor)4 X509Certificate (java.security.cert.X509Certificate)2