configuredFilePermissions = asList("WriteProperties", "AddChildren");
- when(nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT))
+ when(mockNodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT))
.thenReturn(true);
- when(permissionService.hasPermission(nodeRef, RMPermissionModel.READ_RECORDS))
+ when(mockPermissionService.hasPermission(nodeRef, RMPermissionModel.READ_RECORDS))
.thenReturn(AccessStatus.ALLOWED);
AccessStatus result = recordsManagementPermissionPostProcessor.process(accessStatus, nodeRef, perm, configuredReadPermissions, configuredFilePermissions);
assertEquals(AccessStatus.DENIED, result);
}
+
+ /**
+ * Test that the permission groups configured in the global properties file imply descendant permission groups.
+ *
+ * Given a configured permission is an ancestor of another permission P
+ * And the post processor checks if the user has P
+ * Then the post processor says that they do.
+ */
+ @Test
+ public void permissionInherittedFromConfiguredGroup()
+ {
+ NodeRef nodeRef = new NodeRef("node://ref/");
+ // permissions do not include perm created above
+ List configuredReadPermissions = asList();
+ List configuredFilePermissions = asList("WriteProperties");
+
+ when(mockNodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT))
+ .thenReturn(true);
+ when(mockPermissionService.hasPermission(nodeRef, RMPermissionModel.FILE_RECORDS))
+ .thenReturn(AccessStatus.ALLOWED);
+
+ // Set up "WriteProperties" to imply three other permission groups.
+ PermissionReference mockWritePropsPermRef = mock(PermissionReference.class);
+ when(mockPermissionModel.getPermissionReference(null, "WriteProperties")).thenReturn(mockWritePropsPermRef);
+ PermissionReference childOne = mock(PermissionReference.class);
+ when(childOne.getName()).thenReturn("Not this one");
+ PermissionReference childTwo = mock(PermissionReference.class);
+ when(childTwo.getName()).thenReturn("This is the requested permission");
+ PermissionReference childThree = mock(PermissionReference.class);
+ when(childThree.getName()).thenReturn("Not this one either");
+ when(mockPermissionModel.getGranteePermissions(mockWritePropsPermRef)).thenReturn(Sets.newHashSet(childOne, childTwo, childThree));
+
+ // Call the method under test.
+ AccessStatus result = recordsManagementPermissionPostProcessor.process(AccessStatus.DENIED, nodeRef,
+ "This is the requested permission", configuredReadPermissions, configuredFilePermissions);
+
+ assertEquals(AccessStatus.ALLOWED, result);
+ }
}