blob: 4dfa494dbb84d9f41ad1f682ecc80abf25888f84 [file] [log] [blame]
package org.eclipse.jetty.exssl;
import java.io.File;
import java.security.cert.CertificateException;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.After;
import org.junit.Test;
public abstract class CertificateValidationTestBase
{
protected Server _server;
protected EnhancedSslConnector _connector;
@After
public void tearDown()
{
try
{
_server.stop();
_connector = null;
_server = null;
}
catch (Exception ex) {}
}
protected void doTest(String keystore) throws Exception
{
String keypath = MavenTestingUtils.getTestResourceFile(keystore).getAbsolutePath();
String trustpath = new File(System.getProperty("java.home"),"./lib/security/cacerts").getAbsolutePath();
String crlpath = MavenTestingUtils.getTestResourceFile("crlfile.pem").getAbsolutePath();
_connector.setPort(0);
_connector.setValidateCert(true);
_connector.setKeystore(keypath);
_connector.setPassword("webtide");
_connector.setKeyPassword("webtide");
_connector.setTruststore(trustpath);
_connector.setTrustPassword("changeit");
_connector.setCrlPath(crlpath);
_server = new Server();
_server.addConnector(_connector);
_server.start();
Thread.sleep(1000);
}
@Test
public void validCertificateTest() throws Exception
{
doTest("jetty-valid.keystore"); // certificate is valid until Jan 1, 2050
}
@Test(expected = CertificateException.class)
public void revokedCertificateTest() throws Exception
{
doTest("jetty-revoked.keystore"); // certificate is valid until Jan 1, 2050
}
@Test(expected = CertificateException.class)
public void notvalidCertificateTest() throws Exception
{
doTest("jetty-notvalid.keystore"); // certificate is valid from Jan 1, 2049
}
@Test(expected = CertificateException.class)
public void expiredCertificateTest() throws Exception
{
doTest("jetty-expired.keystore"); // certificate is valid until Dec 31, 2000
}
}