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

neil_a_wilson
15.50.2006 c933bedb75818290b5a49ca178fcfc5340dbb3c3
Update the LDAPSearch, LDAPModify, LDAPCompare, and LDAPDelete tools to rename
the "--controls" argument to "--control", since each instance only allows the
user to specify information about a single control. Issue #1009.

Update the LDAPSearch, LDAPModify, LDAPCompare, and LDAPDelete tools to allow
multiple instances of the "-J"/"--control" argument to specify multiple
arbitrary controls. Issue #1010.
7 files modified
190 ■■■■ changed files
opends/src/server/org/opends/server/tools/LDAPCompare.java 25 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPDelete.java 26 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPModify.java 25 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPSearch.java 24 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPDeleteTestCase.java 28 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPModifyTestCase.java 32 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java 30 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPCompare.java
@@ -464,7 +464,7 @@
      argParser.addArgument(assertionFilter);
      controlStr =
           new StringArgument("controls", 'J', "controls", false, false, true,
           new StringArgument("control", 'J', "control", false, true, true,
                    "{controloid[:criticality[:value|::b64value|:<filePath]]}",
                    null, null, MSGID_DESCRIPTION_CONTROLS);
      argParser.addArgument(controlStr);
@@ -698,19 +698,22 @@
    compareOptions.setVerbose(verbose.isPresent());
    compareOptions.setContinueOnError(continueOnError.isPresent());
    compareOptions.setEncoding(encodingStr.getValue());
    if(controlStr.hasValue())
    if(controlStr.isPresent())
    {
      String ctrlString = controlStr.getValue();
      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
      if(ctrl == null)
      for (String ctrlString : controlStr.getValues())
      {
        int    msgID   = MSGID_TOOL_INVALID_CONTROL_STRING;
        String message = getMessage(msgID, ctrlString);
        err.println(wrapText(message, MAX_LINE_WIDTH));
        err.println(argParser.getUsage());
        return 1;
        LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
        if(ctrl == null)
        {
          int    msgID   = MSGID_TOOL_INVALID_CONTROL_STRING;
          String message = getMessage(msgID, ctrlString);
          err.println(wrapText(message, MAX_LINE_WIDTH));
          err.println(argParser.getUsage());
          return 1;
        }
        compareOptions.getControls().add(ctrl);
      }
      compareOptions.getControls().add(ctrl);
    }
    if (assertionFilter.isPresent())
opends/src/server/org/opends/server/tools/LDAPDelete.java
@@ -440,7 +440,7 @@
      argParser.addArgument(deleteSubtree);
      controlStr =
           new StringArgument("controls", 'J', "controls", false, false, true,
           new StringArgument("control", 'J', "control", false, true, true,
                    "{controloid[:criticality[:value|::b64value|:<fileurl]]}",
                    null, null, MSGID_DESCRIPTION_CONTROLS);
      argParser.addArgument(controlStr);
@@ -591,20 +591,24 @@
    deleteOptions.setContinueOnError(continueOnError.isPresent());
    deleteOptions.setEncoding(encodingStr.getValue());
    deleteOptions.setDeleteSubtree(deleteSubtree.isPresent());
    if(controlStr.hasValue())
    if(controlStr.isPresent())
    {
      String ctrlString = controlStr.getValue();
      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
      if(ctrl == null)
      for (String ctrlString : controlStr.getValues())
      {
        int    msgID   = MSGID_TOOL_INVALID_CONTROL_STRING;
        String message = getMessage(msgID, ctrlString);
        err.println(wrapText(message, MAX_LINE_WIDTH));
        err.println(argParser.getUsage());
        return 1;
        LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
        if(ctrl == null)
        {
          int    msgID   = MSGID_TOOL_INVALID_CONTROL_STRING;
          String message = getMessage(msgID, ctrlString);
          err.println(wrapText(message, MAX_LINE_WIDTH));
          err.println(argParser.getUsage());
          return 1;
        }
        deleteOptions.getControls().add(ctrl);
      }
      deleteOptions.getControls().add(ctrl);
    }
    if(deleteOptions.getDeleteSubtree())
    {
      LDAPControl control = new LDAPControl(OID_SUBTREE_DELETE_CONTROL);
opends/src/server/org/opends/server/tools/LDAPModify.java
@@ -726,7 +726,7 @@
      argParser.addArgument(postReadAttributes);
      controlStr =
           new StringArgument("controls", 'J', "controls", false, false, true,
           new StringArgument("control", 'J', "control", false, true, true,
                    "{controloid[:criticality[:value|::b64value|:<fileurl]]}",
                    null, null, MSGID_DESCRIPTION_CONTROLS);
      argParser.addArgument(controlStr);
@@ -878,19 +878,22 @@
    modifyOptions.setContinueOnError(continueOnError.isPresent());
    modifyOptions.setEncoding(encodingStr.getValue());
    modifyOptions.setDefaultAdd(defaultAdd.isPresent());
    if(controlStr.hasValue())
    if (controlStr.isPresent())
    {
      String ctrlString = controlStr.getValue();
      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
      if(ctrl == null)
      for (String ctrlString : controlStr.getValues())
      {
        int    msgID   = MSGID_TOOL_INVALID_CONTROL_STRING;
        String message = getMessage(msgID, ctrlString);
        err.println(wrapText(message, MAX_LINE_WIDTH));
        err.println(argParser.getUsage());
        return 1;
        LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
        if(ctrl == null)
        {
          int    msgID   = MSGID_TOOL_INVALID_CONTROL_STRING;
          String message = getMessage(msgID, ctrlString);
          err.println(wrapText(message, MAX_LINE_WIDTH));
          err.println(argParser.getUsage());
          return 1;
        }
        modifyOptions.getControls().add(ctrl);
      }
      modifyOptions.getControls().add(ctrl);
    }
    if (proxyAuthzID.isPresent())
opends/src/server/org/opends/server/tools/LDAPSearch.java
@@ -702,7 +702,7 @@
      argParser.addArgument(matchedValuesFilter);
      controlStr =
           new StringArgument("controls", 'J', "controls", false, false, true,
           new StringArgument("control", 'J', "control", false, true, true,
                    "{controloid[:criticality[:value|::b64value|:<fileurl]]}",
                    null, null, MSGID_DESCRIPTION_CONTROLS);
      argParser.addArgument(controlStr);
@@ -955,19 +955,21 @@
      return 1;
    }
    if(controlStr.hasValue())
    if(controlStr.isPresent())
    {
      String ctrlString = controlStr.getValue();
      LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
      if(ctrl == null)
      for (String ctrlString : controlStr.getValues())
      {
        int    msgID   = MSGID_TOOL_INVALID_CONTROL_STRING;
        String message = getMessage(msgID, ctrlString);
        err.println(wrapText(message, MAX_LINE_WIDTH));
        err.println(argParser.getUsage());
        return 1;
        LDAPControl ctrl = LDAPToolUtils.getControl(ctrlString, err);
        if(ctrl == null)
        {
          int    msgID   = MSGID_TOOL_INVALID_CONTROL_STRING;
          String message = getMessage(msgID, ctrlString);
          err.println(wrapText(message, MAX_LINE_WIDTH));
          err.println(argParser.getUsage());
          return 1;
        }
        searchOptions.getControls().add(ctrl);
      }
      searchOptions.getControls().add(ctrl);
    }
    if (proxyAuthzID.isPresent())
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPDeleteTestCase.java
@@ -850,6 +850,34 @@
  /**
   * Tests the inclusion of multiple arbitrary controls in the request to the
   * server.
   *
   * @throws  Exception  If an unexpectd problem occurs.
   */
  @Test()
  public void testMultipleRequestControls()
         throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    String[] args =
    {
      "-h", "127.0.0.1",
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-J", OID_MANAGE_DSAIT_CONTROL + ":false",
      "-J", OID_SUBTREE_DELETE_CONTROL + ":true",
      "o=test"
    };
    assertEquals(LDAPDelete.mainDelete(args, false, null, System.err), 0);
  }
  /**
   * Tests the LDAPDelete tool with the "--help" option.
   */
  @Test()
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPModifyTestCase.java
@@ -1549,6 +1549,38 @@
  /**
   * Tests the inclusion of multiple arbitrary controls in the request to the
   * server.
   *
   * @throws  Exception  If an unexpectd problem occurs.
   */
  @Test()
  public void testMultipleRequestControls()
         throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    String path = TestCaseUtils.createTempFile(
         "dn: o=test",
         "changetype: delete");
    String[] args =
    {
      "-h", "127.0.0.1",
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-J", OID_MANAGE_DSAIT_CONTROL + ":false",
      "-J", OID_SUBTREE_DELETE_CONTROL + ":true",
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
  }
  /**
   * Tests with various forms of malformed LDIF changes.
   *
   * @throws  Exception  If an unexpected problem occurs.
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java
@@ -1350,6 +1350,36 @@
  /**
   * Tests the inclusion of multiple arbitrary controls in the request to the
   * server.
   *
   * @throws  Exception  If an unexpectd problem occurs.
   */
  @Test()
  public void testMultipleRequestControls()
         throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    String[] args =
    {
      "-h", "127.0.0.1",
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-b", "o=test",
      "-s", "base",
      "-J", OID_ACCOUNT_USABLE_CONTROL + ":true",
      "-J", OID_MANAGE_DSAIT_CONTROL + ":false",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
  }
  /**
   * Tests the LDAPSearch tool with the "--help" option.
   */
  @Test()