CertificateManagerTestCase.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2013-2015 ForgeRock AS
*/
/**
* A set of generic test cases for the certificate manager class.
*/
public class CertificateManagerTestCase
extends UtilTestCase
{
/**
* Indicates whether the certificate manager is available on this platform and
* should be tested.
*/
public static final boolean CERT_MANAGER_AVAILABLE =
// Get the build root and use it to create a test package directory.
public static final String BUILD_ROOT =
/**
* The path to a JKS key store file.
*/
public static final String JKS_KEY_STORE_PATH =
"package-instance" +
/**
* The path to a PKCS#12 key store file.
*/
public static final String PKCS12_KEY_STORE_PATH =
"package-instance" +
/**
* The path to the unit test working directory.
*/
"package-instance";
/**
* Make sure the server is running.
*
* @throws Exception If a problem occurs.
*/
public void startServer()
throws Exception
{
}
/**
* Tests the CertificateManager constructor using a null argument for the key
* store path.
*
* @throws Exception If a problem occurs.
*/
public void testConstructorNullPath()
throws Exception
{
}
/**
* Tests the CertificateManager constructor using an empty string for the key
* store path.
*
* @throws Exception If a problem occurs.
*/
public void testConstructorEmptyPath()
throws Exception
{
}
/**
* Tests the CertificateManager constructor using a key store path that refers
* to a file in a nonexistent directory.
*
* @throws Exception If a problem occurs.
*/
public void testConstructorNonexistentPath()
throws Exception
{
"doesntmatter";
}
/**
* Tests the CertificateManager constructor using a key store path that refers
* to a file that exists but isn't a file.
*
* @throws Exception If a problem occurs.
*/
public void testConstructorPathNotFile()
throws Exception
{
}
/**
* Tests the CertificateManager constructor using a null argument for the key
* store type.
*
* @throws Exception If a problem occurs.
*/
public void testConstructorNullType()
throws Exception
{
}
/**
* Tests the CertificateManager constructor using an empty string for the key
* store type.
*
* @throws Exception If a problem occurs.
*/
public void testConstructorEmptyType()
throws Exception
{
}
/**
* Tests the CertificateManager constructor using an invalid key store type.
*
* @throws Exception If a problem occurs.
*/
public void testConstructorInvalidType()
throws Exception
{
}
/**
* Tests the CertificateManager constructor using an invalid key store path
* in conjunction with the PKCS11 key store type..
*
* @throws Exception If a problem occurs.
*/
public void testConstructorInvalidPKCS11Path()
throws Exception
{
}
/**
* Tests the CertificateManager constructor using a null argument for the key
* store PIN.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testConstructorNullPIN()
throws Exception
{
}
/**
* Tests the CertificateManager constructor using an empty string for the key
* store PIN.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testConstructorEmptyPIN()
throws Exception
{
}
/**
* Tests the certificate manager with a valid constructor using the JKS key
* store type.
*/
@Test
public void testValidConstructorJKS()
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
}
/**
* Tests the certificate manager with a valid constructor using the PKCS12 key
* store type.
*/
@Test
public void testValidConstructorPKCS12()
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
}
/**
* Tests the {@code aliasInUse} method with a null alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAliasInUseNull()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to null alias");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code aliasInUse} method with an empty alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAliasInUseEmpty()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to empty alias");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code aliasInUse} method with an invalid key store.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAliasInUseInvalidKeyStore()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
".notakeystore");
path.deleteOnExit();
try
{
fail("Expected a key store exception due to an invalid key store");
} catch (KeyStoreException kse) {}
}
/**
* Tests the {@code aliasInUse} method for a key store using the JKS type.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAliasInUseJKS()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
}
/**
* Tests the {@code aliasInUse} method for a key store using the PKCS12 type.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAliasInUsePKCS12()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
}
/**
* Tests the {@code getCertificateAliases} method for a key store using the
* JKS type.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGetCertificateAliasesJKS()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
}
/**
* Tests the {@code getCertificateAliases} method for a key store using the
* PKCS12 type.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGetCertificateAliasesPKCS12()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
}
/**
* Tests the {@code getCertificate} method using a null alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGetCertificateNull()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to a null alias");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code getCertificate} method using an empty alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGetCertificateEmpty()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to a null alias");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code getCertificate} method for a key store using the JKS type.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGetCertificateJKS()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected a key store exception due to a nonexistent key store");
} catch (KeyStoreException kse) {}
}
/**
* Tests the {@code getCertificate} method for a key store using the PKCS12
* type.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGetCertificatePKCS12()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected a key store exception due to a nonexistent key store");
} catch (KeyStoreException kse) {}
}
/**
* Tests the {@code generateSelfSignedCertificate} method using a null alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGenerateSelfSignedCertificateNullAlias()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to a null alias");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code generateSelfSignedCertificate} method using an empty
* alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGenerateSelfSignedCertificateEmptyAlias()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to an empty alias");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code generateSelfSignedCertificate} method using an alias
* that's already being used.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGenerateSelfSignedCertificateAliasInUse()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
365);
fail("Expected an illegal argument exception to a duplicate alias");
} catch (IllegalArgumentException iae) {}
}
/**
* Tests the {@code generateSelfSignedCertificate} method using a null
* subject.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGenerateSelfSignedCertificateNullSubject()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to a null subject");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code generateSelfSignedCertificate} method using an empty
* subject.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGenerateSelfSignedCertificateEmptySubject()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to an empty subject");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code generateSelfSignedCertificate} method using an invalid
* subject.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGenerateSelfSignedCertificateInvalidSubject()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
".keystore");
path.deleteOnExit();
try
{
fail("Expected a key store exception due to an invalid subject");
} catch (KeyStoreException cse) {}
}
/**
* Tests the {@code generateSelfSignedCertificate} method using an invalid
* validity.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGenerateSelfSignedCertificateInvalidValidity()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
0);
fail("Expected an illegal argument exception due to an invalid validity");
} catch (IllegalArgumentException iae) {}
}
/**
* Tests the {@code generateSelfSignedCertificate} method for a JKS key store.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testGenerateSelfSignedCertificateJKS()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
".keystore");
path.deleteOnExit();
365);
}
/**
* Tests the {@code generateSelfSignedCertificate} method for a PKCS12 key
* store.
*
* @throws Exception If a problem occurs.
*/
public void testGenerateSelfSignedCertificatePKCS12()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
".p12");
path.deleteOnExit();
365);
}
/**
* Tests the {@code addCertificate} method using a null alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAddCertificateNullAlias()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to a null alias");
} catch (NullPointerException npe) {}
exportFile.delete();
}
/**
* Tests the {@code addCertificate} method using an empty alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAddCertificateEmptyAlias()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to an empty alias");
} catch (NullPointerException npe) {}
exportFile.delete();
}
/**
* Tests the {@code addCertificate} method using a null certificate file.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAddCertificateNullCertificateFile()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to a null certificate file");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code addCertificate} method using a certificate file that does
* not exist.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAddCertificateMissingCertificateFile()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an illegal argument exception due to a missing " +
"certificate file");
} catch (IllegalArgumentException iae) {}
}
/**
* Tests the {@code addCertificate} method using a certificate file that is
* not a file.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAddCertificateFileNotFile()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an illegal argument exception due to a certificate file " +
"actually being a directory");
} catch (IllegalArgumentException iae) {}
}
/**
* Tests the {@code addCertificate} method using a certificate file that
* contains something other than a certificate.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAddCertificateFileNotCertificate()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
".notacertificate");
path.deleteOnExit();
try
{
fail("Expected a key store exception due to an invalid certificate");
} catch (KeyStoreException kse) {}
}
/**
* Tests the {@code removeCertificate} method using a null alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testRemoveCertificateNullAlias()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to a null alias");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code removeCertificate} method using an empty alias.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testRemoveCertificateEmptyAlias()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an NPE due to an empty alias");
} catch (NullPointerException npe) {}
}
/**
* Tests the {@code removeCertificate} method using an alias that doesn't
* exist.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testRemoveCertificateNonexistentAlias()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
try
{
fail("Expected an illegal argument exception due to a nonexistent alias");
} catch (IllegalArgumentException iae) {}
}
/**
* Tests the {@code addCertificate} and {@code removeCertificate} methods
* using a newly-created JKS key store.
*
* @throws Exception If a problem occurs.
*/
@Test
public void testAddAndRemoveCertificateJKS()
throws Exception
{
if (! CERT_MANAGER_AVAILABLE)
{
return;
}
".keystore");
path.deleteOnExit();
exportFile.delete();
}
/**
* Exports a certificate to a temporary file.
*
* @throws Exception If a problem occurs.
*/
private File exportCertificate()
throws Exception
{
".cert");
path.deleteOnExit();
return path;
}
}