From f14469e3b3a695e7f750eea6e9cfbf1e6c00329f Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Mon, 28 Nov 2011 13:03:37 +0000
Subject: [PATCH] Fix for OPENDJ-255: Incorrect dsconfig usage for setting multiple property values at once. Contribution by German Parente (cgp). Both --set prop:value1 --set prop:value2 AND --set prop:value1 --add prop:value2 are accepted to set/create multivalued properties with dsconfig. When adding to existing property, --add is to be used.

---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigOptionsTestCase.java |  137 +++++++++++++++++++++++++++++++++++++++++++++
 opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java                        |    6 -
 2 files changed, 138 insertions(+), 5 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
index d29039b..6300ba0 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2007-2010 Sun Microsystems, Inc.
+ *      Portions Copyright 2011 ForgeRock AS
  */
 package org.opends.server.tools.dsconfig;
 
@@ -823,11 +824,6 @@
       }
 
       // Apply the modification.
-      if (lastModTypes.containsKey(propertyName) &&
-        (lastModTypes.get(propertyName) == ModificationType.SET)) {
-        throw ArgumentExceptionFactory.incompatiblePropertyModification(m);
-      }
-
       if (lastModTypes.containsKey(propertyName)) {
         modifyPropertyValues(child, pd, changes, ModificationType.ADD, value);
       } else {
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigOptionsTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigOptionsTestCase.java
new file mode 100644
index 0000000..aec4795
--- /dev/null
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigOptionsTestCase.java
@@ -0,0 +1,137 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *      Copyright 2011 ForgeRock AS
+ */
+package org.opends.server.tools.dsconfig;
+
+
+
+import java.io.File;
+import java.io.FileWriter;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.opends.server.TestCaseUtils;
+import org.opends.server.DirectoryServerTestCase;
+import org.opends.server.core.DirectoryServer;
+
+import static org.testng.Assert.*;
+
+import static org.opends.server.admin.client.cli.DsFrameworkCliReturnCode.*;
+
+
+
+/**
+ * A set of test cases for the dsservice tool.
+ */
+public class DsconfigOptionsTestCase extends DirectoryServerTestCase {
+
+
+  /**
+   * Ensures that the Directory Server is running and performs other necessary
+   * setup.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @BeforeClass()
+  public void before()
+         throws Exception
+  {
+    TestCaseUtils.startServer();
+  }
+
+  /**
+   * Ensures ADS is removed.
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @AfterClass()
+  public void afterClass()
+         throws Exception
+  {
+  }
+
+  /**
+   * Tests that multiple  "--set" option cannot be used with a singlevalued
+   * property
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testMultipleSetSingleValuedProperty()
+         throws Exception
+  {
+    String[] args =
+    {
+          "set-global-configuration-prop",
+          "-p",String.valueOf(TestCaseUtils.getServerAdminPort()),
+          "--trustAll",
+          "--bindDN","cn=Directory Manager",
+          "--bindPassword" , "password",
+          "--no-prompt",
+          "--set", "idle-time-limit:10000ms",
+          "--set", "idle-time-limit:1000ms"
+    };
+
+     assertFalse(DSConfig.main(args, false, System.out, System.err)
+        == SUCCESSFUL.getReturnCode());
+
+
+  }
+
+  /**
+   * Tests that multiple  "--set" option are allowed to be used with a multivalued
+   * property (see OPENDJ-255)
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testMultipleSetMultiValuedProperty()
+         throws Exception
+  {
+    String[] args =
+    {
+          "set-connection-handler-prop",
+          "--handler-name", "LDAP Connection Handler",
+          "-p",String.valueOf(TestCaseUtils.getServerAdminPort()),
+          "--trustAll",
+          "--bindDN","cn=Directory Manager",
+          "--bindPassword" , "password",
+          "--no-prompt",
+          "--set", "denied-client:1.1.1.1",
+          "--set", "denied-client:2.2.2.2"
+          
+    };
+
+     assertEquals(DSConfig.main(args, false, System.out, System.err),
+        SUCCESSFUL.getReturnCode());
+
+
+  }
+
+
+
+}
+

--
Gitblit v1.10.0