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

Jean-Noel Rouvignac
25.40.2013 3e0b1e8a22d3d074429684dedeff0d39da670d1d
AciTestCase.java:
Fixed expected/actual mismatch in asserts.

Unit tests cleanup.
Converted comments to javadocs.
Applied AutoRefactor.
5 files modified
272 ■■■■ changed files
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/AciTestCase.java 19 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/AlternateRootDN.java 45 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/GetEffectiveRightsTestCase.java 79 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/TargetAttrTestCase.java 73 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/TargetControlTestCase.java 56 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/AciTestCase.java
@@ -196,10 +196,9 @@
    }
    String[] args = new String[argList.size()];
    oStream.reset();
    int ret=
           LDAPPasswordModify.mainPasswordModify(argList.toArray(args),
    int ret = LDAPPasswordModify.mainPasswordModify(argList.toArray(args),
                   false, oStream, oStream);
    Assert.assertEquals(expectedRc, ret, "Returned error: " + oStream);
    Assert.assertEquals(ret, expectedRc, "Returned error: " + oStream);
    return oStream.toString();
  }
@@ -236,7 +235,7 @@
    oStream.reset();
    int retVal =
            LDAPSearch.mainSearch(argList.toArray(args), false, oStream, oStream);
    Assert.assertEquals(0, retVal, "Returned error: " + oStream);
    Assert.assertEquals(retVal, 0, "Returned error: " + oStream);
    return oStream.toString();
  }
@@ -373,7 +372,7 @@
  {
    oStream.reset();
    int retVal = LDAPDelete.mainDelete(args, false, oStream, oStream);
    Assert.assertEquals(expectedRc, retVal, "Returned error: " + oStream);
    Assert.assertEquals(retVal, expectedRc, "Returned error: " + oStream);
  }
