jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r784106 - in /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api: HasPermissionTest.java TestAll.java
Date Fri, 12 Jun 2009 13:09:20 GMT
Author: angela
Date: Fri Jun 12 13:09:19 2009
New Revision: 784106

URL: http://svn.apache.org/viewvc?rev=784106&view=rev
Log:
JCR-2085: test case (TCK) maintenance for JCR 2.0

- trivial tests for Session.hasPermission

Added:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/HasPermissionTest.java
      - copied, changed from r784098, jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/CheckPermissionTest.java
Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java

Copied: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/HasPermissionTest.java
(from r784098, jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/CheckPermissionTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/HasPermissionTest.java?p2=jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/HasPermissionTest.java&p1=jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/CheckPermissionTest.java&r1=784098&r2=784106&rev=784106&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/CheckPermissionTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/HasPermissionTest.java
Fri Jun 12 13:09:19 2009
@@ -19,78 +19,75 @@
 import org.apache.jackrabbit.test.AbstractJCRTest;
 
 import javax.jcr.Session;
-
-import java.security.AccessControlException;
+import javax.jcr.Node;
 
 /**
- * Tests if {@link Session#checkPermission(String, String)} yields the correct
- * permissions for a read-only session and a 'superuser' session.
- *
- * @test
- * @sources CheckPermissionTest.java
- * @executeClass org.apache.jackrabbit.test.api.CheckPermissionTest
- * @keywords level2
+ * Tests if {@link javax.jcr.Session#hasPermission(String, String)} yields the
+ * correct permissions for a read-only, a read-write and an admin session.
  */
-public class CheckPermissionTest extends AbstractJCRTest {
+public class HasPermissionTest extends AbstractJCRTest {
+
+    private static final String ACTION_ALL = Session.ACTION_READ + "," + Session.ACTION_ADD_NODE
+ "," + Session.ACTION_REMOVE + "," + Session.ACTION_SET_PROPERTY;
 
     /**
-     * Tests if <code>Session.checkPermission(String, String)</code> works
-     * properly: <ul> <li>Returns quietly if access is permitted.</li>
-     * <li>Throws an {@link java.security.AccessControlException} if access is
-     * denied.</li> </ul>
+     * Tests if <code>Session.hasPermission(String, String)</code> returns
+     * <ul>
+     * <li><code>true</code> for READ.</li>
+     * <li><code>false</code> for all other actions.</li>
+     * </ul>
      */
-    public void testCheckPermission() throws Exception {
-        testRootNode.addNode(nodeName2, testNodeType);
+    public void testReadOnlyPermission() throws Exception {
+        Node n = testRootNode.addNode(nodeName2, testNodeType);
         superuser.save();
 
         Session readOnly = helper.getReadOnlySession();
-        try {
-            permissionCheckReadOnly(readOnly);
-            permissionCheckReadWrite(superuser);
-        } finally {
-            readOnly.logout();
-        }
+        String path = n.getPath();
+
+        assertTrue(readOnly.hasPermission(path, Session.ACTION_READ));
+        assertFalse(readOnly.hasPermission(path + "newNode", Session.ACTION_ADD_NODE));
+        assertFalse(readOnly.hasPermission(path, Session.ACTION_REMOVE));
+        assertFalse(readOnly.hasPermission(path, Session.ACTION_SET_PROPERTY));
+        assertFalse(readOnly.hasPermission(path, ACTION_ALL));
+        assertFalse(readOnly.hasPermission(path, Session.ACTION_REMOVE + "," + Session.ACTION_SET_PROPERTY));
     }
 
     /**
-     * Helper function used in testCheckPermission checks if a read-only session
-     * has the correct permissions
+     * Tests if <code>Session.hasPermission(String, String)</code> returns
+     * <ul>
+     * <li><code>true</code> for all actions.</li>
+     * </ul>
      */
-    private void permissionCheckReadOnly(Session readOnly) throws Exception {
-        String pathPrefix = (testRoot.length() == 1) ? testRoot : testRoot + "/";
-        readOnly.checkPermission(testRoot, "read");
-
-        try {
-            readOnly.checkPermission(pathPrefix + nodeName1, "add_node");
-            fail("add_node permission granted to read-only Session");
-        } catch (AccessControlException success) {
-            // ok
-        }
-
-        try {
-            readOnly.checkPermission(pathPrefix + nodeName1, "set_property");
-            fail("set_property permission granted to read-only Session");
-        } catch (AccessControlException success) {
-            // ok
-        }
-
-        try {
-            readOnly.checkPermission(pathPrefix + nodeName2, "remove");
-            fail("remove permission granted to read-only Session");
-        } catch (AccessControlException success) {
-            // ok
-        }
+    public void testReadWritePermission() throws Exception {
+        Node n = testRootNode.addNode(nodeName2, testNodeType);
+        superuser.save();
+
+        String path = n.getPath();
+        Session rwSession = helper.getReadWriteSession();
+
+        assertTrue(rwSession.hasPermission(path, Session.ACTION_READ));
+        assertTrue(rwSession.hasPermission(path + "newNode", Session.ACTION_ADD_NODE));
+        assertTrue(rwSession.hasPermission(path, Session.ACTION_REMOVE));
+        assertTrue(rwSession.hasPermission(path, Session.ACTION_SET_PROPERTY));
+        assertTrue(rwSession.hasPermission(path, ACTION_ALL));
     }
 
+
     /**
-     * Helper function used in testCheckPermission checks if a read-write
-     * session has the correct permissions
+     * Tests if <code>Session.hasPermission(String, String)</code> returns
+     * <ul>
+     * <li><code>true</code> for all actions.</li>
+     * </ul>
      */
-    private void permissionCheckReadWrite(Session readWrite) throws Exception {
-        String pathPrefix = (testRoot.length() == 1) ? testRoot : testRoot + "/";
-        readWrite.checkPermission(testRoot, "read");
-        readWrite.checkPermission(pathPrefix + nodeName1, "add_node");
-        readWrite.checkPermission(pathPrefix + propertyName1, "set_property");
-        readWrite.checkPermission(pathPrefix + nodeName2, "remove");
+    public void testAdminPermission() throws Exception {
+        Node n = testRootNode.addNode(nodeName2, testNodeType);
+        superuser.save();
+
+        String path = n.getPath();
+
+        assertTrue(superuser.hasPermission(path, Session.ACTION_READ));
+        assertTrue(superuser.hasPermission(path + "newNode", Session.ACTION_ADD_NODE));
+        assertTrue(superuser.hasPermission(path, Session.ACTION_REMOVE));
+        assertTrue(superuser.hasPermission(path, Session.ACTION_SET_PROPERTY));
+        assertTrue(superuser.hasPermission(path, ACTION_ALL));
     }
-}
+}
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java?rev=784106&r1=784105&r2=784106&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/TestAll.java
Fri Jun 12 13:09:19 2009
@@ -145,6 +145,7 @@
         //// new Session features
         
         suite.addTestSuite(SessionRemoveItemTest.class);
+        suite.addTestSuite(HasPermissionTest.class);
 
         //// new Workspace features
         



Mime
View raw message