jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1390380 - in /jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user: AuthorizableImplTest.java UserImplTest.java UserManagerImplTest.java
Date Wed, 26 Sep 2012 10:29:57 GMT
Author: angela
Date: Wed Sep 26 10:29:57 2012
New Revision: 1390380

URL: http://svn.apache.org/viewvc?rev=1390380&view=rev
Log:
OAK-50 : Implement User Management (WIP)

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImplTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImplTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImplTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImplTest.java?rev=1390380&r1=1390379&r2=1390380&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableImplTest.java
Wed Sep 26 10:29:57 2012
@@ -16,14 +16,12 @@
  */
 package org.apache.jackrabbit.oak.jcr.security.user;
 
-import org.apache.jackrabbit.api.security.user.Authorizable;
-import org.apache.jackrabbit.api.security.user.Group;
-import org.apache.jackrabbit.api.security.user.UserManager;
-import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
-import org.apache.jackrabbit.test.NotExecutableException;
-import org.apache.jackrabbit.value.StringValue;
-import org.junit.Test;
-
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
@@ -33,12 +31,14 @@ import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.nodetype.ConstraintViolationException;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.value.StringValue;
+import org.junit.Test;
 
 /**
  * AuthorizableImplTest...
@@ -65,10 +65,13 @@ public class AuthorizableImplTest extend
     }
 
     @Test
-    public void testRemoveAdmin() {
+    public void testRemoveAdmin() throws NotExecutableException {
         String adminID = superuser.getUserID();
         try {
             Authorizable admin = userMgr.getAuthorizable(adminID);
+            if (admin == null) {
+                throw new NotExecutableException("Admin user does not exist");
+            }
             admin.remove();
             fail("The admin user cannot be removed.");
         } catch (RepositoryException e) {
@@ -87,6 +90,8 @@ public class AuthorizableImplTest extend
                 fail("changing the '" + pName + "' property on a User should fail.");
             } catch (RepositoryException e) {
                 // success
+            } finally {
+                superuser.refresh(false);
             }
         }
 
@@ -97,6 +102,8 @@ public class AuthorizableImplTest extend
                 fail("changing the '" + pName + "' property on a Group should fail.");
             } catch (RepositoryException e) {
                 // success
+            } finally {
+                superuser.refresh(false);
             }
         }
     }
@@ -110,6 +117,8 @@ public class AuthorizableImplTest extend
                 fail("removing the '" + pName + "' property on a User should fail.");
             } catch (RepositoryException e) {
                 // success
+            } finally {
+                superuser.refresh(false);
             }
         }
         for (String pName : protectedGroupProps) {
@@ -119,6 +128,8 @@ public class AuthorizableImplTest extend
                 fail("removing the '" + pName + "' property on a Group should fail.");
             } catch (RepositoryException e) {
                 // success
+            } finally {
+                superuser.refresh(false);
             }
         }
     }
@@ -128,7 +139,9 @@ public class AuthorizableImplTest extend
         UserImpl user = (UserImpl) getTestUser(superuser);
         Node n = user.getNode();
 
-        checkProtected(n.getProperty(UserConstants.REP_PASSWORD));
+        if (n.hasProperty(UserConstants.REP_PASSWORD)) {
+            checkProtected(n.getProperty(UserConstants.REP_PASSWORD));
+        }
         if (n.hasProperty(UserConstants.REP_PRINCIPAL_NAME)) {
             checkProtected(n.getProperty(UserConstants.REP_PRINCIPAL_NAME));
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImplTest.java?rev=1390380&r1=1390379&r2=1390380&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserImplTest.java
Wed Sep 26 10:29:57 2012
@@ -16,17 +16,17 @@
  */
 package org.apache.jackrabbit.oak.jcr.security.user;
 
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
 import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.junit.Test;
 
-import javax.jcr.LoginException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-
 /**
  * UserTest...
  */
@@ -46,8 +46,13 @@ public class UserImplTest extends Abstra
     @Test
     public void testIsAdmin() throws NotExecutableException, RepositoryException {
         assertFalse(user.isAdmin());
+    }
 