@@ -437,7 +436,7 @@
    oStream.reset();
    int retVal =LDAPModify.mainModify(args, false, oStream, oStream);
    if (expectedRc != -1)
      Assert.assertEquals(expectedRc, retVal, "Returned error: " + oStream);
      Assert.assertEquals(retVal, expectedRc, "Returned error: " + oStream);
  }
  protected void deleteAttrFromEntry(String dn, String attr) throws Exception {
@@ -691,11 +690,11 @@
            "ds-privilege-name: proxied-auth");
  }
  protected HashMap<String, String>
  getAttrMap(String resultString) {
  protected Map<String, String> getAttrMap(String resultString)
  {
    StringReader r=new StringReader(resultString);
    BufferedReader br=new BufferedReader(r);
    HashMap<String, String> attrMap = new HashMap<String,String>();
    Map<String, String> attrMap = new HashMap<String, String>();
    try {
      while(true) {
        String s = br.readLine();
@@ -709,7 +708,7 @@
        attrMap.put(a[0].toLowerCase(),a[1]);
      }
    } catch (IOException e) {
      Assert.assertEquals(0, 1,  e.getMessage());
      Assert.fail(e.getMessage());
    }
    return attrMap;
  }
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/AlternateRootDN.java
@@ -23,24 +23,24 @@
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS
 */
package org.opends.server.authorization.dseecompat;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.Assert;
import static org.opends.server.config.ConfigConstants.*;
import java.util.HashMap;
import static org.opends.server.util.ServerConstants.*;
import java.util.Map;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
 * This class tests ACI behavior using alternate root bind DNs.
 */
@SuppressWarnings("javadoc")
public class AlternateRootDN extends AciTestCase {
  private static final String user1="uid=user.1,ou=People,o=test";
@@ -55,7 +55,8 @@
       "(version 3.0; acl \"proxy" +  user3 + "\";" +
       "allow (proxy) userdn=\"ldap:///" + user3 + "\";)";
  //Need an ACI to allow proxy control
  /** Need an ACI to allow proxy control */
  private static final
  String controlACI = "(targetcontrol=\"" + OID_PROXIED_AUTH_V2 + "\")" +
          "(version 3.0; acl \"control\";" +
          "allow(read) userdn=\"ldap:///" + user3 + "\";)";
@@ -96,20 +97,20 @@
    String adminDNResults =
            LDAPSearchParams(adminDN, PWD, null, null, null,
                    user1, pwdFilter, ATTR_USER_PASSWORD);
    Assert.assertFalse(adminDNResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(adminDNResults);
    Assert.assertFalse("".equals(adminDNResults));
    Map<String, String> attrMap = getAttrMap(adminDNResults);
    Assert.assertTrue(attrMap.containsKey(ATTR_USER_PASSWORD));
    String adminRootDNResults =
            LDAPSearchParams(adminRootDN, PWD, null, null, null,
                    user1, pwdFilter, ATTR_USER_PASSWORD);
    Assert.assertFalse(adminRootDNResults.equals(""));
    HashMap<String, String> attrMap1=getAttrMap(adminRootDNResults);
    Assert.assertFalse("".equals(adminRootDNResults));
    Map<String, String> attrMap1 = getAttrMap(adminRootDNResults);
    Assert.assertTrue(attrMap1.containsKey(ATTR_USER_PASSWORD));
    String rootDNResults =
            LDAPSearchParams(rootDN, PWD, null, null, null,
                    user1, pwdFilter, ATTR_USER_PASSWORD);
    Assert.assertFalse(rootDNResults.equals(""));
    HashMap<String, String> attrMap2=getAttrMap(rootDNResults);
    Assert.assertFalse("".equals(rootDNResults));
    Map<String, String> attrMap2 = getAttrMap(rootDNResults);
    Assert.assertTrue(attrMap2.containsKey(ATTR_USER_PASSWORD));
    deleteAttrFromEntry(user1, "aci");
  }
@@ -133,20 +134,20 @@
    String adminDNResults =
            LDAPSearchParams(user3, PWD, adminDN, null, null,
                    user1, pwdFilter, ATTR_USER_PASSWORD);
    Assert.assertFalse(adminDNResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(adminDNResults);
    Assert.assertFalse("".equals(adminDNResults));
    Map<String, String> attrMap = getAttrMap(adminDNResults);
    Assert.assertTrue(attrMap.containsKey(ATTR_USER_PASSWORD));
    String adminRootDNResults =
            LDAPSearchParams(user3, PWD, adminRootDN, null, null,
                    user1, pwdFilter, ATTR_USER_PASSWORD);
    Assert.assertFalse(adminRootDNResults.equals(""));
    HashMap<String, String> attrMap1=getAttrMap(adminRootDNResults);
    Assert.assertFalse("".equals(adminRootDNResults));
    Map<String, String> attrMap1 = getAttrMap(adminRootDNResults);
    Assert.assertTrue(attrMap1.containsKey(ATTR_USER_PASSWORD));
    String rootDNResults =
            LDAPSearchParams(user3, PWD, adminDN, null, null,
                    user1, pwdFilter, ATTR_USER_PASSWORD);
    Assert.assertFalse(rootDNResults.equals(""));
    HashMap<String, String> attrMap2=getAttrMap(rootDNResults);
    Assert.assertFalse("".equals(rootDNResults));
    Map<String, String> attrMap2 = getAttrMap(rootDNResults);
    Assert.assertTrue(attrMap2.containsKey(ATTR_USER_PASSWORD));
    deleteAttrFromEntry(user1, "aci");
  }
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/GetEffectiveRightsTestCase.java
@@ -23,20 +23,23 @@
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS
 */
package org.opends.server.authorization.dseecompat;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.util.ServerConstants.*;
import java.util.Map;
import org.testng.Assert;
import static org.opends.server.util.ServerConstants.OID_GET_EFFECTIVE_RIGHTS;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.HashMap;
@SuppressWarnings("javadoc")
public class GetEffectiveRightsTestCase extends AciTestCase {
  private static final String base="uid=user.3,ou=People,o=test";
  private static final String user1="uid=user.1,ou=People,o=test";
  private static final String superUser="uid=superuser,ou=admins,o=test";
@@ -45,7 +48,7 @@
  private static final String entryLevel = "aclRights;entryLevel";
  private static final String attributeLevel = "aclRights;attributeLevel;";
  //Various results for entryLevel searches.
  /** Various results for entryLevel searches. */
  private static final
  String bypassRights = "add:1,delete:1,read:1,write:1,proxy:1";
@@ -64,7 +67,7 @@
  private static final
  String allRights = "add:1,delete:1,read:1,write:1,proxy:1";
  //Results for attributeLevel searches
  /** Results for attributeLevel searches. */
  private static final String srwMailAttrRights =
          "search:1,read:1,compare:0,write:1," +
          "selfwrite_add:0,selfwrite_delete:0,proxy:0";
@@ -87,7 +90,7 @@
  //ACI needed to search/read aciRights attribute.
  //Need an ACI to allow proxy control
  /** Need an ACI to allow proxy control. */
  String controlACI = "(targetcontrol=\"" + OID_GET_EFFECTIVE_RIGHTS + "\")" +
          "(version 3.0; acl \"control\";" +
          "allow(read) userdn=\"ldap:///anyone\";)";
@@ -98,22 +101,21 @@
          "allow (search, read) " +
          "userdn=\"ldap:///uid=superuser,ou=admins,o=test\";)";
  //General ACI superuser to search/read.
  /** General ACI superuser to search/read. */
  private static final
  String readSearchAci = "(targetattr=\"*\")" +
          "(version 3.0;acl \"read/search access\";" +
          "allow (search, read) " +
          "userdn=\"ldap:///uid=superuser,ou=admins,o=test\";)";
  //General ACI for anonymous test.
  /** General ACI for anonymous test. */
  private static final
  String readSearchAnonAci = "(targetattr=\"*\")" +
          "(version 3.0;acl \"anonymous read/search access\";" +
          "allow (search, read) " +
          "userdn=\"ldap:///anyone\";)";
  //Test ACIs.
  /** Test ACIs. */
  private static final
  String addAci = "(version 3.0;acl \"add access\";" +
          "allow (add) " +
@@ -183,10 +185,9 @@
    String userResults =
            LDAPSearchParams(DIR_MGR_DN, PWD, null, "dn:", null,
                    base, filter, "aclRights");
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    checkEntryLevel(attrMap, rRights);
  }
  /**
@@ -204,15 +205,15 @@
    String userResults =
            LDAPSearchParams(superUser, PWD, null, "dn: " + superUser, null,
                    base, filter, "aclRights");
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    checkEntryLevel(attrMap, rRights);
    aciLdif=makeAddLDIF("aci", "ou=People,o=test", addAci);
    LDIFModify(aciLdif, DIR_MGR_DN, PWD);
    userResults =
            LDAPSearchParams(superUser, PWD, null, "dn: " + superUser, null,
                    base, filter, "aclRights");
    Assert.assertFalse(userResults.equals(""));
    Assert.assertFalse("".equals(userResults));
    attrMap=getAttrMap(userResults);
    checkEntryLevel(attrMap, arRights);
    aciLdif=makeAddLDIF("aci", "ou=People,o=test", delAci);
@@ -220,7 +221,7 @@
    userResults =
            LDAPSearchParams(superUser, PWD, null, "dn: " + superUser, null,
                    base, filter, "aclRights");
    Assert.assertFalse(userResults.equals(""));
    Assert.assertFalse("".equals(userResults));
    attrMap=getAttrMap(userResults);
    checkEntryLevel(attrMap, adrRights);
    aciLdif=makeAddLDIF("aci", "ou=People,o=test", writeAci);
@@ -228,7 +229,7 @@
    userResults =
            LDAPSearchParams(superUser, PWD, null, "dn: " + superUser, null,
                    base, filter, "aclRights");
    Assert.assertFalse(userResults.equals(""));
    Assert.assertFalse("".equals(userResults));
    attrMap=getAttrMap(userResults);
    checkEntryLevel(attrMap, adrwRights);
    aciLdif=makeAddLDIF("aci", "ou=People,o=test", proxyAci);
@@ -236,7 +237,7 @@
    userResults =
            LDAPSearchParams(superUser, PWD, null, "dn: " + superUser, null,
                    base, filter, "aclRights");
    Assert.assertFalse(userResults.equals(""));
    Assert.assertFalse("".equals(userResults));
    attrMap=getAttrMap(userResults);
    checkEntryLevel(attrMap, allRights);
  }
@@ -257,15 +258,15 @@
     String userResults =
            LDAPSearchCtrl(superUser, PWD, null, OID_GET_EFFECTIVE_RIGHTS,
                    base, filter, "aclRights");
     Assert.assertFalse(userResults.equals(""));
     HashMap<String, String> attrMap=getAttrMap(userResults);
     Assert.assertFalse("".equals(userResults));
     Map<String, String> attrMap = getAttrMap(userResults);
     checkEntryLevel(attrMap, rRights);
     aciLdif=makeAddLDIF("aci", "ou=People,o=test", addAci);
     LDIFModify(aciLdif, DIR_MGR_DN, PWD);
     userResults =
            LDAPSearchCtrl(superUser, PWD, null, OID_GET_EFFECTIVE_RIGHTS,
                    base, filter, "aclRights");
     Assert.assertFalse(userResults.equals(""));
     Assert.assertFalse("".equals(userResults));
     attrMap=getAttrMap(userResults);
     checkEntryLevel(attrMap, arRights);
     aciLdif=makeAddLDIF("aci", "ou=People,o=test", delAci);
@@ -273,7 +274,7 @@
     userResults =
            LDAPSearchCtrl(superUser, PWD, null, OID_GET_EFFECTIVE_RIGHTS,
                    base, filter, "aclRights");
     Assert.assertFalse(userResults.equals(""));
     Assert.assertFalse("".equals(userResults));
     attrMap=getAttrMap(userResults);
     checkEntryLevel(attrMap, adrRights);
     aciLdif=makeAddLDIF("aci", "ou=People,o=test", writeAci);
@@ -281,7 +282,7 @@
     userResults =
            LDAPSearchCtrl(superUser, PWD, null, OID_GET_EFFECTIVE_RIGHTS,
                    base, filter, "aclRights");
     Assert.assertFalse(userResults.equals(""));
     Assert.assertFalse("".equals(userResults));
     attrMap=getAttrMap(userResults);
     checkEntryLevel(attrMap, adrwRights);
     aciLdif=makeAddLDIF("aci", "ou=People,o=test", proxyAci);
@@ -289,7 +290,7 @@
     userResults =
             LDAPSearchCtrl(superUser, PWD, null, OID_GET_EFFECTIVE_RIGHTS,
                     base, filter, "aclRights");
     Assert.assertFalse(userResults.equals(""));
     Assert.assertFalse("".equals(userResults));
     attrMap=getAttrMap(userResults);
     checkEntryLevel(attrMap, allRights);
   }
@@ -307,8 +308,8 @@
    String userResults =
           LDAPSearchCtrl(DIR_MGR_DN, PWD, null, OID_GET_EFFECTIVE_RIGHTS,
                   base, filter, "aclRights");
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    checkEntryLevel(attrMap, bypassRights);
  }
@@ -331,8 +332,8 @@
    String userResults =
            LDAPSearchParams(superUser, PWD, null, "dn: " + superUser, null,
                    base, filter, "aclRights mail description");
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    checkAttributeLevel(attrMap, "mail", srwMailAttrRights);
    checkAttributeLevel(attrMap, "description", srDescrptionAttrRights);
  }
@@ -362,8 +363,8 @@
  String userResults =
          LDAPSearchParams(superUser, PWD, null, "dn: " + superUser, attrList,
                  base, filter, "aclRights mail description");
  Assert.assertFalse(userResults.equals(""));
  HashMap<String, String> attrMap=getAttrMap(userResults);
  Assert.assertFalse("".equals(userResults));
  Map<String, String> attrMap = getAttrMap(userResults);
  checkAttributeLevel(attrMap, "mail", srwMailAttrRights);
  checkAttributeLevel(attrMap, "description", srDescrptionAttrRights);
  checkAttributeLevel(attrMap, "fax", srxFaxAttrRights);
@@ -391,13 +392,13 @@
  String userResults =
          LDAPSearchParams(superUser, PWD, null, "dn: " + user1, memberAttrList,
                  base, filter, "aclRights");
  Assert.assertFalse(userResults.equals(""));
  HashMap<String, String> attrMap=getAttrMap(userResults);
  Assert.assertFalse("".equals(userResults));
  Map<String, String> attrMap = getAttrMap(userResults);
  checkAttributeLevel(attrMap, "member", selfWriteAttrRights);
}
 private void
 checkAttributeLevel(HashMap<String, String> attrMap, String attr,
 checkAttributeLevel(Map<String, String> attrMap, String attr,
                     String reqRightsStr) throws Exception {
   String attrType=attributeLevel.toLowerCase() + attr;
   String retRightsStr=attrMap.get(attrType);
@@ -405,7 +406,7 @@
 }
 private void
 checkEntryLevel(HashMap<String, String> attrMap, String reqRightsStr)
 checkEntryLevel(Map<String, String> attrMap, String reqRightsStr)
 throws Exception {
    String retRightsStr=attrMap.get(entryLevel.toLowerCase());
    Assert.assertTrue(retRightsStr.equals(reqRightsStr));
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/TargetAttrTestCase.java
@@ -23,13 +23,14 @@
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2012 ForgeRock AS
 *      Portions Copyright 2012-2013 ForgeRock AS
 */
package org.opends.server.authorization.dseecompat;
import java.util.HashMap;
import static org.opends.server.config.ConfigConstants.*;
import java.util.Map;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.AttributeType;
import org.testng.Assert;
@@ -37,6 +38,7 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class TargetAttrTestCase extends AciTestCase {
  private static String attrList="sn uid l";
@@ -44,7 +46,7 @@
  private static String opAttrList="sn uid aci";
  private static final String user1="uid=user.1,ou=People,o=test";
  private static final String user3="uid=user.3,ou=People,o=test";
  public  static final String aciFilter = "(aci=*)";
  private static final String aciFilter = "(aci=*)";
  private static final
@@ -138,16 +140,16 @@
    String userResults =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, attrList);
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    checkAttributeVal(attrMap, "l", "Austin");
    checkAttributeVal(attrMap, "sn", "1");
    checkAttributeVal(attrMap, "uid", "user.1");
    String userResults1 =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, attrList1);
    Assert.assertFalse(userResults1.equals(""));
    HashMap<String, String> attrMap1=getAttrMap(userResults1);
    Assert.assertFalse("".equals(userResults1));
    Map<String, String> attrMap1 = getAttrMap(userResults1);
    checkAttributeVal(attrMap1, "sn", "1");
    checkAttributeVal(attrMap1, "uid", "user.1");
    deleteAttrFromEntry(user1, "aci");
@@ -156,8 +158,8 @@
    String userResults2 =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, attrList);
    Assert.assertFalse(userResults2.equals(""));
    HashMap<String, String> attrMap2=getAttrMap(userResults2);
    Assert.assertFalse("".equals(userResults2));
    Map<String, String> attrMap2 = getAttrMap(userResults2);
    checkAttributeVal(attrMap2, "l", "Austin");
    checkAttributeVal(attrMap2, "sn", "1");
    checkAttributeVal(attrMap2, "uid", "user.1");
