jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1508780 - in /jackrabbit/oak/trunk: oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java
Date Wed, 31 Jul 2013 09:12:28 GMT
Author: angela
Date: Wed Jul 31 09:12:28 2013
New Revision: 1508780

URL: http://svn.apache.org/r1508780
Log:
OAK-90 : Implement Principal Management 

- add tests for everyone group

Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java?rev=1508780&r1=1508779&r2=1508780&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/principal/PrincipalProviderImplTest.java
Wed Jul 31 09:12:28 2013
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.securi
 
 import java.security.Principal;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -25,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import com.google.common.collect.ImmutableSet;
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.User;
@@ -95,6 +97,38 @@ public class PrincipalProviderImplTest e
     }
 
     @Test
+    public void testEveryoneMembers() throws Exception {
+        Principal everyone = principalProvider.getPrincipal(EveryonePrincipal.NAME);
+        assertTrue(everyone instanceof EveryonePrincipal);
+
+        Group everyoneGroup = null;
+        try {
+            UserManager userMgr = getUserManager(root);
+            everyoneGroup = userMgr.createGroup(EveryonePrincipal.NAME);
+            root.commit();
+
+            Principal ep = principalProvider.getPrincipal(EveryonePrincipal.NAME);
+            Set<? extends Principal> everyoneMembers = ImmutableSet.copyOf(Collections.list(((java.security.acl.Group)
ep).members()));
+
+            Iterator<? extends Principal> all = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
+            while (all.hasNext()) {
+                Principal p = all.next();
+                if (everyone.equals(p)) {
+                    assertFalse(everyoneMembers.contains(p));
+                } else {
+                    assertTrue(everyoneMembers.contains(p));
+                }
+            }
+
+        } finally {
+            if (everyoneGroup != null) {
+                everyoneGroup.remove();
+                root.commit();
+            }
+        }
+    }
+
+    @Test
     public void testFindUserPrincipal() throws Exception {
         User testUser = null;
         try {

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java?rev=1508780&r1=1508779&r2=1508780&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/principal/PrincipalManagerTest.java
Wed Jul 31 09:12:28 2013
@@ -175,11 +175,14 @@ public class PrincipalManagerTest extend
     }
 
     @Test
-    public void testGroupMembers() {
+    public void testMembers() {
         PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
         while (it.hasNext()) {
             Principal p = it.nextPrincipal();
-            if (isGroup(p) && !p.equals(principalMgr.getEveryone())) {
+            if (p.equals(principalMgr.getEveryone())) {
+                continue;
+            }
+            if (isGroup(p)) {
                 Enumeration<? extends Principal> en = ((java.security.acl.Group) p).members();
                 while (en.hasMoreElements()) {
                     Principal memb = en.nextElement();
@@ -201,24 +204,28 @@ public class PrincipalManagerTest extend
         while (it.hasNext()) {
             Principal p = it.nextPrincipal();
             if (p.equals(everyone)) {
-                for (PrincipalIterator membership = principalMgr.getGroupMembership(p); membership.hasNext();)
{
-                    Principal gr = membership.nextPrincipal();
-                    assertTrue(isGroup(gr));
-                    if (gr.equals(everyone)) {
-                        fail("Everyone must never be a member of the EveryOne group.");
-                    }
-                }
-            } else {
-                boolean atleastEveryone = false;
-                for (PrincipalIterator membership = principalMgr.getGroupMembership(p); membership.hasNext();)
{
-                    Principal gr = membership.nextPrincipal();
-                    assertTrue(isGroup(gr));
-                    if (gr.equals(everyone)) {
-                        atleastEveryone = true;
-                    }
+                continue;
+            }
+            boolean atleastEveryone = false;
+            for (PrincipalIterator membership = principalMgr.getGroupMembership(p); membership.hasNext();)
{
+                Principal gr = membership.nextPrincipal();
+                assertTrue(isGroup(gr));
+                if (gr.equals(everyone)) {
+                    atleastEveryone = true;
                 }
-                assertTrue("All principals (except everyone) must be member of the everyone
group.", atleastEveryone);
+            }
+            assertTrue("All principals (except everyone) must be member of the everyone group.",
atleastEveryone);
+        }
+    }
 
+    @Test
+    public void testEveryoneGroupMembership() {
+        Principal everyone = EveryonePrincipal.getInstance();
+        for (PrincipalIterator membership = principalMgr.getGroupMembership(everyone); membership.hasNext();)
{
+            Principal gr = membership.nextPrincipal();
+            assertTrue(isGroup(gr));
+            if (gr.equals(everyone)) {
+                fail("Everyone must never be a member of the EveryOne group.");
             }
         }
     }



Mime
View raw message