private Tree getAceTree(Restriction... restrictions) throws Exception { NodeUtil rootNode = new NodeUtil(root.getTree("/")); NodeUtil tmp = rootNode.addChild("testRoot", JcrConstants.NT_UNSTRUCTURED); Tree ace = tmp.addChild("rep:policy", NT_REP_ACL).addChild("ace0", NT_REP_GRANT_ACE).getTree(); restrictionProvider.writeRestrictions(tmp.getTree().getPath(), ace, ImmutableSet.copyOf(restrictions)); return ace; }
@NotNull Tree createTokenTree(@NotNull TokenInfo base, @NotNull NodeUtil parent, @NotNull String ntName) throws AccessDeniedException { Tree tokenTree = getTokenTree(base); Tree tree = parent.addChild("token", ntName).getTree(); tree.setProperty(tokenTree.getProperty(JcrConstants.JCR_UUID)); tree.setProperty(tokenTree.getProperty(TOKEN_ATTRIBUTE_KEY)); tree.setProperty(tokenTree.getProperty(TOKEN_ATTRIBUTE_EXPIRY)); return tree; } }
@Test public void testRemoveEmptyHistoryAfterRemovingVersionable() throws RepositoryException, CommitFailedException { NodeUtil node = new NodeUtil(root.getTree("/")); NodeUtil testVersionable = node.addChild("testVersionable", NodeTypeConstants.NT_OAK_UNSTRUCTURED); TreeUtil.addMixin(testVersionable.getTree(), JcrConstants.MIX_VERSIONABLE, root.getTree(NodeTypeConstants.NODE_TYPES_PATH), null); root.commit(); String historyPath = versionManager.getVersionHistory(testVersionable.getTree()).getPath(); assertTrue(root.getTree(historyPath).exists()); testVersionable.getTree().remove(); root.commit(); assertFalse(root.getTree(historyPath).exists()); }
@Test public void testWriteUnsupportedRestrictions() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); Restriction invalid = new RestrictionImpl(PropertyStates.createProperty("invalid", vf.createValue(true)), false); try { provider.writeRestrictions("/test", aceNode.getTree(), ImmutableSet.<Restriction>of(invalid)); fail("AccessControlException expected"); } catch (AccessControlException e) { // success } }
@Test public void testGetRestrictionPattern() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setString(REP_GLOB, "*"); assertFalse(provider.getPattern("/test", aceNode.getTree()) instanceof CompositePattern); rNode.setBoolean("boolean", true); rNode.setValues("longs", new Value[]{vf.createValue(10), vf.createValue(290)}); assertTrue(provider.getPattern("/test", rNode.getTree()) instanceof CompositePattern); } }
@Test public void testAdmininistrativePermissions() throws AccessDeniedException, CommitFailedException { // EXERCISE walk through the read access Tree rootTree = root.getTree("/"); // EXERCISE walk through the add + remove NodeUtil child = new NodeUtil(rootTree).addChild("test", NodeTypeConstants.NT_OAK_UNSTRUCTURED); root.commit(); child.getTree().remove(); root.commit(); }
@Test public void testIsInCugSupportedPathWithoutCug() throws Exception { NodeUtil node = new NodeUtil(root.getTree(SUPPORTED_PATH2)); Tree c1 = node.addChild("c1", NT_OAK_UNSTRUCTURED).getTree(); Tree c2 = node.addChild("c2", NT_OAK_UNSTRUCTURED).getTree(); String cugPath = c2.getPath(); createCug(cugPath, getTestGroupPrincipal()); root.commit(); assertTrue(getCugTreePermission(cugPath).isInCug()); assertFalse(getCugTreePermission(c1.getPath()).isInCug()); }
@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 testWriteRestrictions() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); Set<Restriction> restrictions = ImmutableSet.of( provider.createRestriction("/test","boolean", vf.createValue(true)), provider.createRestriction("/test", "longs"), provider.createRestriction("/test", REP_GLOB, vf.createValue("*")), provider.createRestriction("/test", REP_NT_NAMES, vf.createValue("nt:base", PropertyType.NAME), vf.createValue("nt:version", PropertyType.NAME))); provider.writeRestrictions("/test", aceNode.getTree(), restrictions); }
@Test public void testValidateUnsupportedRestriction() throws Exception { RestrictionProvider rp = CompositeRestrictionProvider.newInstance(rp1, rp3); NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setString("unsupported", "value"); try { rp.validateRestrictions("/test", aceNode.getTree()); fail("Validation must detect unsupported restriction"); } catch (AccessControlException e) { // success } }
Tree createGroupTree() throws Exception { String groupPath = getUserConfiguration().getParameters().getConfigValue(PARAM_GROUP_PATH, DEFAULT_GROUP_PATH); NodeUtil node = new NodeUtil(root.getTree(PathUtils.ROOT_PATH)); NodeUtil groupRoot = node.getOrAddTree(PathUtils.relativize(PathUtils.ROOT_PATH, groupPath), NT_REP_AUTHORIZABLE_FOLDER); Tree groupTree = groupRoot.addChild("testGroup", NT_REP_GROUP).getTree(); groupTree.setProperty(JcrConstants.JCR_UUID, new UserProvider(root, ConfigurationParameters.EMPTY).getContentID(TEST_GROUP_ID)); return groupTree; }
@Test public void testValidateRestrictionsAtEntryNode() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); aceNode.setBoolean("boolean", true); aceNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)}); aceNode.setString(REP_GLOB, "*"); aceNode.setNames(REP_NT_NAMES); // empty array provider.validateRestrictions("/test", aceNode.getTree()); }
@Before public void setUp() throws Exception { Tree tree = root.getTree("/"); NodeUtil node = new NodeUtil(tree); node.addChild("x", JcrConstants.NT_UNSTRUCTURED).addChild("y", JcrConstants.NT_UNSTRUCTURED).addChild("z", JcrConstants.NT_UNSTRUCTURED); Tree orderable = node.addChild("orderable", JcrConstants.NT_UNSTRUCTURED).getTree(); orderable.setOrderableChildren(true); root.commit(); immutable = new ImmutableTree(((AbstractTree) root.getTree("/")).getNodeState()); }
@Test public void testValidateInvalidRestrictionDef() throws Exception { RestrictionProvider rp = CompositeRestrictionProvider.newInstance(rp1, rp3); NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setValues(REP_GLOB, new Value[]{vf.createValue(10), vf.createValue(290)}); try { rp.validateRestrictions("/test", aceNode.getTree()); fail("Validation must detect invalid restriction definition"); } catch (AccessControlException e) { // success } }
@Test public void testHasCug() throws Exception { assertTrue(CugUtil.hasCug(root.getTree(SUPPORTED_PATH))); for (String path : new String[] {PathUtils.ROOT_PATH, INVALID_PATH, UNSUPPORTED_PATH, SUPPORTED_PATH + "/subtree", SUPPORTED_PATH2, SUPPORTED_PATH3}) { assertFalse(CugUtil.hasCug(root.getTree(path))); } new NodeUtil(root.getTree(SUPPORTED_PATH2)).addChild(REP_CUG_POLICY, NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree(); assertTrue(CugUtil.hasCug(root.getTree(SUPPORTED_PATH2))); }
@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 testCreateReservedKeyProperty() throws Exception { NodeUtil node = new NodeUtil(root.getTree("/")).addChild("testNode", JcrConstants.NT_UNSTRUCTURED); try { node.setString(TOKEN_ATTRIBUTE_KEY, "anyValue"); root.commit(CommitMarker.asCommitAttributes()); fail("The reserved token key property must not used with other node types."); } catch (CommitFailedException e) { assertEquals(60, e.getCode()); } finally { node.getTree().remove(); root.commit(); } }
@Test public void testDefinesCug() throws Exception { assertFalse(CugUtil.definesCug(root.getTree(PathUtils.concat(INVALID_PATH, REP_CUG_POLICY)))); assertTrue(CugUtil.definesCug(root.getTree(PathUtils.concat(SUPPORTED_PATH, REP_CUG_POLICY)))); Tree invalid = new NodeUtil(root.getTree(SUPPORTED_PATH2)).addChild(REP_CUG_POLICY, NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree(); assertFalse(CugUtil.definesCug(invalid)); }
@Test public void testSingleTypeHistoryProperty() throws Exception { Tree userTree = root.getTree(getTestUser().getPath()); Tree pwdNode = new NodeUtil(userTree).getOrAddChild(REP_PWD, NT_REP_PASSWORD).getTree(); pwdNode.setProperty(REP_PWD_HISTORY, "singleValuedProperty"); assertFalse(pwdNode.getProperty(REP_PWD_HISTORY).isArray()); assertFalse(pwdNode.getProperty(REP_PWD_HISTORY).getType().isArray()); PasswordHistory history = new PasswordHistory(CONFIG); assertTrue(history.updatePasswordHistory(userTree, "anyOtherPassword")); assertTrue(pwdNode.getProperty(REP_PWD_HISTORY).isArray()); assertTrue(pwdNode.getProperty(REP_PWD_HISTORY).getType().isArray()); } }