mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

vharseko
12.41.2023 0de6858e9548e84aebc148747be92a811ba33636
opendj-server-legacy/src/test/java/org/opends/server/util/CertificateManagerTestCase.java
@@ -50,31 +50,34 @@
  /** Get the build root and use it to create a test package directory. */
  public static final String BUILD_ROOT =
          System.getProperty(TestCaseUtils.PROPERTY_BUILD_ROOT);
//  public static final String BUILD_ROOT =
//          System.getProperty(TestCaseUtils.PROPERTY_BUILD_ROOT);
  /**
   * The path to a JKS key store file.
   */
  public static final String JKS_KEY_STORE_PATH = TestCaseUtils.getUnitTestRootPath()
       + File.separator + "package-instance" + File.separator + "config" + File.separator + "server.keystore";
  public static final String JKS_KEY_STORE_PATH() {
     return TestCaseUtils.paths.testInstanceRoot.getPath() + File.separator + "config" + File.separator + "server.keystore";
  }
  /**
   * The path to a PKCS#12 key store file.
   */
  public static final String PKCS12_KEY_STORE_PATH = TestCaseUtils.getUnitTestRootPath()
       + File.separator + "package-instance" + File.separator + "config" + File.separator + "server-cert.p12";
  public static final String PKCS12_KEY_STORE_PATH() {
     return TestCaseUtils.paths.testInstanceRoot.getPath() + File.separator + "config" + File.separator + "server-cert.p12";
  }
  /**
   * The path to the unit test working directory.
   */
  public static final String TEST_DIR = TestCaseUtils.getUnitTestRootPath()
       + File.separator + "package-instance";
  public static final String TEST_DIR() {
     return TestCaseUtils.paths.testInstanceRoot.getPath();
  }
@@ -138,7 +141,7 @@
  public void testConstructorNonexistentPath()
         throws Exception
  {
    String path = TEST_DIR + File.separator + "nonexistent" + File.separator +
    String path = TEST_DIR() + File.separator + "nonexistent" + File.separator +
                  "doesntmatter";
    new CertificateManager(path, "JKS", "password");
@@ -156,7 +159,7 @@
  public void testConstructorPathNotFile()
         throws Exception
  {
    new CertificateManager(TEST_DIR, "JKS", "password");
    new CertificateManager(TEST_DIR(), "JKS", "password");
  }
@@ -171,7 +174,7 @@
  public void testConstructorNullType()
         throws Exception
  {
    new CertificateManager(JKS_KEY_STORE_PATH, null, "password");
    new CertificateManager(JKS_KEY_STORE_PATH(), null, "password");
  }
@@ -186,7 +189,7 @@
  public void testConstructorEmptyType()
         throws Exception
  {
    new CertificateManager(JKS_KEY_STORE_PATH, "", "password");
    new CertificateManager(JKS_KEY_STORE_PATH(), "", "password");
  }
@@ -200,7 +203,7 @@
  public void testConstructorInvalidType()
         throws Exception
  {
    new CertificateManager(JKS_KEY_STORE_PATH, "invalid", "password");
    new CertificateManager(JKS_KEY_STORE_PATH(), "invalid", "password");
  }
@@ -215,7 +218,7 @@
  public void testConstructorInvalidPKCS11Path()
         throws Exception
  {
    new CertificateManager(JKS_KEY_STORE_PATH, "PKCS11", "password");
    new CertificateManager(JKS_KEY_STORE_PATH(), "PKCS11", "password");
  }
@@ -230,7 +233,7 @@
  public void testConstructorNullPIN()
         throws Exception
  {
    assertNotNull(new CertificateManager(JKS_KEY_STORE_PATH, "JKS", (String) null));
    assertNotNull(new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", (String) null));
  }
@@ -245,7 +248,7 @@
  public void testConstructorEmptyPIN()
         throws Exception
  {
    assertNotNull(new CertificateManager(JKS_KEY_STORE_PATH, "JKS", ""));
    assertNotNull(new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", ""));
  }
@@ -262,7 +265,7 @@
      return;
    }
    new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
    new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
  }
@@ -279,7 +282,7 @@
      return;
    }
    new CertificateManager(PKCS12_KEY_STORE_PATH, "PKCS12", "password");
    new CertificateManager(PKCS12_KEY_STORE_PATH(), "PKCS12", "password");
  }
