PermissionHook implements PostValidationHook, AccessControlConstants, PermissionConstants { @NotNull @Override public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) { NodeBuilder rootAfter = after.builder(); permissionStore = getPermissionStore(rootAfter); bitsProvider = new PrivilegeBitsProvider(rootProvider.createReadOnlyRoot(after)); isACL = new TypePredicate(after, NT_REP_ACL); isACE = new TypePredicate(after, NT_REP_ACE); isGrantACE = new TypePredicate(after, NT_REP_GRANT_ACE); Diff diff = new Diff(""); after.compareAgainstBaseState(before, diff); apply(); return rootAfter.getNodeState(); } PermissionHook(@NotNull String workspaceName, @NotNull RestrictionProvider restrictionProvider,
                          @NotNull MountInfoProvider mountInfoProvider, @NotNull RootProvider rootProvider,
                          @NotNull TreeProvider treeProvider); @NotNull @Override NodeState processCommit(NodeState before, NodeState after, CommitInfo info); @Override String toString();  }
@Test public void testHiddenChildNodeAdded() throws Exception { PermissionHook ph = createPermissionHook(adminSession.getWorkspaceName()); NodeState before = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeState after = spy(before); NodeState child = mock(NodeState.class); Iterable newCnes = Collections.singleton(new MemoryChildNodeEntry(":hidden", child)); Iterable cnes = Iterables.concat(newCnes, before.getChildNodeEntries()); when(after.getChildNodeEntries()).thenReturn(cnes); when(after.getChildNode(":hidden")).thenReturn(child); ph.processCommit(before, after, new CommitInfo("sid", null)); verify(child, never()).getProperty(anyString()); }
@Test public void testHiddenChildNodeChanged() { PermissionHook ph = createPermissionHook(adminSession.getWorkspaceName()); NodeState nodeState = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeState after = spy(nodeState); NodeState before = spy(nodeState); NodeState child = mock(NodeState.class); Iterable hidden = Collections.singleton(new MemoryChildNodeEntry(":hidden", child)); Iterable cnes = Iterables.concat(hidden, nodeState.getChildNodeEntries()); when(before.getChildNodeEntries()).thenReturn(cnes); when(before.getChildNode(":hidden")).thenReturn(child); NodeState child2 = when(mock(NodeState.class).exists()).thenReturn(true).getMock(); hidden = Collections.singleton(new MemoryChildNodeEntry(":hidden", child2)); cnes = Iterables.concat(hidden, nodeState.getChildNodeEntries()); when(after.getChildNodeEntries()).thenReturn(cnes); when(after.getChildNode(":hidden")).thenReturn(child2); ph.processCommit(before, after, new CommitInfo("sid", null)); verify(child, never()).getProperty(anyString()); verify(child2, never()).getProperty(anyString()); }
@Test public void testHiddenChildNodeDeleted() { PermissionHook ph = createPermissionHook(adminSession.getWorkspaceName()); NodeState after = getTreeProvider().asNodeState(root.getTree(PathUtils.ROOT_PATH)); NodeState before = spy(after); NodeState child = mock(NodeState.class); Iterable deletedCnes = Collections.singleton(new MemoryChildNodeEntry(":hidden", child)); Iterable cnes = Iterables.concat(deletedCnes, after.getChildNodeEntries()); when(before.getChildNodeEntries()).thenReturn(cnes); when(before.getChildNode(":hidden")).thenReturn(child); ph.processCommit(before, after, new CommitInfo("sid", null)); verify(child, never()).getProperty(anyString()); }