use of com.enonic.xp.node.NodeAccessException in project xp by enonic.
the class MoveNodeCommandTest method move_without_permissions.
@Test
public void move_without_permissions() throws Exception {
final Node deleteUngrantedNode = createNode(CreateNodeParams.create().name("mynode").parent(NodePath.ROOT).setNodeId(NodeId.from("mynode")).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.MODIFY).build())).build());
final Node deleteGrantedNode = createNode(CreateNodeParams.create().name("mynode2").parent(NodePath.ROOT).setNodeId(NodeId.from("mynode2")).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build())).build());
final Node createUngrantedNewParent = createNode(CreateNodeParams.create().name("new-parent").parent(NodePath.ROOT).setNodeId(NodeId.from("newparent")).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.CREATE).build())).build());
final Node createGrantedNewParent = createNode(CreateNodeParams.create().name("new-parent2").parent(NodePath.ROOT).setNodeId(NodeId.from("newparent2")).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build())).build());
// Tests the check of the DELETE right on the moved node
boolean deleteRightChecked = false;
try {
MoveNodeCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(deleteUngrantedNode.id()).newParent(createGrantedNewParent.path()).build().execute();
} catch (NodeAccessException e) {
deleteRightChecked = true;
}
assertTrue(deleteRightChecked);
// Tests the check of the CREATE right on the new parent
boolean createRightChecked = false;
try {
MoveNodeCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(deleteGrantedNode.id()).newParent(createUngrantedNewParent.path()).build().execute();
} catch (NodeAccessException e) {
createRightChecked = true;
}
assertTrue(createRightChecked);
// Tests the correct behaviour if both rights are granted
MoveNodeCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(deleteGrantedNode.id()).newParent(createGrantedNewParent.path()).build().execute();
final Node movedNode = getNodeById(deleteGrantedNode.id());
assertEquals(createGrantedNewParent.path(), movedNode.parentPath());
assertEquals("mynode2", movedNode.name().toString());
}
Aggregations