From fe19ac2d6f1b978356b29e81901b91ae7a09daf9 Mon Sep 17 00:00:00 2001
From: Chris Ridd <chris.ridd@forgerock.com>
Date: Fri, 02 Oct 2015 12:39:01 +0000
Subject: [PATCH] OPENDJ-2312 Check rightsMask for all operations in setEval{User,Op}Attributes

---
 opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciTestCase.java |   73 ++++++++++++++++++++++++++++++++----
 1 files changed, 65 insertions(+), 8 deletions(-)

diff --git a/opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciTestCase.java
index a7adc51..675d984 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciTestCase.java
@@ -199,6 +199,47 @@
     return oStream.toString();
   }
 
+  /**
+   * Perform a modify operation, and request attributes via a preRead control.
+   *
+   * @param bindDn        The user to authenticate as.
+   * @param bindPassword  The user's credentials.
+   * @param ldif          The modification to make.
+   * @param attributes    A space-separated list of attributes to return.
+   *
+   * @return  The output of the command.
+   *
+   * @throws Exception  If an unexpected problem occurred.
+   */
+  protected String preReadModify(String bindDn, String bindPassword,
+                                 String ldif, String attributes) throws Exception
+  {
+    File tempFile = getTemporaryLdifFile();
+    TestCaseUtils.writeFile(tempFile, ldif);
+
+    ArrayList<String> argList=new ArrayList<>(20);
+    argList.add("-h");
+    argList.add("127.0.0.1");
+    argList.add("-p");
+    argList.add(String.valueOf(TestCaseUtils.getServerLdapPort()));
+    argList.add("-D");
+    argList.add(bindDn);
+    argList.add("-w");
+    argList.add(bindPassword);
+    if (attributes != null) {
+      argList.add("--preReadAttributes");
+      argList.add(attributes);
+    }
+    argList.add("-f");
+    argList.add(tempFile.getAbsolutePath());
+    String[] args = new String[argList.size()];
+
+    oStream.reset();
+    int retVal =LDAPModify.mainModify(argList.toArray(args), false, oStream, oStream);
+    Assert.assertEquals(retVal, 0, "Returned error: " + oStream);
+    return oStream.toString();
+  }
+
   protected String LDAPSearchCtrl(String bindDn, String bindPassword,
                             String proxyDN, String controlStr,
                             String base, String filter, String attr) {
@@ -719,26 +760,42 @@
 
   protected Map<String, String> getAttrMap(String resultString)
   {
-    StringReader r=new StringReader(resultString);
-    BufferedReader br=new BufferedReader(r);
+    return getAttrMap(resultString, false);
+  }
+
+  /**
+   * Parse a tool output for an LDIF record, returning the attributes in a Map.
+   *
+   * @param resultString The entire output from the operation
+   * @param stripHeader  Set to {@code true} if data before the LDIF needs to be ignored
+   * @return  A map of attribute-values
+   */
+  protected Map<String, String> getAttrMap(String resultString, boolean stripHeader)
+  {
+    StringReader r = new StringReader(resultString);
+    BufferedReader br = new BufferedReader(r);
+    boolean stripping = stripHeader;
     Map<String, String> attrMap = new HashMap<>();
     try {
-      while(true) {
+      while (true) {
         String s = br.readLine();
-        if(s == null)
+        if (s == null)
         {
           break;
         }
-        if(s.startsWith("dn:"))
-        {
+        if (stripping) {
+          if (s.startsWith("dn:"))
+          {
+            stripping = false;
+          }
           continue;
         }
         String[] a=s.split(": ");
-        if(a.length != 2)
+        if (a.length != 2)
         {
           break;
         }
-        attrMap.put(a[0].toLowerCase(),a[1]);
+        attrMap.put(a[0].toLowerCase(), a[1]);
       }
     } catch (IOException e) {
       Assert.fail(e.getMessage());

--
Gitblit v1.10.0