From 4fc797d6a4c0e33640b49822c0d01cddec0de79d Mon Sep 17 00:00:00 2001
From: Fabio Pistolesi <fabio.pistolesi@forgerock.com>
Date: Thu, 02 Jun 2016 12:46:27 +0000
Subject: [PATCH] OPENDJ-3051 Make sure cryptographic keys are generated or imported atomically.

---
 opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java |   15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java
index 765c86c..6dc4053 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java
@@ -49,7 +49,6 @@
 import org.opends.server.util.EmbeddedUtils;
 import org.opends.server.util.StaticUtils;
 import org.opends.server.util.TimeThread;
-import org.testng.Assert;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
@@ -81,8 +80,8 @@
     TestCaseUtils.restartServer();
   }
 
-  @Test(expectedExceptions = CryptoManagerException.class)
-  public void testImportKeysReplacesExistingKeys()
+  @Test
+  public void testImportKeysUsesLatestKey()
       throws Exception {
     final CryptoManagerImpl cm = DirectoryServer.getCryptoManager();
     final int keyLength = 56;
@@ -93,14 +92,8 @@
     Modification mod = new Modification(REPLACE, create("ds-cfg-key-id", UUID.randomUUID().toString()));
     oldKey.applyModification(mod);
     cm.importCipherKeyEntry(oldKey);
-    try
-    {
-      cm.decrypt(cipherText);
-      Assert.fail("Was expecting a CryptoManager exception, the key should be invalid.");
-    }
-    finally
-    {
-    }
+    byte[] newCipherText = cm.encrypt(cipher, keyLength, new byte[56]);
+    assertThat(ByteString.wrap(cipherText, 1, 16).compareTo(newCipherText, 1, 16)).isNotEqualTo(0);
   }
 
   private Entry getKeyForCipher(String cipher, int keyLength) throws DirectoryException

--
Gitblit v1.10.0