@@ -177,8 +179,8 @@
    String userResults =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, opAttrList);
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    //The aci attribute type is operational, it should not be there.
    //The other two should be there.
    Assert.assertFalse(attrMap.containsKey("aci"));
@@ -192,8 +194,8 @@
    String userResults1 =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, opAttrList);
    Assert.assertFalse(userResults1.equals(""));
    HashMap<String, String> attrMap1=getAttrMap(userResults1);
    Assert.assertFalse("".equals(userResults1));
    Map<String, String> attrMap1 = getAttrMap(userResults1);
    //All three attributes should be there.
    Assert.assertTrue(attrMap1.containsKey("aci"));
    Assert.assertTrue(attrMap1.containsKey("sn"));
@@ -205,10 +207,9 @@
    String userResults2 =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, aciFilter, opAttrList);
    Assert.assertFalse(userResults2.equals(""));
    HashMap<String, String> attrMap2=getAttrMap(userResults2);
    //Only operational attribute aci should be there, the other two should
    //not.
    Assert.assertFalse("".equals(userResults2));
    Map<String, String> attrMap2 = getAttrMap(userResults2);
    // Only operational attribute aci should be there, the other two should not.
    Assert.assertTrue(attrMap2.containsKey("aci"));
    Assert.assertFalse(attrMap2.containsKey("sn"));
    Assert.assertFalse(attrMap2.containsKey("uid"));
