diff --git a/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/workflow/WorkflowResourceIntegrationTest.java b/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/workflow/WorkflowResourceIntegrationTest.java index 78d27ab9d97c..7101f63015f9 100644 --- a/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/workflow/WorkflowResourceIntegrationTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/workflow/WorkflowResourceIntegrationTest.java @@ -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); @@ -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); @@ -2536,19 +2544,12 @@ public void Test_Fire_Reset_Permissions_Action_For_Contentlet_Id() throws Except ReindexThread.unpause(); - List 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()); } diff --git a/dotcms-integration/src/test/java/com/dotmarketing/portlets/workflows/business/WorkflowAPITest.java b/dotcms-integration/src/test/java/com/dotmarketing/portlets/workflows/business/WorkflowAPITest.java index b235586e6165..56375599ee59 100644 --- a/dotcms-integration/src/test/java/com/dotmarketing/portlets/workflows/business/WorkflowAPITest.java +++ b/dotcms-integration/src/test/java/com/dotmarketing/portlets/workflows/business/WorkflowAPITest.java @@ -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(); @@ -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()); }