Author: angela
Date: Thu Feb 23 18:26:10 2017
New Revision: 1784184

URL: http://svn.apache.org/viewvc?rev=1784184&view=rev
Log:
OAK-5793 : Improve coverage for security code in oak-core (wip)

Added:
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/AllTreePermissionTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyPermissionProviderTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyTreePermissionTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/NoRecurseTreePermissionTest.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/OpenPermissionProviderTest.java

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/AllTreePermissionTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/AllTreePermissionTest.java?rev=1784184&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/AllTreePermissionTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/AllTreePermissionTest.java
 Thu Feb 23 18:26:10 2017
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.spi.security.authorization.permission;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+public class AllTreePermissionTest {
+
+    private final TreePermission all = TreePermission.ALL;
+    private final PropertyState property = 
PropertyStates.createProperty("prop", "value");
+
+    @Test
+    public void testGetChildPermission() {
+        assertSame(TreePermission.ALL, all.getChildPermission("name", 
EmptyNodeState.EMPTY_NODE));
+    }
+
+    @Test
+    public void testCanRead() {
+        assertTrue(all.canRead());
+    }
+
+    @Test
+    public void testCanReadProperty() {
+        assertTrue(all.canRead(property));
+    }
+
+    @Test
+    public void testCanReadAll() {
+        assertTrue(all.canReadAll());
+    }
+
+    @Test
+    public void testCanReadProperties() {
+        assertTrue(all.canReadProperties());
+    }
+
+    @Test
+    public void testIsGranted() {
+        assertTrue(all.isGranted(Permissions.ALL));
+    }
+
+    @Test
+    public void testIsGrantedProperty() {
+        assertTrue(all.isGranted(Permissions.ALL, property));
+    }
+}
\ No newline at end of file

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyPermissionProviderTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyPermissionProviderTest.java?rev=1784184&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyPermissionProviderTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyPermissionProviderTest.java
 Thu Feb 23 18:26:10 2017
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.spi.security.authorization.permission;
+
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.tree.TreeFactory;
+import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+public class EmptyPermissionProviderTest {
+
+    private final PermissionProvider emptyProvider = 
EmptyPermissionProvider.getInstance();
+
+    private final Tree tree = 
TreeFactory.createReadOnlyTree(EmptyNodeState.EMPTY_NODE);
+
+    @Test
+    public void testGetPrivileges() {
+        assertTrue(emptyProvider.getPrivileges(tree).isEmpty());
+    }
+
+    @Test
+    public void testHasPrivileges() {
+        assertFalse(emptyProvider.hasPrivileges(tree, 
PrivilegeConstants.JCR_READ));
+    }
+
+    @Test
+    public void testGetRepositoryPermission() {
+        assertSame(RepositoryPermission.EMPTY, 
emptyProvider.getRepositoryPermission());
+    }
+
+    @Test
+    public void testGetTreePermission() {
+        assertSame(TreePermission.EMPTY, emptyProvider.getTreePermission(tree, 
TreePermission.EMPTY));
+    }
+
+    @Test
+    public void testIsGranted() {
+        assertFalse(emptyProvider.isGranted(tree, null, Permissions.READ));
+        assertFalse(emptyProvider.isGranted(tree, 
PropertyStates.createProperty("prop", "value"), Permissions.READ));
+    }
+
+    @Test
+    public void testIsGrantedActions() {
+        assertFalse(emptyProvider.isGranted("/", Session.ACTION_READ));
+    }
+}
\ No newline at end of file

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyTreePermissionTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyTreePermissionTest.java?rev=1784184&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyTreePermissionTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/EmptyTreePermissionTest.java
 Thu Feb 23 18:26:10 2017
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.spi.security.authorization.permission;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+
+public class EmptyTreePermissionTest {
+
+    private final TreePermission empty = TreePermission.EMPTY;
+    private final PropertyState property = 
PropertyStates.createProperty("prop", "value");
+
+    @Test
+    public void testGetChildPermission() {
+        assertSame(TreePermission.EMPTY, empty.getChildPermission("name", 
EmptyNodeState.EMPTY_NODE));
+    }
+
+    @Test
+    public void testCanRead() {
+        assertFalse(empty.canRead());
+    }
+
+    @Test
+    public void testCanReadProperty() {
+        assertFalse(empty.canRead(property));
+    }
+
+    @Test
+    public void testCanReadAll() {
+        assertFalse(empty.canReadAll());
+    }
+
+    @Test
+    public void testCanReadProperties() {
+        assertFalse(empty.canReadProperties());
+    }
+
+    @Test
+    public void testIsGranted() {
+        assertFalse(empty.isGranted(Permissions.ALL));
+    }
+
+    @Test
+    public void testIsGrantedProperty() {
+        assertFalse(empty.isGranted(Permissions.ALL, property));
+    }
+
+}
\ No newline at end of file

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/NoRecurseTreePermissionTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/NoRecurseTreePermissionTest.java?rev=1784184&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/NoRecurseTreePermissionTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/NoRecurseTreePermissionTest.java
 Thu Feb 23 18:26:10 2017
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.spi.security.authorization.permission;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+public class NoRecurseTreePermissionTest {
+
+    private final TreePermission noRecurse = TreePermission.NO_RECOURSE;
+    private final PropertyState property = 
PropertyStates.createProperty("prop", "value");
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testGetChildPermission() {
+        noRecurse.getChildPermission("name", EmptyNodeState.EMPTY_NODE);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testCanRead() {
+        noRecurse.canRead();
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testCanReadProperty() {
+        noRecurse.canRead(property);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testCanReadAll() {
+        noRecurse.canReadAll();
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testCanReadProperties() {
+        noRecurse.canReadProperties();
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testIsGranted() {
+        noRecurse.isGranted(Permissions.ALL);
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testIsGrantedProperty() {
+        noRecurse.isGranted(Permissions.ALL, property);
+    }
+}
\ No newline at end of file

Added: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/OpenPermissionProviderTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/OpenPermissionProviderTest.java?rev=1784184&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/OpenPermissionProviderTest.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/permission/OpenPermissionProviderTest.java
 Thu Feb 23 18:26:10 2017
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.spi.security.authorization.permission;
+
+import java.util.Set;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.tree.TreeFactory;
+import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
+import org.apache.jackrabbit.util.Text;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+public class OpenPermissionProviderTest {
+
+    private final PermissionProvider openProvider = 
OpenPermissionProvider.getInstance();
+
+    private final Tree tree = 
TreeFactory.createReadOnlyTree(EmptyNodeState.EMPTY_NODE);
+
+    @Test
+    public void testGetPrivileges() {
+        Set<String> privs = openProvider.getPrivileges(tree);
+        assertFalse(privs.isEmpty());
+        assertTrue(privs.contains(PrivilegeConstants.JCR_ALL));
+    }
+
+    @Test
+    public void testHasPrivileges() {
+        assertTrue(openProvider.hasPrivileges(tree, 
PrivilegeConstants.JCR_ALL));
+    }
+
+    @Test
+    public void testGetRepositoryPermission() {
+        assertSame(RepositoryPermission.ALL, 
openProvider.getRepositoryPermission());
+    }
+
+    @Test
+    public void testGetTreePermission() {
+        assertSame(TreePermission.ALL, openProvider.getTreePermission(tree, 
TreePermission.EMPTY));
+    }
+
+    @Test
+    public void testIsGranted() {
+        assertTrue(openProvider.isGranted(tree, null, Permissions.ALL));
+        assertTrue(openProvider.isGranted(tree, 
PropertyStates.createProperty("prop", "value"), Permissions.ALL));
+    }
+
+    @Test
+    public void testIsGrantedActions() {
+        assertTrue(openProvider.isGranted("/", Text.implode(new 
String[]{Session.ACTION_READ, Session.ACTION_ADD_NODE, Session.ACTION_REMOVE, 
Session.ACTION_SET_PROPERTY}, ",")));
+    }
+}
\ No newline at end of file


Reply via email to