Skip to content

Commit

Permalink
test: fix test (#28579)
Browse files Browse the repository at this point in the history
  • Loading branch information
gortiz-dotcms committed Oct 16, 2024
1 parent 8d4f2d7 commit f6d63a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,8 @@ public void Test_Fire_Reset_Permissions_Action_For_Contentlet_Id() throws Except

Role limitedUserRole = TestUserUtils.getBackendRole();

final int originalSizePermissions = APILocator.getPermissionAPI().getPermissions(contentlet3).size();

//we add to two of the contentlets only read permissions, this way we will check some fails
addPermission(limitedUserRole, contentlet, PermissionLevel.READ);
addPermission(limitedUserRole, contentlet2, PermissionLevel.READ);
Expand All @@ -2445,6 +2447,12 @@ public void Test_Fire_Reset_Permissions_Action_For_Contentlet_Id() throws Except
addPermission(limitedUserRole, contentlet3, PermissionLevel.PUBLISH);
addPermission(limitedUserRole, contentlet3, PermissionLevel.EDIT_PERMISSIONS);

//Since we're setting permissions individually, should be only 1 permission
Assert.assertEquals(1, APILocator.getPermissionAPI().getPermissions(contentlet).size());
Assert.assertEquals(1, APILocator.getPermissionAPI().getPermissions(contentlet2).size());
Assert.assertEquals(4, APILocator.getPermissionAPI().getPermissions(contentlet3).size());


final User userWithBackendRole = TestUserUtils.getBackendUser(APILocator.systemHost());

WorkflowResource myWorkflowResource = mockWorkflowResourceToResetPermissionsAction(userWithBackendRole);
Expand Down Expand Up @@ -2536,19 +2544,12 @@ public void Test_Fire_Reset_Permissions_Action_For_Contentlet_Id() throws Except

ReindexThread.unpause();

List<Contentlet> contentletsAfter = APILocator.getContentletAPIImpl().findContentletsByIdentifiers(contentlets.stream()
.map(Contentlet::getIdentifier)
.toArray(String[]::new), false, 1L, adminUser, false);


//first, check that the two first contentlets still have the read permission (because it should not have been reset)
APILocator.getPermissionAPI().checkPermission(contentletsAfter.get(1), PermissionLevel.READ, userWithBackendRole);
APILocator.getPermissionAPI().checkPermission(contentletsAfter.get(0), PermissionLevel.READ, userWithBackendRole);

//then the check on the last contentlet, it should throw the exception because the permissions should have been reset
assertThrows(DotSecurityException.class, () -> {
APILocator.getPermissionAPI().checkPermission(contentletsAfter.get(2), PermissionLevel.READ, userWithBackendRole);
});
//first we check the contentlets that should have failed, they should have the same permissions
Assert.assertEquals(1, APILocator.getPermissionAPI().getPermissions(contentlet).size());
Assert.assertEquals(1, APILocator.getPermissionAPI().getPermissions(contentlet2).size());
//and last we check the contentlet that should have been successful, it should have the original size of permissions
Assert.assertEquals(originalSizePermissions, APILocator.getPermissionAPI().getPermissions(contentlet3).size());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4893,12 +4893,15 @@ public void test_reset_permissions_subaction() throws DotDataException, DotSecur
.host(APILocator.systemHost())
.nextPersisted();

//Get original size permissions
final int originalSizePermissions = APILocator.getPermissionAPI().getPermissions(contentlet).size();

Role limitedUserRole = TestUserUtils.getBackendRole();

addPermission(limitedUserRole, contentlet, PermissionLevel.READ);

final User userWithBackendRole = TestUserUtils.getBackendUser(APILocator.systemHost());
//Since we're setting permissions individually, should be only 1 permission
Assert.assertEquals(1, APILocator.getPermissionAPI().getPermissions(contentlet).size());


final long time = System.currentTimeMillis();
Expand Down Expand Up @@ -4940,19 +4943,13 @@ public void test_reset_permissions_subaction() throws DotDataException, DotSecur
final ContentletRelationships contentletRelationships = APILocator.getContentletAPI()
.getAllRelationships(contentlet);


//Reset permissions
contentlet = fireWorkflowAction(contentlet, contentletRelationships, workflowSchemeResetPermissionAction,
StringPool.BLANK, StringPool.BLANK, user);


Contentlet finalContentlet = contentlet;

//check after the workflow action is fired, at this moment the user should no longer have permissions on the contentlet
assertThrows(DotSecurityException.class, () -> {
APILocator.getPermissionAPI().checkPermission(finalContentlet, PermissionLevel.READ, userWithBackendRole);
});

//After reset permissions, the permissions should be back to their original size
Assert.assertEquals(originalSizePermissions, APILocator.getPermissionAPI().getPermissions(contentlet).size());

}

Expand Down

0 comments on commit f6d63a0

Please sign in to comment.