From bb88230c821f3b248970b09260279514e84ac0d1 Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Thu, 24 Oct 2024 12:05:53 +0530 Subject: [PATCH 1/3] Fix unit tests --- .../invitation/management/InvitationCoreServiceImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImplTest.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImplTest.java index dffb45788..acd974f3d 100644 --- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImplTest.java +++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImplTest.java @@ -355,13 +355,13 @@ public Object[][] inviteNotificationManagingData() { true, "false", "false", true }, { - false, null, "false", true + true, "true", "true", false }, { true, "true", "false", false }, { - true, "true", "true", false + false, null, "false", true }, { false, null, "true", false From 7d51146052241bdbe5471edb9c1094436a5cef70 Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Thu, 24 Oct 2024 12:42:37 +0530 Subject: [PATCH 2/3] Downgrade mockito version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 067152219..55a7a0a70 100644 --- a/pom.xml +++ b/pom.xml @@ -577,7 +577,7 @@ 1.0.0 [1.0.0,1.0.3) - 5.3.1 + 4.6.1 5.2.0 6.9.10 2.22.0 From 8c75c3db07b37a9cf9639b7bd43df635d215e2fc Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Thu, 24 Oct 2024 22:12:19 +0530 Subject: [PATCH 3/3] Add unit test for validate invite for sub org console role --- .../InvitationCoreServiceImplTest.java | 58 ++++++++++++++----- pom.xml | 2 +- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImplTest.java b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImplTest.java index acd974f3d..3ce91978b 100644 --- a/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImplTest.java +++ b/components/org.wso2.carbon.identity.organization.user.invitation.management/src/test/java/org/wso2/carbon/identity/organization/user/invitation/management/InvitationCoreServiceImplTest.java @@ -50,9 +50,11 @@ import org.wso2.carbon.identity.recovery.util.Utils; 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.identity.role.v2.mgt.core.model.RoleBasicInfo; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.core.common.AbstractUserStoreManager; +import org.wso2.carbon.user.core.common.Group; import org.wso2.carbon.user.core.service.RealmService; import java.nio.file.Paths; @@ -60,6 +62,7 @@ import java.util.Collections; import java.util.List; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; @@ -116,6 +119,9 @@ public class InvitationCoreServiceImplTest { private UserRealm userRealm; @Mock private AbstractUserStoreManager userStoreManager; + @Mock + private RoleManagementService roleManagementService; + @Mock private IdentityEventService identityEventService; @@ -164,6 +170,11 @@ public void setUp() throws Exception { when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); when(userStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(userStoreManager); doNothing().when(identityEventService).handleEvent(isA(Event.class)); + when(userStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(userStoreManager); + + UserInvitationMgtDataHolder.getInstance().setRoleManagementService(roleManagementService); + when(roleManagementService.getRoleWithoutUsers(anyString(), anyString())).thenReturn(buildRoleInfo()); + when(roleManagementService.isExistingRole(anyString(), anyString())).thenReturn(true); } private Role buildRoleInfo() { @@ -184,6 +195,7 @@ public void tearDown() throws Exception { Mockito.reset(userRealm); Mockito.reset(userStoreManager); Mockito.reset(identityEventService); + Mockito.reset(roleManagementService); } @@ -204,9 +216,6 @@ public void testGetInvitation() throws Exception { identityUtil.when(() -> IdentityTenantUtil.getTenantId(anyString())).thenReturn(-1234); identityDBUtil.when(() -> IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(getConnection()); - RoleManagementService roleManagementService = mock(RoleManagementService.class); - UserInvitationMgtDataHolder.getInstance().setRoleManagementService(roleManagementService); - when(roleManagementService.getRoleWithoutUsers(anyString(), anyString())).thenReturn(buildRoleInfo()); OrganizationManager organizationManager = mock(OrganizationManager.class); UserInvitationMgtDataHolder.getInstance().setOrganizationManagerService(organizationManager); when(organizationManager.resolveTenantDomain(anyString())).thenReturn("carbon.super"); @@ -349,22 +358,22 @@ public Object[][] inviteNotificationManagingData() { return new Object[][]{ { - true, "false", "true", true + true, "false", "true", true, true }, { - true, "false", "false", true + true, "false", "false", true, false }, { - true, "true", "true", false + true, "true", "true", false, true }, { - true, "true", "false", false + true, "true", "false", false, false }, { - false, null, "false", true + false, null, "false", true, true }, { - false, null, "true", false + false, null, "true", false, false } }; } @@ -373,7 +382,8 @@ public Object[][] inviteNotificationManagingData() { public void testConfirmationCodeReturnOnInviteCreation(boolean setNotificationManagingProperty, String propertyValue, String isNotificationManagedInternallyForOrg, - boolean isConfirmationCodeReturnInResponse) + boolean isConfirmationCodeReturnInResponse, + boolean inviteConsoleRole) throws Exception { String username = "alex"; @@ -388,7 +398,14 @@ public void testConfirmationCodeReturnOnInviteCreation(boolean setNotificationMa InvitationDO invitation = new InvitationDO(); invitation.setUsernamesList(Collections.singletonList(username)); invitation.setUserDomain(userStoreDomain); - invitation.setRoleAssignments(null); + + if (inviteConsoleRole) { + RoleAssignments roleAssignments = buildRoleAssignments(roleList); + roleAssignments.setRole(roleList[0]); + invitation.setRoleAssignments(new RoleAssignments[]{roleAssignments}); + invitation.setGroupAssignments(new GroupAssignments[]{buildGroupAssignments(groupList)}); + } + invitation.setUserRedirectUrl("https://localhost:8080/travel-manager-001/invitations/accept"); if (setNotificationManagingProperty) { invitation.setInvitationProperties( @@ -423,18 +440,29 @@ public void testConfirmationCodeReturnOnInviteCreation(boolean setNotificationMa UserRealm userRealmParentOrg = mock(UserRealm.class); AbstractUserStoreManager userStoreManagerParentOrg = mock(AbstractUserStoreManager.class); + AbstractUserStoreManager secondaryUserStoreManagerParentOrg = mock(AbstractUserStoreManager.class); + + if (inviteConsoleRole) { + RoleBasicInfo roleBasicInfo = new RoleBasicInfo(); + roleBasicInfo.setAudienceName("Console"); + List groupsList = new ArrayList<>(); + groupsList.add(new Group("123", "adminGroup")); + when(userStoreManagerParentOrg.getGroupListOfUser(anyString(), any(), any())) + .thenReturn(groupsList); + when(roleManagementService.getRoleListOfGroups(any(), anyString())) + .thenReturn(Collections.singletonList(roleBasicInfo)); + } + mockParentOrgDetails(userStoreManagerParentOrg, userStoreQualifiedUsername, userId, userRealmParentOrg, realmService, tenantDomainOfParentOrg, organizationManager, parentOrgId, identityDBUtil); when(userStoreManagerParentOrg.getSecondaryUserStoreManager(anyString())) - .thenReturn(userStoreManagerParentOrg); + .thenReturn(secondaryUserStoreManagerParentOrg); UserRealm userRealmSubOrg = mock(UserRealm.class); AbstractUserStoreManager userStoreManagerSubOrg = mock(AbstractUserStoreManager.class); mockSubOrgDetails(userStoreManagerSubOrg, userStoreQualifiedUsername, userRealmSubOrg, realmService, tenantDomainOfSubOrg, organizationManager, subOrgId, identityDBUtil); - - when(userStoreManagerParentOrg.getSecondaryUserStoreManager(anyString())) - .thenReturn(userStoreManagerParentOrg); + when(userStoreManagerSubOrg.isGroupExist(anyString())).thenReturn(true); orgSharedUserUtil.when(() -> OrganizationSharedUserUtil .getUserManagedOrganizationClaim(userStoreManagerSubOrg, userId)).thenReturn(parentOrgId); diff --git a/pom.xml b/pom.xml index 55a7a0a70..067152219 100644 --- a/pom.xml +++ b/pom.xml @@ -577,7 +577,7 @@ 1.0.0 [1.0.0,1.0.3) - 4.6.1 + 5.3.1 5.2.0 6.9.10 2.22.0