| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.util; |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code generateCertificateSigningRequest} method using a null |
| | | * alias. |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testGenerateCSRNullAlias() |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password"); |
| | | |
| | | try |
| | | { |
| | | certManager.generateCertificateSigningRequest(null, "CN=Test,O=test"); |
| | | fail("Expected an NPE due to a null alias"); |
| | | } catch (NullPointerException npe) {} |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code generateCertificateSigningRequest} method using an empty |
| | | * alias. |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testGenerateCSREmptyAlias() |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password"); |
| | | |
| | | try |
| | | { |
| | | certManager.generateCertificateSigningRequest("", "CN=Test,O=test"); |
| | | fail("Expected an NPE due to an empty alias"); |
| | | } catch (NullPointerException npe) {} |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code generateCertificateSigningRequest} method using an alias |
| | | * that's already being used. |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testGenerateCSRAliasInUse() |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE || Platform.isVendor("IBM")) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password"); |
| | | |
| | | try |
| | | { |
| | | certManager.generateCertificateSigningRequest("server-cert", |
| | | "CN=Test,O=test"); |
| | | fail("Expected an illegal argument exception to a duplicate alias"); |
| | | } catch (IllegalArgumentException iae) {} |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code generateCertificateSigningRequest} method using a null |
| | | * subject. |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testGenerateCSRNullSubject() |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password"); |
| | | |
| | | try |
| | | { |
| | | certManager.generateCertificateSigningRequest("test-cert", null); |
| | | fail("Expected an NPE due to a null subject"); |
| | | } catch (NullPointerException npe) {} |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code generateCertificateSigningRequest} method using an empty |
| | | * subject. |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testGenerateCSREmptySubject() |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password"); |
| | | |
| | | try |
| | | { |
| | | certManager.generateCertificateSigningRequest("test-cert", ""); |
| | | fail("Expected an NPE due to an empty subject"); |
| | | } catch (NullPointerException npe) {} |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code generateCertificateSigningRequest} method using an invalid |
| | | * subject. |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testGenerateCSRInvalidSubject() |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE || Platform.isVendor("IBM")) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | File path = File.createTempFile("testGenerateCSRJKS", |
| | | ".keystore"); |
| | | path.deleteOnExit(); |
| | | path.delete(); |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(path.getAbsolutePath(), "JKS", "password"); |
| | | |
| | | try |
| | | { |
| | | File requestFile = |
| | | certManager.generateCertificateSigningRequest("test-cert", |
| | | "invalid"); |
| | | requestFile.delete(); |
| | | fail("Expected a key store exception due to an invalid subject"); |
| | | } catch (KeyStoreException cse) {} |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code generateCertificateSigningRequest} method for a JKS key |
| | | * store. |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testGenerateCSRJKS() |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE || Platform.isVendor("IBM")) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | File path = File.createTempFile("testGenerateCSRJKS", |
| | | ".keystore"); |
| | | path.deleteOnExit(); |
| | | path.delete(); |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(path.getAbsolutePath(), "JKS", "password"); |
| | | File csrFile = certManager.generateCertificateSigningRequest("test-cert", |
| | | "CN=Test,o=test"); |
| | | assertNotNull(csrFile); |
| | | assertTrue(csrFile.length() > 0); |
| | | path.delete(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code generateCertificateSigningRequest} method for a PKCS12 key |
| | | * store. |
| | | * |
| | | * @throws Exception If a problem occurs. |
| | | */ |
| | | @Test(groups="slow") |
| | | public void testGenerateCSRPKCS12() |
| | | throws Exception |
| | | { |
| | | if (! CERT_MANAGER_AVAILABLE || Platform.isVendor("IBM")) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | File path = File.createTempFile("testGenerateCSRPKCS12", |
| | | ".p12"); |
| | | path.deleteOnExit(); |
| | | path.delete(); |
| | | |
| | | CertificateManager certManager = |
| | | new CertificateManager(path.getAbsolutePath(), "PKCS12", "password"); |
| | | File csrFile = certManager.generateCertificateSigningRequest("test-cert", |
| | | "CN=Test,o=test"); |
| | | assertNotNull(csrFile); |
| | | assertTrue(csrFile.length() > 0); |
| | | path.delete(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code addCertificate} method using a null alias. |
| | | * |
| | | * @throws Exception If a problem occurs. |