jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r651182 - in /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security: AccessManagerTest.java authorization/AbstractEvaluationTest.java jsr283/security/AbstractAccessControlTest.java
Date Thu, 24 Apr 2008 08:01:58 GMT
Author: angela
Date: Thu Apr 24 01:01:54 2008
New Revision: 651182

URL: http://svn.apache.org/viewvc?rev=651182&view=rev
Log:
tests

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/AccessManagerTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/jsr283/security/AbstractAccessControlTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/AccessManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/AccessManagerTest.java?rev=651182&r1=651181&r2=651182&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/AccessManagerTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/AccessManagerTest.java
Thu Apr 24 01:01:54 2008
@@ -21,12 +21,14 @@
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.PropertyImpl;
 import org.apache.jackrabbit.core.security.authorization.Permission;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.uuid.UUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -35,9 +37,12 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Property;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.List;
 
 /**
  * <code>AccessManagerTest</code>...
@@ -105,7 +110,8 @@
         acMgr.checkPermission(id, AccessManager.READ | AccessManager.WRITE | AccessManager.REMOVE
 + 1);
     }
 
-    /*
+/*
+// TODO: uncomment as soon as SimpleAccessManager is replaced
     public void testCheckPermissionWithUnknowId() throws RepositoryException, NotExecutableException
{
         Session s = helper.getReadOnlySession();
         AccessManager acMgr = getAccessManager(s);
@@ -118,7 +124,7 @@
             // ok
         }
     }
-    */
+*/
 
     public void testIsGranted() throws RepositoryException, NotExecutableException {
         Session s = helper.getReadOnlySession();
@@ -150,7 +156,31 @@
 
         assertTrue(acMgr.isGranted(id, AccessManager.READ));
         assertTrue(acMgr.isGranted(id, AccessManager.WRITE));
-        assertTrue(acMgr.isGranted(id, AccessManager.WRITE | AccessManager.REMOVE));    }
+        assertTrue(acMgr.isGranted(id, AccessManager.WRITE | AccessManager.REMOVE));
+    }
+
+/*
+// TODO: uncomment as soon as SimpleAccessManager is replaced
+    public void testIsGrantedForRemovedItem() throws RepositoryException, NotExecutableException
{
+        AccessManager acMgr = getAccessManager(superuser);
+        Property p = testRootNode.setProperty(propertyName1, "anyvalue");
+        ItemId id;
+        if (p instanceof PropertyImpl) {
+            id = ((PropertyImpl)p).getId();
+        } else {
+            throw new NotExecutableException();
+        }
+
+        assertTrue(acMgr.isGranted(id, AccessManager.READ));
+        p.remove();
+        try {
+            acMgr.isGranted(id, AccessManager.READ);
+            fail("AccessManager.isGranted should throw ItemNotFoundException if id of a removed
item is passed.");
+        } catch (ItemNotFoundException e) {
+            // ok
+        }
+    }
+*/
 
     public void testCanAccess() throws RepositoryException, NotExecutableException {
         Session s = helper.getReadOnlySession();
@@ -182,7 +212,8 @@
         assertFalse(getAccessManager(s).canAccess(notAccessibleName));
     }
 