@@ -229,8 +230,8 @@
    String userResults =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, opAttrList);
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    //All should be returned.
    Assert.assertTrue(attrMap.containsKey("aci"));
    Assert.assertTrue(attrMap.containsKey("sn"));
@@ -253,8 +254,8 @@
    String userResults =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, opAttrList);
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    //Only aci should be returned.
    Assert.assertTrue(attrMap.containsKey("aci"));
    Assert.assertFalse(attrMap.containsKey("sn"));
@@ -277,8 +278,8 @@
    String userResults =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, opAttrList);
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    //All should be returned.
    Assert.assertTrue(attrMap.containsKey("aci"));
    Assert.assertTrue(attrMap.containsKey("sn"));
@@ -302,8 +303,8 @@
    String userResults =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, aciFilter, opAttrList);
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    //All should be returned.
    Assert.assertTrue(attrMap.containsKey("aci"));
    Assert.assertTrue(attrMap.containsKey("sn"));
@@ -315,8 +316,8 @@
    String userResults1 =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, aciFilter, opAttrList);
    Assert.assertFalse(userResults1.equals(""));
    HashMap<String, String> attrMap1=getAttrMap(userResults1);
    Assert.assertFalse("".equals(userResults1));
    Map<String, String> attrMap1 = getAttrMap(userResults1);
    //All should be returned.
    Assert.assertTrue(attrMap1.containsKey("aci"));
    Assert.assertTrue(attrMap1.containsKey("sn"));