+    public void testAdminIsAdmin() throws NotExecutableException, RepositoryException {
         User admin = (User) userMgr.getAuthorizable(superuser.getUserID());
+        if (admin == null) {
+            throw new NotExecutableException("Admin user does not exist");
+        }
         assertTrue(admin.isAdmin());
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImplTest.java?rev=1390380&r1=1390379&r2=1390380&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImplTest.java
Wed Sep 26 10:29:57 2012
@@ -54,6 +54,30 @@ public class UserManagerImplTest extends
     }
 
     @Test
+    public void testGetNewAuthorizable() throws RepositoryException, NotExecutableException
{
+        String uid = "testGetNewAuthorizable";
+        User user = userMgr.createUser(uid, uid);
+
+        assertEquals(uid, user.getID());
+        assertNotNull(userMgr.getAuthorizable(uid));
+        assertEquals(user,  userMgr.getAuthorizable(uid));
+
+        assertNotNull(((UserImpl) user).getTree());
+    }
+
+    public void testGetAuthorizable() throws RepositoryException, NotExecutableException
{
+        String uid = "testGetNewAuthorizable";
+        User user = userMgr.createUser(uid, uid);
+        superuser.save();
+
+        assertEquals(uid, user.getID());
+        assertNotNull(userMgr.getAuthorizable(uid));
+        assertEquals(user,  userMgr.getAuthorizable(uid));
+
+        assertNotNull(((UserImpl) user).getTree());
+    }
+
+    @Test
     public void testGetAuthorizableByPath() throws RepositoryException, NotExecutableException
{
         String uid = superuser.getUserID();
         Authorizable a = userMgr.getAuthorizable(uid);
@@ -728,7 +752,7 @@ public class UserManagerImplTest extends
 
     @Test
     public void testEnforceAuthorizableFolderHierarchy() throws RepositoryException {
-        Authorizable auth = userMgr.getAuthorizable(superuser.getUserID());
+        Authorizable auth = userMgr.getAuthorizable(user.getID());
         Node userNode = superuser.getNode(auth.getPath());
 
         Node folder = userNode.addNode("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
@@ -739,6 +763,8 @@ public class UserManagerImplTest extends
             try {
                 Principal p = getTestPrincipal();
                 a = userMgr.createUser(p.getName(), p.getName(), p, path);
+                superuser.save();
+
                 fail("Users may not be nested.");
             } catch (RepositoryException e) {
                 // success
@@ -748,6 +774,7 @@ public class UserManagerImplTest extends
                 }
             }
         } finally {
+            superuser.refresh(false);
             if (superuser.nodeExists(path)) {
                 folder.remove();
                 superuser.save();
@@ -762,6 +789,8 @@ public class UserManagerImplTest extends
             try {
                 Principal p = getTestPrincipal();
                 a = userMgr.createUser(p.getName(), p.getName(), p, someContent.getPath());
+                superuser.save();
+
                 fail("Users may not be nested.");
             } catch (RepositoryException e) {
                 // success
@@ -781,6 +810,8 @@ public class UserManagerImplTest extends
             try {
                 Principal p = getTestPrincipal();
                 a = userMgr.createUser(p.getName(), p.getName(), p, folder.getPath());
+                superuser.save();
+
                 fail("Users may not be nested.");
             } catch (RepositoryException e) {
                 // success
@@ -812,13 +843,33 @@ public class UserManagerImplTest extends
                 User user = userMgr.createUser(uid, "pw", p, path);
                 superuser.save();
 
-                fail("intermediate path may not point outside of the user tree.");
+                fail("intermediate path '"+ path +"' outside of the user tree.");
                 user.remove();
                 superuser.save();
 
             } catch (Exception e) {
                 // success
                 assertNull(userMgr.getAuthorizable(uid));
+            } finally {
+                superuser.refresh(false);
+            }
+        }
+    }
+
+    @Test
+    public void testCreateWithAbsoluteIntermediatePath() throws Exception {
+        Principal p = getTestPrincipal();
+        String uid = p.getName();
+
+        User test = null;
+        try {
+            test = userMgr.createUser(uid, "pw", p, UserConstants.DEFAULT_USER_PATH + "/test");
+            superuser.save();
+            assertTrue(test.getPath().startsWith(UserConstants.DEFAULT_USER_PATH + "/test"));
+        } finally {
+            if (test != null) {
+                test.remove();
+                superuser.save();
             }
         }
     }



Mime
View raw message