@@ -299,7 +302,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -325,7 +328,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -386,11 +389,11 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    assertTrue(certManager.aliasInUse("server-cert"));
    assertFalse(certManager.aliasInUse("nonexistent"));
    String path = TEST_DIR + File.separator + "nonexistent";
    String path = TEST_DIR() + File.separator + "nonexistent";
    certManager = new CertificateManager(path, "JKS", "password");
    assertFalse(certManager.aliasInUse("doesntmatter"));
  }
@@ -412,11 +415,11 @@
    }
    CertificateManager certManager =
         new CertificateManager(PKCS12_KEY_STORE_PATH, "PKCS12", "password");
         new CertificateManager(PKCS12_KEY_STORE_PATH(), "PKCS12", "password");
    assertTrue(certManager.aliasInUse("server-cert"));
    assertFalse(certManager.aliasInUse("nonexistent"));
    String path = TEST_DIR + File.separator + "nonexistent";
    String path = TEST_DIR() + File.separator + "nonexistent";
    certManager = new CertificateManager(path, "PKCS12", "password");
    assertFalse(certManager.aliasInUse("doesntmatter"));
  }
@@ -439,14 +442,14 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    String[] aliases = certManager.getCertificateAliases();
    assertNotNull(aliases);
    assertTrue(aliases.length > 0);
    assertTrue(Arrays.asList(aliases).contains("server-cert"));
    String path = TEST_DIR + File.separator + "nonexistent";
    String path = TEST_DIR() + File.separator + "nonexistent";
    certManager = new CertificateManager(path, "JKS", "password");
    assertNull(certManager.getCertificateAliases());
  }
@@ -469,14 +472,14 @@
    }
    CertificateManager certManager =
         new CertificateManager(PKCS12_KEY_STORE_PATH, "PKCS12", "password");
         new CertificateManager(PKCS12_KEY_STORE_PATH(), "PKCS12", "password");
    String[] aliases = certManager.getCertificateAliases();
    assertNotNull(aliases);
    assertTrue(aliases.length > 0);
    assertTrue(Arrays.asList(aliases).contains("server-cert"));
    String path = TEST_DIR + File.separator + "nonexistent";
    String path = TEST_DIR() + File.separator + "nonexistent";
    certManager = new CertificateManager(path, "PKCS12", "password");
    assertNull(certManager.getCertificateAliases());
  }
@@ -498,7 +501,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -524,7 +527,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -550,11 +553,11 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    assertNotNull(certManager.getCertificate("server-cert"));
    assertNull(certManager.getCertificate("nonexistent"));
    String path = TEST_DIR + File.separator + "nonexistent";
    String path = TEST_DIR() + File.separator + "nonexistent";
    certManager = new CertificateManager(path, "JKS", "password");
    try
    {
@@ -581,11 +584,11 @@
    }
    CertificateManager certManager =
         new CertificateManager(PKCS12_KEY_STORE_PATH, "PKCS12", "password");
         new CertificateManager(PKCS12_KEY_STORE_PATH(), "PKCS12", "password");
    assertNotNull(certManager.getCertificate("server-cert"));
    assertNull(certManager.getCertificate("nonexistent"));
    String path = TEST_DIR + File.separator + "nonexistent";
    String path = TEST_DIR() + File.separator + "nonexistent";
    certManager = new CertificateManager(path, "PKCS12", "password");
    try
    {
@@ -611,7 +614,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -638,7 +641,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -665,7 +668,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -693,7 +696,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -720,7 +723,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -779,7 +782,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -865,7 +868,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    File exportFile = exportCertificate();
    try
@@ -894,7 +897,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    File exportFile = exportCertificate();
    try
@@ -923,7 +926,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -950,9 +953,9 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    File f = new File(TEST_DIR, "nonexistent");
    File f = new File(TEST_DIR(), "nonexistent");
    try
    {
@@ -980,9 +983,9 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    File f = new File(TEST_DIR);
    File f = new File(TEST_DIR());
    try
    {
@@ -1010,7 +1013,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    File path = File.createTempFile("testAddCertificateFileNotCertificate",
                                    ".notacertificate");
@@ -1045,7 +1048,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -1071,7 +1074,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -1098,7 +1101,7 @@
    }
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    try
    {
@@ -1161,7 +1164,7 @@
    path.delete();
    CertificateManager certManager =
         new CertificateManager(JKS_KEY_STORE_PATH, "JKS", "password");
         new CertificateManager(JKS_KEY_STORE_PATH(), "JKS", "password");
    Certificate certificate = certManager.getCertificate("server-cert");
    assertNotNull(certificate);