@@ -328,8 +329,8 @@
    String userResults2 =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, opAttrList);
    Assert.assertFalse(userResults2.equals(""));
    HashMap<String, String> attrMap2=getAttrMap(userResults2);
    Assert.assertFalse("".equals(userResults2));
    Map<String, String> attrMap2 = getAttrMap(userResults2);
    //Only non-operation should be returned.
    Assert.assertFalse(attrMap2.containsKey("aci"));
    Assert.assertTrue(attrMap2.containsKey("sn"));
@@ -349,8 +350,8 @@
    String userResults =
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, attrList);
    Assert.assertFalse(userResults.equals(""));
    HashMap<String, String> attrMap=getAttrMap(userResults);
    Assert.assertFalse("".equals(userResults));
    Map<String, String> attrMap = getAttrMap(userResults);
    Assert.assertTrue(attrMap.containsKey("l"));
    Assert.assertTrue(attrMap.containsKey("sn"));
    Assert.assertTrue(attrMap.containsKey("uid"));
@@ -361,19 +362,17 @@
            LDAPSearchParams(user3, PWD, null, null, null,
                    user1, filter, attrList);
    //This search should return nothing since the URL has a bogus DN.
    Assert.assertTrue(userResults1.equals(""));
    Assert.assertTrue("".equals(userResults1));
  }
  private void
  checkAttributeVal(HashMap<String, String> attrMap, String attr,
  checkAttributeVal(Map<String, String> attrMap, String attr,
                      String val) throws Exception {
    String mapVal=attrMap.get(attr);
    Assert.assertTrue(mapVal.equals(val));
  }
  /*
   * New tests to really unit test the isApplicable method.
   */
  /** New tests to really unit test the isApplicable method. */
  @DataProvider(name = "targetAttrData")
  public Object[][] createData() throws Exception {
    return new Object[][] {
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/TargetControlTestCase.java
@@ -23,22 +23,23 @@
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 *      Portions copyright 2012-2013 ForgeRock AS.
 */
package org.opends.server.authorization.dseecompat;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.util.ServerConstants.*;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.*;
import org.opends.server.protocols.ldap.LDAPResultCode;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.config.ConfigConstants.ATTR_AUTHZ_GLOBAL_ACI;
/**
 * Unit test to test the targetcontrol ACI keyword.
 */
@SuppressWarnings("javadoc")
public class TargetControlTestCase extends AciTestCase {
  private static final String superUser="uid=superuser,ou=admins,o=test";
@@ -86,7 +87,7 @@
    "userPassword: password",
  };
  //Valid targetcontrol statements. Not the complete ACI.
  /** Valid targetcontrol statements. Not the complete ACI. */
  @DataProvider(name = "validStatements")
  public Object[][] valids() {
    return new Object[][] {
@@ -96,7 +97,7 @@
    };
  }
   //Invalid targetcontrol statements. Not the complete ACI.
  /** Invalid targetcontrol statements. Not the complete ACI. */
  @DataProvider(name = "invalidStatements")
  public Object[][] invalids() {
    return new Object[][] {
@@ -120,19 +121,21 @@
          "allow (search, read) " +
          "userdn=\"ldap:///uid=superuser,ou=admins,o=test\";)";
 //Disallow all controls with wild-card.
  /** Disallow all controls with wild-card. */
  private static final
  String controlNotWC = "(targetcontrol!=\"" + "*" + "\")" +
          "(version 3.0; acl \"control\";" +
          "allow(read) userdn=\"ldap:///" + superUser + "\";)";
  //Allow all controls with wild-card.
  /** Allow all controls with wild-card. */
  private static final
  String controlWC = "(targetcontrol=\"" + "*" + "\")" +
          "(version 3.0; acl \"control\";" +
          "allow(read) userdn=\"ldap:///" + superUser + "\";)";
  //People branch can do any control but geteffectiverights assertion control.
  /**
   * People branch can do any control but geteffectiverights assertion control.
   */
  private static final
  String controlPeople = "(targetcontrol!=\"" +
          OID_GET_EFFECTIVE_RIGHTS + "\")" +
@@ -140,15 +143,17 @@
          "(version 3.0; acl \"control\";" +
          "allow(read) userdn=\"ldap:///" + "anyone" + "\";)";
  //Admin branch can only do geteffectiverights control.
  /** Admin branch can only do geteffectiverights control. */
  private static final
  String controlAdmin = "(targetcontrol=\"" + OID_GET_EFFECTIVE_RIGHTS + "\")" +
          "(target=\"ldap:///" + adminBase + "\")" +
          "(version 3.0; acl \"control\";" +
          "allow(read) userdn=\"ldap:///" + "anyone" + "\";)";
  //Allow either reportauthzID or passwordpolicy controls. Used in the
  //bind tests.
  /**
   * Allow either reportauthzID or passwordpolicy controls. Used in the bind
   * tests.
   */
  private static final
  String pwdControls =
          "(targetcontrol=\"" + OID_AUTHZID_REQUEST + "||" +
@@ -157,8 +162,9 @@
          "allow(read) userdn=\"ldap:///" + "anyone" + "\";)";
  //Allow either no-op or passwordpolicy controls. Used in the
  //ext op tests.
  /**
   * Allow either no-op or passwordpolicy controls. Used in the extop tests.
   */
  private static final
  String extOpControls =
          "(targetcontrol=\"" + OID_LDAP_NOOP_OPENLDAP_ASSIGNED + "||" +
@@ -166,15 +172,17 @@
          "(version 3.0; acl \"control\";" +
          "allow(read) userdn=\"ldap:///" + "anyone" + "\";)";
 //Allow all to extended op.
  /** Allow all to extended op. */
  private static final
  String extOpAll =
          "(extop=\"" + "*" + "\")" +
          "(version 3.0; acl \"control\";" +
          "allow(read) userdn=\"ldap:///" + "anyone" + "\";)";
  //Only allow access to the password policy control. Used to test if the
  //targetattr rule will give access erroneously.
  /**
   * Only allow access to the password policy control. Used to test if the
   * targetattr rule will give access erroneously.
   */
  private static final
  String complicated =
          "(targetcontrol=\"" + OID_PASSWORD_POLICY_CONTROL + "\")" +
@@ -222,14 +230,13 @@
   *
   * @throws Exception If an unexpected result is returned.
   */
  @Test()
  public void testTargetattrSideEffect() throws Exception {
   String pwdLdifs =
        makeAddLDIF("aci", peopleBase, complicated);
    LDIFModify(pwdLdifs, DIR_MGR_DN, PWD);
    String noOpCtrlStr=OID_LDAP_NOOP_OPENLDAP_ASSIGNED + ":true";
    //This should fail beacause this ACI only allows acces to the
    // This should fail because this ACI only allows access to the
    //password policy control.
    pwdModify(level4User, PWD, newPWD, noOpCtrlStr, null,
            LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS);
@@ -287,7 +294,7 @@
  /**
   * Test target from global ACI level. Two global ACIs are added, one allowing
   * all controls except geteffective rights to the ou=people, o=test
   * all controls except geteffectiverights to the ou=people, o=test
   * suffix. The other ACI only allows the geteffectiverights control on
   * the ou=admin, o=test suffix. Comments in method should explain more
   * what operations and controls are attempted.
@@ -306,7 +313,7 @@
            "dn: " + level1User, null,
            level1User, filter, "aclRights mail description",
            false, false, 0);
    //Ok because geteffectiverights control is allowed on
    //OK because geteffectiverights control is allowed on
    //ou=admin, o=test
    LDAPSearchParams(level3User, PWD, null,
            "dn: " + level1User, null,
@@ -338,7 +345,6 @@
   */
  @Test()
  public void testWildCard() throws Exception {
    String aciDeny=makeAddLDIF("aci", base, controlNotWC);
    String aciRight=makeAddLDIF("aci", base, aclRightsAci);
    LDIFModify(aciDeny, DIR_MGR_DN, PWD);