-    /*
+/*
+// TODO: uncomment as soon as SimpleAccessManager is replaced
     public void testCanAccessNotExistingWorkspace() throws RepositoryException, NotExecutableException
{
         Session s = helper.getReadOnlySession();
         List all = Arrays.asList(s.getWorkspace().getAccessibleWorkspaceNames());
@@ -194,7 +225,7 @@
         }
         assertFalse(getAccessManager(s).canAccess(testName));
     }
-    */
+*/
 
     public void testIsGrantedWithRelativePath() throws NotExecutableException {
         AccessManager acMgr = getAccessManager(superuser);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java?rev=651182&r1=651181&r2=651182&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java
Thu Apr 24 01:01:54 2008
@@ -26,9 +26,9 @@
 import org.apache.jackrabbit.core.security.jsr283.security.AccessControlManager;
 import org.apache.jackrabbit.core.security.jsr283.security.Privilege;
 import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.JUnitTest;
+import org.apache.jackrabbit.test.api.observation.EventResult;
 import org.apache.jackrabbit.util.Text;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
@@ -39,6 +39,8 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.jcr.observation.ObservationManager;
+import javax.jcr.observation.Event;
 import javax.jcr.nodetype.ConstraintViolationException;
 import java.security.Principal;
 
@@ -47,7 +49,7 @@
  */
 public abstract class AbstractEvaluationTest extends AbstractAccessControlTest {
 
-    private static Logger log = LoggerFactory.getLogger(AbstractEvaluationTest.class);
+    protected static final long DEFAULT_WAIT_TIMEOUT = 5000;
 
     protected Credentials creds;
     protected User testUser;
@@ -61,6 +63,10 @@
     protected String childchildPPath;
     protected String siblingPath;
 
+    // TODO: test AC for moved node
+    // TODO: test AC for moved AC-controlled node
+    // TODO: test if combination of group and user permissions are properly evaluated
+
     protected void setUp() throws Exception {
         super.setUp();
 
@@ -341,7 +347,6 @@
         }
     }
 
-
     public void testWithDrawRead() throws RepositoryException, NotExecutableException {
         /*
          precondition:
@@ -354,8 +359,7 @@
         // withdraw the READ privilege
         withdrawPrivileges(path, PrivilegeRegistry.READ, getRestrictions(path));
 
-        //assertFalse(testSession.itemExists(path));
-
+        // test if login as testuser -> item at path must not exist.
         Session s = null;
         try {
             s = helper.getRepository().login(creds);
@@ -367,6 +371,42 @@
         }
     }
 
+    public void testEventGeneration() throws RepositoryException, NotExecutableException
{
+        /*
+         precondition:
+         testuser must have READ-only permission on test-node and below
+        */
+        checkReadOnly(path);
+
+        // withdraw the READ privilege
+        withdrawPrivileges(path, PrivilegeRegistry.READ, getRestrictions(path));
+
+        // testUser registers a eventlistener for 'path
+        ObservationManager obsMgr = testSession.getWorkspace().getObservationManager();
+        EventResult listener = new EventResult(((JUnitTest) this).log);
+        try {
+            obsMgr.addEventListener(listener, Event.NODE_REMOVED, path, true, new String[0],
new String[0], true);
+
+            // superuser removes the node with childNPath in order to provoke
+            // events being generated
+            superuser.getItem(childNPath).remove();
+            superuser.save();
+
+            obsMgr.removeEventListener(listener);
+            // since the testUser does not have read-permission on the removed
+            // node, no corresponding event must be generated.
+            Event[] evts = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
+            for (int i = 0; i < evts.length; i++) {
+                if (evts[i].getType() == Event.NODE_REMOVED &&
+                        evts[i].getPath().equals(childNPath)) {
+                    fail("TestUser does not have READ permission below " + path + " ->
events below must not show up.");
+                }
+            }
+        } finally {
+            obsMgr.removeEventListener(listener);
+        }
+    }
+
     public void testInheritance() throws RepositoryException, NotExecutableException {
         /* precondition:
           testuser must have READ-only permission on test-node and below
@@ -504,8 +544,4 @@
         }
         return policyNode;
     }
-
-    // TODO: test AC for moved node
-    // TODO: test AC for moved AC-controlled node
-    // TODO: test if combination of group and user permissions are properly evaluated
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/jsr283/security/AbstractAccessControlTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/jsr283/security/AbstractAccessControlTest.java?rev=651182&r1=651181&r2=651182&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/jsr283/security/AbstractAccessControlTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/jsr283/security/AbstractAccessControlTest.java
Thu Apr 24 01:01:54 2008
@@ -19,20 +19,15 @@
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.Repository;
 
 /**
  * <code>AbstractAccessControlTest</code>...
  */
 public abstract class AbstractAccessControlTest extends AbstractJCRTest {
-
-    private static Logger log = LoggerFactory.getLogger(AbstractAccessControlTest.class);
 
     protected AccessControlManager acMgr;
 



Mime
View raw message