-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add userId in successful user-registration response.
- Loading branch information
1 parent
4ea5d99
commit 7d7b250
Showing
5 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,7 @@ public class UserSelfRegistrationManagerTest { | |
private final String TEST_USERSTORE_DOMAIN = "PRIMARY"; | ||
private final String TEST_SECONDARY_USERSTORE_DOMAIN = "SECONDARY"; | ||
private final String TEST_USER_NAME = "dummyUser"; | ||
private final String TEST_USER_ID = "dummyUserId"; | ||
private final String TEST_INVALID_USER_NAME = "IS"; | ||
private final String TEST_CLAIM_URI = "ttp://wso2.org/claims/emailaddress"; | ||
private final String TEST_CLAIM_VALUE = "[email protected]"; | ||
|
@@ -1149,7 +1150,11 @@ public void testRegisterUser() throws Exception { | |
|
||
User user = getUser(); | ||
mockConfigurations("true", "true"); | ||
when(userStoreManager.isExistingRole(eq(IdentityRecoveryConstants.SELF_SIGNUP_ROLE))).thenReturn(true); | ||
when(userRealm.getUserStoreManager()).thenReturn(abstractUserStoreManager); | ||
when(abstractUserStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(userStoreManager); | ||
when(abstractUserStoreManager.isExistingRole(eq(IdentityRecoveryConstants.SELF_SIGNUP_ROLE))).thenReturn(true); | ||
when(abstractUserStoreManager.addUserWithID(anyString(), anyString(), any(), any(), isNull())) | ||
.thenReturn(getRegisteredUser()); | ||
when(privilegedCarbonContext.getOSGiService(any(), isNull())).thenReturn(notificationChannelManager); | ||
when(notificationChannelManager.resolveCommunicationChannel(anyString(), anyString(), anyString(), any())) | ||
.thenReturn(NotificationChannels.EMAIL_CHANNEL.getChannelType()); | ||
|
@@ -1161,7 +1166,8 @@ public void testRegisterUser() throws Exception { | |
|
||
User registeredUser = notificationResponseBean.getUser(); | ||
assertEquals(user.getUserName(), registeredUser.getUserName()); | ||
verify(userStoreManager).addUser(anyString(), anyString(), any(), any(), isNull()); | ||
assertEquals(registeredUser.getNullableUserId(), TEST_USER_ID); | ||
verify(abstractUserStoreManager).addUserWithID(anyString(), anyString(), any(), any(), isNull()); | ||
verify(consentManger).addConsent(any()); | ||
verify(identityEventService, atLeastOnce()).handleEvent(any()); | ||
} | ||
|
@@ -1172,6 +1178,10 @@ public void testRegisterUserNotificationExternallyAccountLockedOnCreation() thro | |
User user = new User(); | ||
user.setUserName(TEST_USER_NAME); | ||
Property property = new Property(IdentityRecoveryConstants.Consent.CONSENT, consentData); | ||
when(userRealm.getUserStoreManager()).thenReturn(abstractUserStoreManager); | ||
when(abstractUserStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(userStoreManager); | ||
when(abstractUserStoreManager.addUserWithID(anyString(), anyString(), any(), any(), isNull())) | ||
.thenReturn(getRegisteredUser()); | ||
|
||
try (MockedStatic<Utils> mockedUtils = mockStatic(Utils.class)) { | ||
mockedUtils.when(() -> Utils.getSignUpConfigs(eq(ACCOUNT_LOCK_ON_CREATION), anyString())) | ||
|
@@ -1192,7 +1202,9 @@ public void testRegisterUserNotificationExternallyAccountLockedOnCreation() thro | |
assertEquals(IdentityRecoveryConstants.SuccessEvents | ||
.SUCCESS_STATUS_CODE_SUCCESSFUL_USER_CREATION_EXTERNAL_VERIFICATION.getCode(), | ||
notificationResponseBean.getCode()); | ||
verify(userStoreManager).addUser(anyString(), anyString(), any(), any(), isNull()); | ||
User registeredUser = notificationResponseBean.getUser(); | ||
verify(abstractUserStoreManager).addUserWithID(anyString(), anyString(), any(), any(), isNull()); | ||
assertEquals(registeredUser.getNullableUserId(), TEST_USER_ID); | ||
verify(consentManger).addConsent(any()); | ||
verify(identityEventService, atLeastOnce()).handleEvent(any()); | ||
} | ||
|
@@ -1210,6 +1222,10 @@ public void testRegisterUserVerifiedPreferredChannel() throws Exception { | |
.thenReturn("false"); | ||
when(consentUtilityService.filterPIIsFromReceipt(any(), any())).thenReturn( | ||
new HashSet<>(Arrays.asList(emailVerifiedClaimURI))); | ||
when(userRealm.getUserStoreManager()).thenReturn(abstractUserStoreManager); | ||
when(abstractUserStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(userStoreManager); | ||
when(abstractUserStoreManager.addUserWithID(anyString(), anyString(), any(), any(), isNull())) | ||
.thenReturn(getRegisteredUser()); | ||
|
||
try (MockedStatic<Utils> mockedUtils = mockStatic(Utils.class)) { | ||
mockedUtils.when(() -> Utils.getSignUpConfigs(eq(ACCOUNT_LOCK_ON_CREATION), anyString())) | ||
|
@@ -1235,7 +1251,9 @@ public void testRegisterUserVerifiedPreferredChannel() throws Exception { | |
assertEquals(IdentityRecoveryConstants.SuccessEvents | ||
.SUCCESS_STATUS_CODE_SUCCESSFUL_USER_CREATION_WITH_VERIFIED_CHANNEL.getCode(), | ||
notificationResponseBean.getCode()); | ||
verify(userStoreManager).addUser(anyString(), anyString(), any(), any(), isNull()); | ||
User registeredUser = notificationResponseBean.getUser(); | ||
verify(abstractUserStoreManager).addUserWithID(anyString(), anyString(), any(), any(), isNull()); | ||
assertEquals(registeredUser.getNullableUserId(), TEST_USER_ID); | ||
verify(consentManger).addConsent(any()); | ||
verify(identityEventService, atLeastOnce()).handleEvent(any()); | ||
} | ||
|
@@ -1779,6 +1797,16 @@ private User getUser() { | |
return user; | ||
} | ||
|
||
private org.wso2.carbon.user.core.common.User getRegisteredUser() { | ||
|
||
org.wso2.carbon.user.core.common.User user = new org.wso2.carbon.user.core.common.User(); | ||
user.setUsername(TEST_USER_NAME); | ||
user.setUserStoreDomain(TEST_USERSTORE_DOMAIN); | ||
user.setTenantDomain(TEST_TENANT_DOMAIN_NAME); | ||
user.setUserID(TEST_USER_ID); | ||
return user; | ||
} | ||
|
||
private void mockMultiAttributeEnabled(Boolean isEnabled) throws ClaimMetadataException { | ||
|
||
mockedIdentityUtil.when(() -> IdentityUtil.getProperty( | ||
|