| | |
| | | import java.util.Arrays; |
| | | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.util.Platform.KeyType; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | |
| | | /** |
| | | * The path to a JKS key store file. |
| | | */ |
| | | public static final String JKS_KEY_STORE_PATH = |
| | | System.getProperty(TestCaseUtils.PROPERTY_BUILD_DIR, |
| | | BUILD_ROOT + File.separator + "build") + |
| | | File.separator + "unit-tests" + File.separator + |
| | | "package-instance" + |
| | | File.separator + "config" + File.separator + "server.keystore"; |
| | | public static final String JKS_KEY_STORE_PATH = TestCaseUtils.getUnitTestRootPath() |
| | | + File.separator + "package-instance" + File.separator + "config" + File.separator + "server.keystore"; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The path to a PKCS#12 key store file. |
| | | */ |
| | | public static final String PKCS12_KEY_STORE_PATH = |
| | | System.getProperty(TestCaseUtils.PROPERTY_BUILD_DIR, |
| | | BUILD_ROOT + File.separator + "build") + |
| | | File.separator + "unit-tests" + File.separator + |
| | | "package-instance" + |
| | | File.separator + "config" + File.separator + "server-cert.p12"; |
| | | public static final String PKCS12_KEY_STORE_PATH = TestCaseUtils.getUnitTestRootPath() |
| | | + File.separator + "package-instance" + File.separator + "config" + File.separator + "server-cert.p12"; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The path to the unit test working directory. |
| | | */ |
| | | public static final String TEST_DIR = |
| | | System.getProperty(TestCaseUtils.PROPERTY_BUILD_DIR, |
| | | BUILD_ROOT + File.separator + "build") + |
| | | File.separator + "unit-tests" + File.separator + |
| | | "package-instance"; |
| | | public static final String TEST_DIR = TestCaseUtils.getUnitTestRootPath() |
| | | + File.separator + "package-instance"; |
| | | |
| | | |
| | | |
| | |
| | | TestCaseUtils.startServer(); |
| | | } |
| | | |
| | | |
| | | @DataProvider(name="keyTypes") |
| | | public Object[][] keyTypes() { |
| | | return new Object[][] { |
| | | { KeyType.EC }, |
| | | { KeyType.RSA } |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * Tests the CertificateManager constructor using a null argument for the key |
| | |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test |
| | | public void testGenerateSelfSignedCertificateNullAlias() |
| | | @Test(dataProvider="keyTypes") |
| | | public void testGenerateSelfSignedCertificateNullAlias(KeyType keyType) |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | |
| | | |
| | | try |
| | | { |
| | | certManager.generateSelfSignedCertificate(null, "CN=Test,O=test", 365); |
| | | certManager.generateSelfSignedCertificate(keyType, null, "CN=Test,O=test", 365); |
| | | fail("Expected an NPE due to a null alias"); |
| | | } catch (NullPointerException npe) {} |
| | | } |
| | |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test |
| | | public void testGenerateSelfSignedCertificateEmptyAlias() |
| | | @Test(dataProvider="keyTypes") |
| | | public void testGenerateSelfSignedCertificateEmptyAlias(KeyType keyType) |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | |
| | | |
| | | try |
| | | { |
| | | certManager.generateSelfSignedCertificate("", "CN=Test,O=test", 365); |
| | | certManager.generateSelfSignedCertificate(keyType, "", "CN=Test,O=test", 365); |
| | | fail("Expected an NPE due to an empty alias"); |
| | | } catch (NullPointerException npe) {} |
| | | } |
| | |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test |
| | | public void testGenerateSelfSignedCertificateAliasInUse() |
| | | @Test(dataProvider="keyTypes") |
| | | public void testGenerateSelfSignedCertificateAliasInUse(KeyType keyType) |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | |
| | | |
| | | try |
| | | { |
| | | certManager.generateSelfSignedCertificate("server-cert", "CN=Test,O=test", |
| | | certManager.generateSelfSignedCertificate(keyType, "server-cert", "CN=Test,O=test", |
| | | 365); |
| | | fail("Expected an illegal argument exception to a duplicate alias"); |
| | | } catch (IllegalArgumentException iae) {} |
| | |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test |
| | | public void testGenerateSelfSignedCertificateNullSubject() |
| | | @Test(dataProvider="keyTypes") |
| | | public void testGenerateSelfSignedCertificateNullSubject(KeyType keyType) |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | |
| | | |
| | | try |
| | | { |
| | | certManager.generateSelfSignedCertificate("test-cert", null, 365); |
| | | certManager.generateSelfSignedCertificate(keyType, "test-cert", null, 365); |
| | | fail("Expected an NPE due to a null subject"); |
| | | } catch (NullPointerException npe) {} |
| | | } |
| | |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test |
| | | public void testGenerateSelfSignedCertificateEmptySubject() |
| | | @Test(dataProvider="keyTypes") |
| | | public void testGenerateSelfSignedCertificateEmptySubject(KeyType keyType) |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | |
| | | |
| | | try |
| | | { |
| | | certManager.generateSelfSignedCertificate("test-cert", "", 365); |
| | | certManager.generateSelfSignedCertificate(keyType, "test-cert", "", 365); |
| | | fail("Expected an NPE due to an empty subject"); |
| | | } catch (NullPointerException npe) {} |
| | | } |
| | |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test |
| | | public void testGenerateSelfSignedCertificateInvalidSubject() |
| | | @Test(dataProvider="keyTypes") |
| | | public void testGenerateSelfSignedCertificateInvalidSubject(KeyType keyType) |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | |
| | | new CertificateManager(path.getAbsolutePath(), "JKS", "password"); |
| | | try |
| | | { |
| | | certManager.generateSelfSignedCertificate("test-cert", "invalid", 365); |
| | | certManager.generateSelfSignedCertificate(keyType, "test-cert", "invalid", 365); |
| | | fail("Expected a key store exception due to an invalid subject"); |
| | | } catch (KeyStoreException cse) {} |
| | | path.delete(); |
| | |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test |
| | | public void testGenerateSelfSignedCertificateInvalidValidity() |
| | | @Test(dataProvider="keyTypes") |
| | | public void testGenerateSelfSignedCertificateInvalidValidity(KeyType keyType) |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | |
| | | |
| | | try |
| | | { |
| | | certManager.generateSelfSignedCertificate("test-cert", "CN=Test,o=test", |
| | | certManager.generateSelfSignedCertificate(keyType, "test-cert", "CN=Test,o=test", |
| | | 0); |
| | | fail("Expected an illegal argument exception due to an invalid validity"); |
| | | } catch (IllegalArgumentException iae) {} |
| | |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test |
| | | public void testGenerateSelfSignedCertificateJKS() |
| | | @Test(dataProvider="keyTypes") |
| | | public void testGenerateSelfSignedCertificateJKS(KeyType keyType) |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(path.getAbsolutePath(), "JKS", "password"); |
| | | certManager.generateSelfSignedCertificate("test-cert", "CN=Test,o=test", |
| | | certManager.generateSelfSignedCertificate(keyType, "test-cert", "CN=Test,o=test", |
| | | 365); |
| | | assertTrue(certManager.aliasInUse("test-cert")); |
| | | path.delete(); |
| | |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test(groups="slow") |
| | | public void testGenerateSelfSignedCertificatePKCS12() |
| | | @Test(groups="slow", dataProvider="keyTypes") |
| | | public void testGenerateSelfSignedCertificatePKCS12(KeyType keyType) |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(path.getAbsolutePath(), "PKCS12", "password"); |
| | | certManager.generateSelfSignedCertificate("test-cert", "CN=Test,o=test", |
| | | certManager.generateSelfSignedCertificate(keyType, "test-cert", "CN=Test,o=test", |
| | | 365); |
| | | assertTrue(certManager.aliasInUse("test-cert")); |
| | | path.delete(); |