Author: angela
Date: Wed May 3 15:41:26 2017
New Revision: 1793665
URL: http://svn.apache.org/viewvc?rev=1793665&view=rev
Log:
OAK-5882 : Improve coverage for oak.security code in oak-core (wip)
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePatternTest.java
(with props)
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPatternTest.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobPatternTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/ItemNamePatternTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobPatternTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobPatternTest.java?rev=1793665&r1=1793664&r2=1793665&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobPatternTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/GlobPatternTest.java
Wed May 3 15:41:26 2017
@@ -20,9 +20,13 @@ package org.apache.jackrabbit.oak.securi
import java.util.HashMap;
import java.util.Map;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableSet;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -406,4 +410,32 @@ public class GlobPatternTest {
// success
};
}
+
+ @Test
+ public void testMatches() {
+ assertFalse(GlobPattern.create("/a/b/c/d", "/*").matches());
+ }
+
+ @Test
+ public void testHashCode() {
+ GlobPattern pattern = GlobPattern.create("/a/b/c/d", "/*");
+ assertEquals(Objects.hashCode("/a/b/c/d", "/*"), pattern.hashCode());
+ }
+
+ @Test
+ public void testEquals() {
+ GlobPattern pattern = GlobPattern.create("/a/b/c/d", "/*");
+
+ assertEquals(pattern, pattern);
+ assertEquals(pattern, GlobPattern.create("/a/b/c/d", "/*"));
+ }
+
+ @Test
+ public void testNotEquals() {
+ GlobPattern pattern = GlobPattern.create("/a/b/c/d", "/*");
+
+ assertNotEquals(pattern, GlobPattern.create("/a/b/c", "/*"));
+ assertNotEquals(pattern, GlobPattern.create("/a/b/c/d", "*"));
+ assertNotEquals(pattern, new PrefixPattern(ImmutableSet.of("/a/b/c",
"/*")));
+ }
}
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/ItemNamePatternTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/ItemNamePatternTest.java?rev=1793665&r1=1793664&r2=1793665&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/ItemNamePatternTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/ItemNamePatternTest.java
Wed May 3 15:41:26 2017
@@ -17,6 +17,7 @@
package org.apache.jackrabbit.oak.security.authorization.restriction;
import java.util.List;
+import java.util.Set;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -27,12 +28,15 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.util.NodeUtil;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
public class ItemNamePatternTest extends AbstractSecurityTest {
- private ItemNamePattern pattern = new ItemNamePattern(ImmutableSet.of("a",
"b", "c"));
+ private final Set<String> names = ImmutableSet.of("a", "b", "c");
+ private final ItemNamePattern pattern = new ItemNamePattern(names);
@Test
public void testMatchesItem() throws Exception {
@@ -45,6 +49,8 @@ public class ItemNamePatternTest extends
assertTrue(pattern.matches(testTree, null));
assertTrue(pattern.matches(testTree,
PropertyStates.createProperty("a", Boolean.FALSE)));
assertFalse(pattern.matches(testTree,
PropertyStates.createProperty("f", "anyval")));
+
+ testTree.remove();
}
List<String> notMatching = ImmutableList.of("d", "b/d", "d/e/f",
"c/b/abc");
@@ -54,6 +60,8 @@ public class ItemNamePatternTest extends
assertFalse(pattern.matches(testTree, null));
assertTrue(pattern.matches(testTree,
PropertyStates.createProperty("a", Boolean.FALSE)));
assertFalse(pattern.matches(testTree,
PropertyStates.createProperty("f", "anyval")));
+
+ testTree.remove();
}
}
@@ -74,4 +82,26 @@ public class ItemNamePatternTest extends
public void testMatchesNull() {
assertFalse(pattern.matches());
}
+
+ @Test
+ public void testToString() {
+ assertEquals(names.toString(), pattern.toString());
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(names.hashCode(), pattern.hashCode());
+ }
+
+ @Test
+ public void testEquals() {
+ assertEquals(pattern, pattern);
+ assertEquals(pattern, new ItemNamePattern(names));
+ }
+
+ @Test
+ public void testNotEquals() {
+ assertNotEquals(pattern, new ItemNamePattern(ImmutableSet.of("a",
"b")));
+ assertNotEquals(pattern, new PrefixPattern(ImmutableSet.of("a", "b",
"c")));
+ }
}
\ No newline at end of file
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePatternTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePatternTest.java?rev=1793665&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePatternTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePatternTest.java
Wed May 3 15:41:26 2017
@@ -0,0 +1,111 @@
+/*
+ * 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.security.authorization.restriction;
+
+import java.util.List;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+public class NodeTypePatternTest extends AbstractSecurityTest {
+
+ private final Set<String> ntNames =
ImmutableSet.of(JcrConstants.NT_UNSTRUCTURED, JcrConstants.NT_FOLDER);
+
+ private final NodeTypePattern pattern = new NodeTypePattern(ntNames);
+
+ @Test
+ public void testMatchesItem() throws Exception {
+
+ NodeUtil rootTree = new NodeUtil(root.getTree("/"));
+ for (String ntName : ntNames) {
+ Tree testTree = rootTree.addChild("name", ntName).getTree();
+
+ assertTrue(pattern.matches(testTree, null));
+ assertTrue(pattern.matches(testTree,
PropertyStates.createProperty("a", Boolean.FALSE)));
+ assertTrue(pattern.matches(testTree,
PropertyStates.createProperty("f", "anyval")));
+
+ testTree.remove();
+ }
+ }
+
+ @Test
+ public void testNotMatchesItem() throws Exception {
+ NodeUtil rootTree = new NodeUtil(root.getTree("/"));
+
+ List<String> notMatching =
ImmutableList.of(NodeTypeConstants.NT_OAK_RESOURCE,
NodeTypeConstants.NT_OAK_UNSTRUCTURED, JcrConstants.NT_VERSION);
+ for (String ntName : notMatching) {
+ Tree testTree = rootTree.addChild("name", ntName).getTree();
+
+ assertFalse(pattern.matches(testTree, null));
+ assertFalse(pattern.matches(testTree,
PropertyStates.createProperty("a", Boolean.FALSE)));
+ assertFalse(pattern.matches(testTree,
PropertyStates.createProperty("f", "anyval")));
+
+ testTree.remove();
+ }
+ }
+
+ @Test
+ public void testMatchesPath() {
+ List<String> notMatching = ImmutableList.of("/", "/a", "/b", "/c",
"/d/e/a", "/a/b/c/d/b", "/test/c", "/d", "/b/d", "/d/e/f", "/c/b/abc");
+ for (String p : notMatching) {
+ assertFalse(pattern.matches(p));
+ }
+ }
+
+ @Test
+ public void testMatchesNull() {
+ assertFalse(pattern.matches());
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals(ntNames.toString(), pattern.toString());
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(ntNames.hashCode(), pattern.hashCode());
+ }
+
+ @Test
+ public void testEquals() {
+ assertEquals(pattern, pattern);
+ assertEquals(pattern, new NodeTypePattern(ntNames));
+ }
+
+ @Test
+ public void testNotEquals() {
+ assertNotEquals(pattern, new
NodeTypePattern(ImmutableSet.of(JcrConstants.NT_UNSTRUCTURED)));
+ assertNotEquals(pattern, new
NodeTypePattern(ImmutableSet.of(JcrConstants.NT_UNSTRUCTURED,
JcrConstants.NT_FILE)));
+ assertNotEquals(pattern, new
NodeTypePattern(ImmutableSet.of(JcrConstants.NT_VERSION)));
+ assertNotEquals(pattern, new ItemNamePattern(ntNames));
+ }
+
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/NodeTypePatternTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPatternTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPatternTest.java?rev=1793665&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPatternTest.java
(added)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPatternTest.java
Wed May 3 15:41:26 2017
@@ -0,0 +1,109 @@
+/*
+ * 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.security.authorization.restriction;
+
+import java.util.List;
+import java.util.Set;
+import javax.jcr.NamespaceRegistry;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.apache.jackrabbit.oak.AbstractSecurityTest;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+public class PrefixPatternTest extends AbstractSecurityTest {
+
+ private final Set<String> prefixes =
ImmutableSet.of(NamespaceRegistry.PREFIX_JCR);
+
+ private final PrefixPattern pattern = new PrefixPattern(prefixes);
+
+ @Test
+ public void testMatchesItem() throws Exception {
+
+ NodeUtil rootTree = new NodeUtil(root.getTree("/"));
+ for (String prefix : prefixes) {
+ Tree testTree = rootTree.addChild(prefix + ":name",
NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree();
+
+ assertTrue(pattern.matches(testTree, null));
+ assertTrue(pattern.matches(testTree,
PropertyStates.createProperty(prefix + ":f", "anyval")));
+
+ assertFalse(pattern.matches(testTree,
PropertyStates.createProperty("a", Boolean.FALSE)));
+
+ testTree.remove();
+ }
+
+ List<String> notMatching =
ImmutableList.of(NamespaceRegistry.PREFIX_EMPTY, NamespaceRegistry.PREFIX_MIX,
"any");
+ for (String prefix : notMatching) {
+ String name = (prefix.isEmpty()) ? "name" : prefix + ":name";
+ Tree testTree = rootTree.addChild(name,
NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree();
+
+ assertFalse(pattern.matches(testTree, null));
+ assertFalse(pattern.matches(testTree,
PropertyStates.createProperty("f", "anyval")));
+
+ assertTrue(pattern.matches(testTree,
PropertyStates.createProperty("jcr:a", Boolean.FALSE)));
+
+ testTree.remove();
+ }
+ }
+
+ @Test
+ public void testMatchesPath() {
+ List<String> notMatching = ImmutableList.of("/", "/a", "/jcr:b",
"/d/jcr:e/a", "/a/b/c/d/jcr:b");
+ for (String p : notMatching) {
+ assertFalse(pattern.matches(p));
+ }
+ }
+
+ @Test
+ public void testMatchesNull() {
+ assertFalse(pattern.matches());
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals(prefixes.toString(), pattern.toString());
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(prefixes.hashCode(), pattern.hashCode());
+ }
+
+ @Test
+ public void testEquals() {
+ assertEquals(pattern, pattern);
+ assertEquals(pattern, new PrefixPattern(prefixes));
+ }
+
+ @Test
+ public void testNotEquals() {
+ assertNotEquals(pattern, new
PrefixPattern(ImmutableSet.of(NamespaceRegistry.PREFIX_EMPTY)));
+ assertNotEquals(pattern, new
PrefixPattern(ImmutableSet.of(NamespaceRegistry.PREFIX_EMPTY,
NamespaceRegistry.PREFIX_JCR)));
+ assertNotEquals(pattern, new PrefixPattern(ImmutableSet.of("oak")));
+ assertNotEquals(pattern, new ItemNamePattern(prefixes));
+ }
+
+}
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/restriction/PrefixPatternTest.java
------------------------------------------------------------------------------
svn:eol-style = native