blob: da2577016875a872f8e6dd7eae758db65b160d8c [file] [log] [blame]
package org.eclipse.jetty.exssl;
import java.io.File;
import java.lang.reflect.Constructor;
import java.security.cert.CertificateException;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ssl.SslConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.After;
import org.junit.Test;
public abstract class CertificateValidationTestBase
{
protected Server _server;
protected Class<? extends SslConnector> _klass;
@After
public void tearDown()
{
try
{
_server.stop();
_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();
SslParameters sslParams = new SslParameters();
sslParams.setValidateCerts(true);
sslParams.setKeystore(keypath);
sslParams.setPassword("webtide");
sslParams.setKeyPassword("webtide");
sslParams.setTruststore(trustpath);
sslParams.setTrustPassword("changeit");
sslParams.setCrlPath(crlpath);
Constructor<? extends SslConnector> constructor = _klass.getConstructor(SslParameters.class);
SslConnector connector = constructor.newInstance(sslParams);
connector.setPort(0);
_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
}
}