From ec739b8d5f2d925494e7f9743b0d8c8a492c2071 Mon Sep 17 00:00:00 2001
From: Fabio Pistolesi <fabio.pistolesi@forgerock.com>
Date: Fri, 13 May 2016 09:02:20 +0000
Subject: [PATCH] Add confidential versions of backend unit tests

---
 opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/pdb/PDBTestCase.java              |    4 -
 opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/EncryptedJETestCase.java                |   39 +++++++++++++++++++
 opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/PluggableBackendImplTestCase.java |    4 ++
 opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/pdb/EncryptedPDBTestCase.java     |   39 +++++++++++++++++++
 4 files changed, 83 insertions(+), 3 deletions(-)

diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/EncryptedJETestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/EncryptedJETestCase.java
new file mode 100644
index 0000000..2e5b353
--- /dev/null
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/EncryptedJETestCase.java
@@ -0,0 +1,39 @@
+/*
+ * The contents of this file are subject to the terms of the Common Development and
+ * Distribution License (the License). You may not use this file except in compliance with the
+ * License.
+ *
+ * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
+ * specific language governing permission and limitations under the License.
+ *
+ * When distributing Covered Software, include this CDDL Header Notice in each file and include
+ * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
+ * Header, with the fields enclosed by brackets [] replaced by your own identifying
+ * information: "Portions Copyright [year] [name of copyright owner]".
+ *
+ * Copyright 2016 ForgeRock AS.
+ */
+
+package org.opends.server.backends.jeb;
+
+import org.forgerock.opendj.server.config.server.JEBackendCfg;
+import org.testng.annotations.Test;
+
+import static org.mockito.Mockito.when;
+
+/** Encrypted PDBBackend Tester. */
+@Test
+public class EncryptedJETestCase extends JETestCase
+{
+  @Override
+  protected JEBackendCfg createBackendCfg()
+  {
+    JEBackendCfg backendCfg = super.createBackendCfg();
+    when(backendCfg.getBackendId()).thenReturn("EncJETestCase");
+    when(backendCfg.getDBDirectory()).thenReturn("EncJETestCase");
+    when(backendCfg.isConfidentialityEnabled()).thenReturn(true);
+    when(backendCfg.getCipherKeyLength()).thenReturn(128);
+    when(backendCfg.getCipherTransformation()).thenReturn("AES/CBC/PKCS5Padding");
+    return backendCfg;
+  }
+}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/PluggableBackendImplTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/PluggableBackendImplTestCase.java
index a7f466a..85a739c 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/PluggableBackendImplTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/PluggableBackendImplTestCase.java
@@ -167,6 +167,10 @@
       when(indexCfg.getIndexEntryLimit()).thenReturn(4000);
       when(indexCfg.getSubstringLength()).thenReturn(6);
       when(backendCfg.getBackendIndex(index.getKey())).thenReturn(indexCfg);
+      if (backendCfg.isConfidentialityEnabled())
+      {
+        when(indexCfg.isConfidentialityEnabled()).thenReturn(true);
+      }
     }
 
     BackendVLVIndexCfg vlvIndexCfg = mock(BackendVLVIndexCfg.class);
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/pdb/EncryptedPDBTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/pdb/EncryptedPDBTestCase.java
new file mode 100644
index 0000000..a2e6057
--- /dev/null
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/pdb/EncryptedPDBTestCase.java
@@ -0,0 +1,39 @@
+/*
+ * The contents of this file are subject to the terms of the Common Development and
+ * Distribution License (the License). You may not use this file except in compliance with the
+ * License.
+ *
+ * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
+ * specific language governing permission and limitations under the License.
+ *
+ * When distributing Covered Software, include this CDDL Header Notice in each file and include
+ * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
+ * Header, with the fields enclosed by brackets [] replaced by your own identifying
+ * information: "Portions Copyright [year] [name of copyright owner]".
+ *
+ * Copyright 2016 ForgeRock AS.
+ */
+
+package org.opends.server.backends.pluggable.pdb;
+
+import org.forgerock.opendj.server.config.server.PDBBackendCfg;
+import org.testng.annotations.Test;
+
+import static org.mockito.Mockito.when;
+
+/** Encrypted PDBBackend Tester. */
+@Test
+public class EncryptedPDBTestCase extends PDBTestCase
+{
+  @Override
+  protected PDBBackendCfg createBackendCfg()
+  {
+    PDBBackendCfg backendCfg = super.createBackendCfg();
+    when(backendCfg.getBackendId()).thenReturn("EncPDBTestCase");
+    when(backendCfg.getDBDirectory()).thenReturn("EncPDBTestCase");
+    when(backendCfg.isConfidentialityEnabled()).thenReturn(true);
+    when(backendCfg.getCipherKeyLength()).thenReturn(128);
+    when(backendCfg.getCipherTransformation()).thenReturn("AES/CBC/PKCS5Padding");
+    return backendCfg;
+  }
+}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/pdb/PDBTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/pdb/PDBTestCase.java
index afc4804..389f1e8 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/pdb/PDBTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/pdb/PDBTestCase.java
@@ -24,9 +24,7 @@
 import org.opends.server.backends.pluggable.PluggableBackendImplTestCase;
 import org.testng.annotations.Test;
 
-/**
- * PDBBackend Tester.
- */
+/** PDBBackend Tester. */
 @Test
 public class PDBTestCase extends PluggableBackendImplTestCase<PDBBackendCfg>
 {

--
Gitblit v1.10.0