From a7d004f31ad66d16dcce561fd016b69629ab9e9d Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Wed, 22 May 2024 09:55:15 +0530 Subject: [PATCH 01/16] Enable role modification for sub-org admins --- .../listner/AppPortalRoleManagementListener.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java index 6cc3e551877..48ffe51987e 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java @@ -20,6 +20,8 @@ import org.apache.commons.lang.StringUtils; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; +import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil; import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException; import org.wso2.carbon.identity.role.v2.mgt.core.listener.AbstractRoleManagementListener; import org.wso2.carbon.identity.role.v2.mgt.core.model.Permission; @@ -100,6 +102,15 @@ public void preUpdateUserListOfRole(String roleId, List newUserIDList, L return; } + try { + if (isRoleModificationAllowedForTenant(tenantDomain)) { + return; + } + } catch (OrganizationManagementException e) { + throw new IdentityRoleManagementException(INVALID_REQUEST.getCode(), + "Failed to determine if the tenant is a sub-organization for tenant domain: " + tenantDomain, e); + } + String adminUserId; try { UserRealm userRealm = @@ -145,4 +156,9 @@ private boolean isAdministratorRole(String roleId, String tenantDomain) throws I && StringUtils.equalsIgnoreCase(APPLICATION, role.getAudience()) && StringUtils.equalsIgnoreCase(CONSOLE_APP, role.getAudienceName()); } + + private boolean isRoleModificationAllowedForTenant(String tenantDomain) throws OrganizationManagementException { + + return OrganizationManagementUtil.isOrganization(tenantDomain); + } } From 3bd397aa6c69124b57238f20a37f3b4247c9a53a Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Wed, 22 May 2024 10:21:53 +0530 Subject: [PATCH 02/16] =?UTF-8?q?Add=20changeset=20=F0=9F=A6=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/fast-penguins-reply.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fast-penguins-reply.md diff --git a/.changeset/fast-penguins-reply.md b/.changeset/fast-penguins-reply.md new file mode 100644 index 00000000000..f6f55635d1f --- /dev/null +++ b/.changeset/fast-penguins-reply.md @@ -0,0 +1,5 @@ +--- +"@wso2is/identity-apps-core": patch +--- + +Enable Role Modification for Sub-Org Admins in AppPortalRoleManagementListener. From 661ac9daf878e57a1f68c92f7f146877717a7082 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Wed, 22 May 2024 10:42:14 +0530 Subject: [PATCH 03/16] Code refactored-removed unnecessary private method --- .../common/listner/AppPortalRoleManagementListener.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java index 48ffe51987e..46e650697e0 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java @@ -103,7 +103,7 @@ public void preUpdateUserListOfRole(String roleId, List newUserIDList, L } try { - if (isRoleModificationAllowedForTenant(tenantDomain)) { + if (OrganizationManagementUtil.isOrganization(tenantDomain)) { return; } } catch (OrganizationManagementException e) { @@ -156,9 +156,4 @@ private boolean isAdministratorRole(String roleId, String tenantDomain) throws I && StringUtils.equalsIgnoreCase(APPLICATION, role.getAudience()) && StringUtils.equalsIgnoreCase(CONSOLE_APP, role.getAudienceName()); } - - private boolean isRoleModificationAllowedForTenant(String tenantDomain) throws OrganizationManagementException { - - return OrganizationManagementUtil.isOrganization(tenantDomain); - } } From ded2b7962d446e88165b5906e2175d3a57edb9c7 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Sun, 26 May 2024 15:28:21 +0530 Subject: [PATCH 04/16] Added unit test for PreUpdateUserListOfRole method --- .../org.wso2.identity.apps.common/pom.xml | 21 +++ .../AppPortalRoleManagementListenerTest.java | 167 ++++++++++++++++++ identity-apps-core/pom.xml | 31 ++++ 3 files changed, 219 insertions(+) create mode 100644 identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml b/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml index 795457330e0..562aaeceeb8 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml +++ b/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml @@ -94,6 +94,27 @@ xalan 2.7.3 + + + org.testng + testng + test + + + org.mockito + mockito-core + test + + + org.mockito + mockito-testng + test + + + junit + junit + test + diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java new file mode 100644 index 00000000000..33156623905 --- /dev/null +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java @@ -0,0 +1,167 @@ +package org.wso2.identity.apps.common.listener; + +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.testng.MockitoTestNGListener; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.mockito.Mock; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Listeners; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.context.internal.CarbonContextDataHolder; +import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil; +import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService; +import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException; +import org.wso2.carbon.identity.role.v2.mgt.core.model.Role; +import org.wso2.carbon.user.core.UserRealm; +import org.wso2.carbon.user.core.common.AbstractUserStoreManager; +import org.wso2.carbon.user.core.config.RealmConfiguration; +import org.wso2.carbon.utils.CarbonUtils; +import org.wso2.identity.apps.common.internal.AppsCommonDataHolder; +import org.wso2.identity.apps.common.listner.AppPortalRoleManagementListener; + +import java.util.Arrays; +import java.util.List; + +@Listeners(MockitoTestNGListener.class) +public class AppPortalRoleManagementListenerTest { + + @Mock + private UserRealm mockUserRealm; + + @Mock + private AbstractUserStoreManager mockAbstractUserStoreManager; + + @Mock + private RealmConfiguration mockRealmConfiguration; + + @Mock + private RoleManagementService mockRoleManagementService; + + @Mock + private Role mockRole; + + private static final String ADMINISTRATOR = "Administrator"; + private static final String APPLICATION = "application"; + private static final String CONSOLE_APP = "Console"; + private static final String carbonContext = "Console"; + private static final String adminUsername = "admin"; + + @BeforeMethod + public void setUp() throws Exception { + + openMocks(this); + + mockStatic(AppsCommonDataHolder.class); + AppsCommonDataHolder mockAppsCommonDataHolder = mock(AppsCommonDataHolder.class); + when(AppsCommonDataHolder.getInstance()).thenReturn(mockAppsCommonDataHolder); + when(mockAppsCommonDataHolder.getRoleManagementServiceV2()).thenReturn(mockRoleManagementService); + + mockCarbonContextForTenant(); + + when(mockUserRealm.getRealmConfiguration()).thenReturn(mockRealmConfiguration); + when(mockUserRealm.getUserStoreManager()).thenReturn(mockAbstractUserStoreManager); + + mockStatic(OrganizationManagementUtil.class); + + } + + private void mockCarbonContextForTenant() { + + try (MockedStatic privilegedCarbonContext = mockStatic(PrivilegedCarbonContext.class)) { + + PrivilegedCarbonContext mockPrivilegedCarbonContext = mock(PrivilegedCarbonContext.class); + privilegedCarbonContext.when(PrivilegedCarbonContext::getThreadLocalCarbonContext) + .thenReturn(mockPrivilegedCarbonContext); + when(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()).thenReturn(mockUserRealm); + } + } + + @DataProvider(name = "preUpdateUserListOfRoleDataProvider") + public Object[][] preUpdateUserListOfRoleDataProvider() { + return new Object[][]{ + // Test case where deletedUserIDList == null + {"roleId", Arrays.asList("newUser"), null, "tenantDomain", true, false, null}, + + // Test case where !isAdministratorRole(roleId, tenantDomain) + {"roleId", Arrays.asList("newUser"), Arrays.asList("deletedUser"), "tenantDomain", false, false, null}, + + // Test case where both deletedUserIDList == null and !isAdministratorRole(roleId, tenantDomain) + {"roleId", Arrays.asList("newUser"), null, "tenantDomain", false, false, null}, + + // Test case where both deletedUserIDList != null and isAdministratorRole(roleId, tenantDomain) + {"roleId", Arrays.asList("newUser"), Arrays.asList("deletedUser"), "tenantDomain", true, false, null}, + + // Test case where isOrganization == true + {"roleId", Arrays.asList("newUser"), Arrays.asList("deletedUser"), "tenantDomain", true, true, null}, + + // Test case where isOrganization == false + {"roleId", Arrays.asList("newUser"), Arrays.asList("deletedUser"), "tenantDomain", true, false, null}, + + // Test case where deletedUserIDList contains adminUserId + {"roleId", Arrays.asList("newUser"), Arrays.asList("adminUserId"), "tenantDomain", true, false, "adminUserId"} + }; + } + + @Test(dataProvider = "preUpdateUserListOfRoleDataProvider") + public void testPreUpdateUserListOfRole(String roleId, List newUserIDList, List deletedUserIDList, + String tenantDomain, boolean isAdminRole, boolean isOrganization, String adminUserId) + throws Exception { + + //Create AppPortalRoleManagementListener Instance + AppPortalRoleManagementListener appPortalRoleManagementListener = + new AppPortalRoleManagementListener(true); + + // Mock the behavior of isAdministratorRole + when(mockRoleManagementService.getRole(roleId, tenantDomain)).thenReturn(mockRole); + when(mockRole.getName()).thenReturn(ADMINISTRATOR); + when(mockRole.getAudience()).thenReturn(APPLICATION); + when(mockRole.getAudienceName()).thenReturn(CONSOLE_APP); + + // Mock the behavior of OrganizationManagementUtil + when(OrganizationManagementUtil.isOrganization(tenantDomain)).thenReturn(isOrganization); + + if (adminUserId != null) { + when(mockRealmConfiguration.getAdminUserName()).thenReturn(adminUsername); + when(mockAbstractUserStoreManager.getUserIDFromUserName(adminUsername)).thenReturn(adminUserId); + } + + if (adminUserId != null && deletedUserIDList != null && deletedUserIDList.contains(adminUserId)) { + IdentityRoleManagementException thrownException = null; + try { + appPortalRoleManagementListener.preUpdateUserListOfRole( + roleId, newUserIDList, deletedUserIDList, tenantDomain); + } catch (IdentityRoleManagementException e) { + thrownException = e; + } + assertNotNull(thrownException); + assertEquals(thrownException.getMessage(), "Deleting the tenant admin from 'Administrator' " + + "role belongs to the 'Console' application is not allowed."); + } else { + appPortalRoleManagementListener.preUpdateUserListOfRole( + roleId, newUserIDList, deletedUserIDList, tenantDomain); + + // Verify that the appPortalRoleManagementListener method is called when it should be + if (deletedUserIDList != null && isAdminRole && !isOrganization) { + verify(appPortalRoleManagementListener).preUpdateUserListOfRole( + roleId, newUserIDList, deletedUserIDList, tenantDomain); + } else { + verify(appPortalRoleManagementListener, never()).preUpdateUserListOfRole( + roleId, newUserIDList, deletedUserIDList, tenantDomain); + } + } + } +} + diff --git a/identity-apps-core/pom.xml b/identity-apps-core/pom.xml index 51b258ea82b..fce82dfcc18 100644 --- a/identity-apps-core/pom.xml +++ b/identity-apps-core/pom.xml @@ -563,6 +563,31 @@ org.wso2.identity.apps.taglibs.layout.controller ${project.version} + + + org.testng + testng + ${testng.version} + test + + + org.mockito + mockito-core + ${mockito.version} + test + + + org.mockito + mockito-testng + ${mockito-testng.version} + test + + + junit + junit + ${junit.version} + test + @@ -740,5 +765,11 @@ true false + + + 7.10.1 + 5.3.1 + 0.5.2 + 4.13.1 From 2db01844a9f38a5e685d01cbb2fd5cf083c42844 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Mon, 27 May 2024 03:22:07 +0530 Subject: [PATCH 05/16] Updated unit test code for preUpdatePermissionsForRole method --- .../AppPortalRoleManagementListenerTest.java | 234 ++++++++++-------- 1 file changed, 124 insertions(+), 110 deletions(-) diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java index 33156623905..13ebb4b47c3 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java @@ -1,117 +1,98 @@ package org.wso2.identity.apps.common.listener; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.mockito.testng.MockitoTestNGListener; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.openMocks; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - import org.mockito.Mock; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Listeners; +import org.mockito.MockedStatic; +import org.mockito.MockitoAnnotations; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.base.CarbonBaseConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.context.internal.CarbonContextDataHolder; import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil; -import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService; import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException; +import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService; import org.wso2.carbon.identity.role.v2.mgt.core.model.Role; import org.wso2.carbon.user.core.UserRealm; import org.wso2.carbon.user.core.common.AbstractUserStoreManager; import org.wso2.carbon.user.core.config.RealmConfiguration; -import org.wso2.carbon.utils.CarbonUtils; import org.wso2.identity.apps.common.internal.AppsCommonDataHolder; import org.wso2.identity.apps.common.listner.AppPortalRoleManagementListener; -import java.util.Arrays; +import java.nio.file.Paths; +import java.util.Collections; import java.util.List; -@Listeners(MockitoTestNGListener.class) +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.fail; +import static org.wso2.carbon.base.CarbonBaseConstants.CARBON_HOME; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.ADMINISTRATOR; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.APPLICATION; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.ORGANIZATION; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.RoleTableColumns.ROLE_NAME; +import static org.wso2.identity.apps.common.util.AppPortalConstants.CONSOLE_APP; + public class AppPortalRoleManagementListenerTest { - @Mock - private UserRealm mockUserRealm; + private AutoCloseable closeable; - @Mock - private AbstractUserStoreManager mockAbstractUserStoreManager; + private MockedStatic privilegedCarbonContext; + private MockedStatic organizationManagementUtil; + private MockedStatic appsCommonDataHolder; @Mock - private RealmConfiguration mockRealmConfiguration; + private UserRealm mockUserRealm; @Mock - private RoleManagementService mockRoleManagementService; + private RoleManagementService roleManagementService; @Mock - private Role mockRole; - - private static final String ADMINISTRATOR = "Administrator"; - private static final String APPLICATION = "application"; - private static final String CONSOLE_APP = "Console"; - private static final String carbonContext = "Console"; - private static final String adminUsername = "admin"; + private Role role; @BeforeMethod - public void setUp() throws Exception { - - openMocks(this); - - mockStatic(AppsCommonDataHolder.class); - AppsCommonDataHolder mockAppsCommonDataHolder = mock(AppsCommonDataHolder.class); - when(AppsCommonDataHolder.getInstance()).thenReturn(mockAppsCommonDataHolder); - when(mockAppsCommonDataHolder.getRoleManagementServiceV2()).thenReturn(mockRoleManagementService); - - mockCarbonContextForTenant(); - - when(mockUserRealm.getRealmConfiguration()).thenReturn(mockRealmConfiguration); - when(mockUserRealm.getUserStoreManager()).thenReturn(mockAbstractUserStoreManager); - - mockStatic(OrganizationManagementUtil.class); - + public void setUp() { + + setUpCarbonHome(); + privilegedCarbonContext = mockStatic(PrivilegedCarbonContext.class); + organizationManagementUtil = mockStatic(OrganizationManagementUtil.class); + appsCommonDataHolder = mockStatic(AppsCommonDataHolder.class); + mockCarbonContext(privilegedCarbonContext); + closeable = MockitoAnnotations.openMocks(this); } - private void mockCarbonContextForTenant() { - - try (MockedStatic privilegedCarbonContext = mockStatic(PrivilegedCarbonContext.class)) { + @AfterMethod + public void tearDown() throws Exception { - PrivilegedCarbonContext mockPrivilegedCarbonContext = mock(PrivilegedCarbonContext.class); - privilegedCarbonContext.when(PrivilegedCarbonContext::getThreadLocalCarbonContext) - .thenReturn(mockPrivilegedCarbonContext); - when(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()).thenReturn(mockUserRealm); - } + privilegedCarbonContext.close(); + organizationManagementUtil.close(); + appsCommonDataHolder.close(); + closeable.close(); } @DataProvider(name = "preUpdateUserListOfRoleDataProvider") public Object[][] preUpdateUserListOfRoleDataProvider() { return new Object[][]{ // Test case where deletedUserIDList == null - {"roleId", Arrays.asList("newUser"), null, "tenantDomain", true, false, null}, + {"roleId", Collections.emptyList(), null, CARBON_HOME, true, false, "adminUserId"}, - // Test case where !isAdministratorRole(roleId, tenantDomain) - {"roleId", Arrays.asList("newUser"), Arrays.asList("deletedUser"), "tenantDomain", false, false, null}, - - // Test case where both deletedUserIDList == null and !isAdministratorRole(roleId, tenantDomain) - {"roleId", Arrays.asList("newUser"), null, "tenantDomain", false, false, null}, - - // Test case where both deletedUserIDList != null and isAdministratorRole(roleId, tenantDomain) - {"roleId", Arrays.asList("newUser"), Arrays.asList("deletedUser"), "tenantDomain", true, false, null}, + // Test case where !isAdministratorRole + {"roleId", Collections.emptyList(), Collections.singletonList("deletedUser"), CARBON_HOME, false, false, + "adminUserId"}, // Test case where isOrganization == true - {"roleId", Arrays.asList("newUser"), Arrays.asList("deletedUser"), "tenantDomain", true, true, null}, - - // Test case where isOrganization == false - {"roleId", Arrays.asList("newUser"), Arrays.asList("deletedUser"), "tenantDomain", true, false, null}, + {"roleId", Collections.emptyList(), Collections.singletonList("deletedUser"), CARBON_HOME, true, true, + "adminUserId"}, // Test case where deletedUserIDList contains adminUserId - {"roleId", Arrays.asList("newUser"), Arrays.asList("adminUserId"), "tenantDomain", true, false, "adminUserId"} + {"roleId", Collections.emptyList(), Collections.singletonList("adminUserId"), CARBON_HOME, true, false, + "adminUserId"} }; } @@ -120,48 +101,81 @@ public void testPreUpdateUserListOfRole(String roleId, List newUserIDLis String tenantDomain, boolean isAdminRole, boolean isOrganization, String adminUserId) throws Exception { - //Create AppPortalRoleManagementListener Instance - AppPortalRoleManagementListener appPortalRoleManagementListener = - new AppPortalRoleManagementListener(true); - - // Mock the behavior of isAdministratorRole - when(mockRoleManagementService.getRole(roleId, tenantDomain)).thenReturn(mockRole); - when(mockRole.getName()).thenReturn(ADMINISTRATOR); - when(mockRole.getAudience()).thenReturn(APPLICATION); - when(mockRole.getAudienceName()).thenReturn(CONSOLE_APP); - - // Mock the behavior of OrganizationManagementUtil - when(OrganizationManagementUtil.isOrganization(tenantDomain)).thenReturn(isOrganization); - - if (adminUserId != null) { - when(mockRealmConfiguration.getAdminUserName()).thenReturn(adminUsername); - when(mockAbstractUserStoreManager.getUserIDFromUserName(adminUsername)).thenReturn(adminUserId); - } - - if (adminUserId != null && deletedUserIDList != null && deletedUserIDList.contains(adminUserId)) { - IdentityRoleManagementException thrownException = null; + AppPortalRoleManagementListener appPortalRoleManagementListener = spy( + new AppPortalRoleManagementListener(true)); + + // Set up the mock behaviors + organizationManagementUtil.when(() -> + OrganizationManagementUtil.isOrganization(tenantDomain)).thenReturn(isOrganization); + AbstractUserStoreManager mockUserStoreManager = mock(AbstractUserStoreManager.class); + when(mockUserRealm.getRealmConfiguration()).thenReturn(mock(RealmConfiguration.class)); + when(mockUserRealm.getRealmConfiguration().getAdminUserName()).thenReturn(ADMINISTRATOR); + when(mockUserRealm.getUserStoreManager()).thenReturn(mockUserStoreManager); + when(mockUserStoreManager.getUserIDFromUserName(anyString())) + .thenReturn(adminUserId); + mockAppsCommonDataHolder(appsCommonDataHolder); + when(roleManagementService.getRole(roleId, tenantDomain)).thenReturn(role); + setRoleAttributes(isAdminRole); + + // Call the method + if (!isAdminRole || deletedUserIDList == null || isOrganization || !deletedUserIDList.contains(adminUserId)) { + appPortalRoleManagementListener.preUpdateUserListOfRole(roleId, newUserIDList, deletedUserIDList, + tenantDomain); + } else { + Exception exception = null; try { - appPortalRoleManagementListener.preUpdateUserListOfRole( - roleId, newUserIDList, deletedUserIDList, tenantDomain); + appPortalRoleManagementListener.preUpdateUserListOfRole(roleId, newUserIDList, deletedUserIDList, + tenantDomain); + fail("Expected IdentityRoleManagementException was not thrown"); } catch (IdentityRoleManagementException e) { - thrownException = e; + exception = e; } - assertNotNull(thrownException); - assertEquals(thrownException.getMessage(), "Deleting the tenant admin from 'Administrator' " + - "role belongs to the 'Console' application is not allowed."); + assertNotNull(exception); + assertEquals(exception.getMessage(), "Deleting the tenant admin from 'Administrator' role " + + "belongs to the 'Console' application is not allowed."); + } + + if (deletedUserIDList == null || !isAdminRole) { + organizationManagementUtil.verify(() -> OrganizationManagementUtil.isOrganization(tenantDomain), never()); + } else if (isOrganization) { + organizationManagementUtil.verify(() -> OrganizationManagementUtil.isOrganization(tenantDomain)); + } + } + + private void setRoleAttributes(boolean isAdminRole) { + + if (isAdminRole) { + when(role.getName()).thenReturn(ADMINISTRATOR); + when(role.getAudience()).thenReturn(APPLICATION); + when(role.getAudienceName()).thenReturn(CONSOLE_APP); } else { - appPortalRoleManagementListener.preUpdateUserListOfRole( - roleId, newUserIDList, deletedUserIDList, tenantDomain); - - // Verify that the appPortalRoleManagementListener method is called when it should be - if (deletedUserIDList != null && isAdminRole && !isOrganization) { - verify(appPortalRoleManagementListener).preUpdateUserListOfRole( - roleId, newUserIDList, deletedUserIDList, tenantDomain); - } else { - verify(appPortalRoleManagementListener, never()).preUpdateUserListOfRole( - roleId, newUserIDList, deletedUserIDList, tenantDomain); - } + when(role.getName()).thenReturn(ROLE_NAME); + when(role.getAudience()).thenReturn(ORGANIZATION); + when(role.getAudienceName()).thenReturn("App1"); } } -} + private static void setUpCarbonHome() { + + String carbonHome = Paths.get(System.getProperty("user.dir"), "target", "test-classes").toString(); + System.setProperty(CARBON_HOME, carbonHome); + System.setProperty(CarbonBaseConstants.CARBON_CONFIG_DIR_PATH, Paths.get(carbonHome, + "repository/conf").toString()); + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + private void mockAppsCommonDataHolder(MockedStatic appsCommonDataHolder) { + + AppsCommonDataHolder mockAppsCommonDataHolder = mock(AppsCommonDataHolder.class); + appsCommonDataHolder.when(AppsCommonDataHolder::getInstance).thenReturn(mockAppsCommonDataHolder); + when(mockAppsCommonDataHolder.getRoleManagementServiceV2()).thenReturn(roleManagementService); + } + + private void mockCarbonContext(MockedStatic privilegedCarbonContext) { + + PrivilegedCarbonContext mockPrivilegedCarbonContext = mock(PrivilegedCarbonContext.class); + privilegedCarbonContext.when( + PrivilegedCarbonContext::getThreadLocalCarbonContext).thenReturn(mockPrivilegedCarbonContext); + when(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()).thenReturn(mockUserRealm); + } +} From 3ae5808c0c26434278ec9f6d692285935a163000 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Mon, 27 May 2024 03:30:19 +0530 Subject: [PATCH 06/16] Fixed checkstyle issues --- .../common/listener/AppPortalRoleManagementListenerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java index 13ebb4b47c3..60981939436 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java @@ -10,8 +10,8 @@ import org.wso2.carbon.base.CarbonBaseConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil; -import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException; import org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService; +import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException; import org.wso2.carbon.identity.role.v2.mgt.core.model.Role; import org.wso2.carbon.user.core.UserRealm; import org.wso2.carbon.user.core.common.AbstractUserStoreManager; @@ -24,8 +24,8 @@ import java.util.List; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; From 69401045a052c6ce2e191b7a6d0ff351983e0a99 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Mon, 27 May 2024 03:44:22 +0530 Subject: [PATCH 07/16] Removed additional dependancy --- .../components/org.wso2.identity.apps.common/pom.xml | 5 ----- identity-apps-core/pom.xml | 7 ------- 2 files changed, 12 deletions(-) diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml b/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml index 562aaeceeb8..c37a9f65929 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml +++ b/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml @@ -105,11 +105,6 @@ mockito-core test - - org.mockito - mockito-testng - test - junit junit diff --git a/identity-apps-core/pom.xml b/identity-apps-core/pom.xml index fce82dfcc18..7d66e7a890a 100644 --- a/identity-apps-core/pom.xml +++ b/identity-apps-core/pom.xml @@ -576,12 +576,6 @@ ${mockito.version} test - - org.mockito - mockito-testng - ${mockito-testng.version} - test - junit junit @@ -769,7 +763,6 @@ 7.10.1 5.3.1 - 0.5.2 4.13.1 From fcce526e72350ba7ce42d679acccf5eb99f78eaa Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Mon, 27 May 2024 09:32:43 +0530 Subject: [PATCH 08/16] Added license header --- .../AppPortalRoleManagementListenerTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java index 60981939436..c302241d32b 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org). + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.wso2.identity.apps.common.listener; import org.mockito.Mock; From a21768b2f6934170eac808eec609a7804c84698c Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Mon, 27 May 2024 09:41:59 +0530 Subject: [PATCH 09/16] Added testNG.xml --- .../src/test/resources/testng.xml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml new file mode 100644 index 00000000000..bee63aa7a66 --- /dev/null +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + From e896c7b6edf787da0ea82281ce5f520a3530a9d7 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Mon, 27 May 2024 09:46:58 +0530 Subject: [PATCH 10/16] Updated testNG.xml --- .../src/test/resources/testng.xml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml index bee63aa7a66..4186b08fe69 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml @@ -17,15 +17,10 @@ ~ under the License. --> - - + + - - - - - + From 26f2b2ac336db57fde90f40532fcbc215aff2bbb Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Mon, 27 May 2024 10:07:30 +0530 Subject: [PATCH 11/16] Upgraded PR builder Java version to 11 --- .github/workflows/pr-builder.yml | 7 ++++--- .../listener/AppPortalRoleManagementListenerTest.java | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml index bfc4c820c90..393767a1222 100644 --- a/.github/workflows/pr-builder.yml +++ b/.github/workflows/pr-builder.yml @@ -212,7 +212,7 @@ jobs: matrix: node-version: [ lts/* ] maven-version: [ 3.8.6 ] - java-version: [ 1.8 ] + java-version: [ 11 ] pnpm-version: [ 8.7.4 ] steps: - name: ⬇️ Checkout @@ -225,11 +225,12 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: ☕ Set up JDK 1.8 + - name: ☕ Set up JDK 11 id: jdk-setup - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: java-version: ${{ matrix.java-version }} + distribution: "adopt" cache: maven - name: 🦩 Set up Maven diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java index c302241d32b..06008593142 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java @@ -56,6 +56,9 @@ import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.RoleTableColumns.ROLE_NAME; import static org.wso2.identity.apps.common.util.AppPortalConstants.CONSOLE_APP; +/** + * Test class for AppPortalRoleManagementListener test cases. + */ public class AppPortalRoleManagementListenerTest { private AutoCloseable closeable; From cbf3fe1d5b659af14d06a29f4bdda3c9afcb8759 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Mon, 27 May 2024 12:09:44 +0530 Subject: [PATCH 12/16] Revert "Upgraded PR builder Java version to 11" This reverts commit 26f2b2ac336db57fde90f40532fcbc215aff2bbb. --- .github/workflows/pr-builder.yml | 7 +++---- .../listener/AppPortalRoleManagementListenerTest.java | 3 --- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml index 393767a1222..bfc4c820c90 100644 --- a/.github/workflows/pr-builder.yml +++ b/.github/workflows/pr-builder.yml @@ -212,7 +212,7 @@ jobs: matrix: node-version: [ lts/* ] maven-version: [ 3.8.6 ] - java-version: [ 11 ] + java-version: [ 1.8 ] pnpm-version: [ 8.7.4 ] steps: - name: ⬇️ Checkout @@ -225,12 +225,11 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: ☕ Set up JDK 11 + - name: ☕ Set up JDK 1.8 id: jdk-setup - uses: actions/setup-java@v2 + uses: actions/setup-java@v1 with: java-version: ${{ matrix.java-version }} - distribution: "adopt" cache: maven - name: 🦩 Set up Maven diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java index 06008593142..c302241d32b 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java @@ -56,9 +56,6 @@ import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.RoleTableColumns.ROLE_NAME; import static org.wso2.identity.apps.common.util.AppPortalConstants.CONSOLE_APP; -/** - * Test class for AppPortalRoleManagementListener test cases. - */ public class AppPortalRoleManagementListenerTest { private AutoCloseable closeable; From a01b15bbbdc67511003a1c723cbe362f391fbd8a Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Mon, 27 May 2024 12:17:34 +0530 Subject: [PATCH 13/16] Added review suggestions --- .../apps/common/listner/AppPortalRoleManagementListener.java | 4 ++-- .../common/listener/AppPortalRoleManagementListenerTest.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java index 46e650697e0..0513c4faed0 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java @@ -107,8 +107,8 @@ public void preUpdateUserListOfRole(String roleId, List newUserIDList, L return; } } catch (OrganizationManagementException e) { - throw new IdentityRoleManagementException(INVALID_REQUEST.getCode(), - "Failed to determine if the tenant is a sub-organization for tenant domain: " + tenantDomain, e); + throw new IdentityRoleManagementException("Failed to determine if the tenant is a sub-organization for " + + "tenant domain: " + tenantDomain, e); } String adminUserId; diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java index c302241d32b..06008593142 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java @@ -56,6 +56,9 @@ import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.RoleTableColumns.ROLE_NAME; import static org.wso2.identity.apps.common.util.AppPortalConstants.CONSOLE_APP; +/** + * Test class for AppPortalRoleManagementListener test cases. + */ public class AppPortalRoleManagementListenerTest { private AutoCloseable closeable; From 6cc10e90271be192879dc7408d15d2710b11e55d Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Tue, 28 May 2024 00:34:09 +0530 Subject: [PATCH 14/16] Added review suggestions --- .../org.wso2.identity.apps.common/pom.xml | 5 --- .../AppPortalRoleManagementListener.java | 2 +- .../AppPortalRoleManagementListenerTest.java | 42 +++++++++++-------- .../src/test/resources/testng.xml | 2 +- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml b/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml index 85a95ff41c1..3d9e29fd259 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml +++ b/identity-apps-core/components/org.wso2.identity.apps.common/pom.xml @@ -105,11 +105,6 @@ mockito-core test - - junit - junit - test - diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java index 0513c4faed0..a16d320c33b 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/main/java/org/wso2/identity/apps/common/listner/AppPortalRoleManagementListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java index 06008593142..90dc5fdcdbc 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/java/org/wso2/identity/apps/common/listener/AppPortalRoleManagementListenerTest.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org). + * Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at @@ -61,6 +61,13 @@ */ public class AppPortalRoleManagementListenerTest { + private final String roleId = "roleId"; + private final String deletedUserId = "deletedUserId"; + private final String adminUserId = "adminUserId"; + private final String tenantDomain = "abc.com"; + private final boolean isAdminRole = true; + private final boolean isOrganization = true; + private AutoCloseable closeable; private MockedStatic privilegedCarbonContext; @@ -99,20 +106,20 @@ public void tearDown() throws Exception { @DataProvider(name = "preUpdateUserListOfRoleDataProvider") public Object[][] preUpdateUserListOfRoleDataProvider() { return new Object[][]{ - // Test case where deletedUserIDList == null - {"roleId", Collections.emptyList(), null, CARBON_HOME, true, false, "adminUserId"}, + // Test case where deletedUserIDList == null. + {roleId, Collections.emptyList(), null, tenantDomain, isAdminRole, !isOrganization, adminUserId}, - // Test case where !isAdministratorRole - {"roleId", Collections.emptyList(), Collections.singletonList("deletedUser"), CARBON_HOME, false, false, - "adminUserId"}, + // Test case where !isAdministratorRole. + {roleId, Collections.emptyList(), Collections.singletonList(deletedUserId), tenantDomain, !isAdminRole, + !isOrganization, adminUserId}, - // Test case where isOrganization == true - {"roleId", Collections.emptyList(), Collections.singletonList("deletedUser"), CARBON_HOME, true, true, - "adminUserId"}, + // Test case where isOrganization == true. + {roleId, Collections.emptyList(), Collections.singletonList(deletedUserId), tenantDomain, isAdminRole, + isOrganization, adminUserId}, - // Test case where deletedUserIDList contains adminUserId - {"roleId", Collections.emptyList(), Collections.singletonList("adminUserId"), CARBON_HOME, true, false, - "adminUserId"} + // Test case where deletedUserIDList contains adminUserId. + {roleId, Collections.emptyList(), Collections.singletonList(adminUserId), tenantDomain, isAdminRole, + !isOrganization, adminUserId} }; } @@ -124,20 +131,19 @@ public void testPreUpdateUserListOfRole(String roleId, List newUserIDLis AppPortalRoleManagementListener appPortalRoleManagementListener = spy( new AppPortalRoleManagementListener(true)); - // Set up the mock behaviors + // Set up the mock behaviors. organizationManagementUtil.when(() -> OrganizationManagementUtil.isOrganization(tenantDomain)).thenReturn(isOrganization); AbstractUserStoreManager mockUserStoreManager = mock(AbstractUserStoreManager.class); when(mockUserRealm.getRealmConfiguration()).thenReturn(mock(RealmConfiguration.class)); when(mockUserRealm.getRealmConfiguration().getAdminUserName()).thenReturn(ADMINISTRATOR); when(mockUserRealm.getUserStoreManager()).thenReturn(mockUserStoreManager); - when(mockUserStoreManager.getUserIDFromUserName(anyString())) - .thenReturn(adminUserId); + when(mockUserStoreManager.getUserIDFromUserName(anyString())).thenReturn(adminUserId); mockAppsCommonDataHolder(appsCommonDataHolder); when(roleManagementService.getRole(roleId, tenantDomain)).thenReturn(role); setRoleAttributes(isAdminRole); - // Call the method + // Call the method. if (!isAdminRole || deletedUserIDList == null || isOrganization || !deletedUserIDList.contains(adminUserId)) { appPortalRoleManagementListener.preUpdateUserListOfRole(roleId, newUserIDList, deletedUserIDList, tenantDomain); @@ -171,7 +177,7 @@ private void setRoleAttributes(boolean isAdminRole) { } else { when(role.getName()).thenReturn(ROLE_NAME); when(role.getAudience()).thenReturn(ORGANIZATION); - when(role.getAudienceName()).thenReturn("App1"); + when(role.getAudienceName()).thenReturn("org1"); } } diff --git a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml index 4186b08fe69..12bffbb899f 100644 --- a/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml +++ b/identity-apps-core/components/org.wso2.identity.apps.common/src/test/resources/testng.xml @@ -1,6 +1,6 @@ 7.10.1 5.3.1 - 4.13.1 From 93305a6091c3f01c3effdec8c1692e8f1f4b7f80 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Tue, 28 May 2024 16:20:02 +0530 Subject: [PATCH 16/16] Updated github workflow java setup version to V3 --- .github/workflows/pr-builder.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-builder.yml b/.github/workflows/pr-builder.yml index 393767a1222..b50ef8261c4 100644 --- a/.github/workflows/pr-builder.yml +++ b/.github/workflows/pr-builder.yml @@ -227,7 +227,7 @@ jobs: - name: ☕ Set up JDK 11 id: jdk-setup - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: ${{ matrix.java-version }} distribution: "adopt"