-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #881 from RushanNanayakkara/patch_internal_2647
Pick username java regex from alternative key
- Loading branch information
Showing
2 changed files
with
70 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,7 +236,9 @@ public class UserSelfRegistrationManagerTest { | |
private final String TEST_TENANT_DOMAIN_NAME = "carbon.super"; | ||
private final int TEST_TENANT_ID = 12; | ||
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_INVALID_USER_NAME = "IS"; | ||
private final String TEST_CLAIM_URI = "ttp://wso2.org/claims/emailaddress"; | ||
private final String TEST_CLAIM_VALUE = "[email protected]"; | ||
private final String TEST_MOBILE_CLAIM_VALUE = "0775553443"; | ||
|
@@ -1429,6 +1431,7 @@ public void testIsMatchUserNameRegex() | |
mockedUserCoreUtil.when(() -> UserCoreUtil.removeDomainFromName(anyString())).thenReturn(TEST_USER_NAME); | ||
mockedIdentityUtil.when(() -> IdentityUtil.extractDomainFromName(anyString())) | ||
.thenReturn(TEST_USERSTORE_DOMAIN); | ||
when(realmConfiguration.isPrimary()).thenReturn(true); | ||
when(realmConfiguration.getTenantId()).thenReturn(TEST_TENANT_ID); | ||
mockedIdentityUtil.when(() -> IdentityTenantUtil.getTenantDomain(TEST_TENANT_ID)) | ||
.thenReturn(TEST_TENANT_DOMAIN_NAME); | ||
|
@@ -1438,10 +1441,16 @@ public void testIsMatchUserNameRegex() | |
when(validationConfiguration.getField()).thenReturn("username"); | ||
mockedIdentityUtil.when(() -> IdentityUtil.getProperty(Constants.INPUT_VALIDATION_USERNAME_ENABLED_CONFIG)) | ||
.thenReturn("false"); | ||
when(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USER_NAME_JAVA_REG_EX)) | ||
.thenReturn(null); | ||
boolean isMatchUsernameRegex = | ||
userSelfRegistrationManager.isMatchUserNameRegex(TEST_TENANT_DOMAIN_NAME, TEST_USER_NAME); | ||
assertTrue(isMatchUsernameRegex); | ||
|
||
when(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USER_NAME_JAVA_REG_EX)) | ||
.thenReturn("^[\\S]{5,30}$"); | ||
|
||
boolean isMatchUsernameRegex = | ||
isMatchUsernameRegex = | ||
userSelfRegistrationManager.isMatchUserNameRegex(TEST_TENANT_DOMAIN_NAME, TEST_USER_NAME); | ||
assertTrue(isMatchUsernameRegex); | ||
|
||
|
@@ -1486,6 +1495,62 @@ public void testIsMatchUserNameRegex() | |
} | ||
} | ||
|
||
@Test | ||
public void testIsMatchUserNameRegexForSecondaryUserStore() | ||
throws IdentityRecoveryException, InputValidationMgtException, | ||
UserStoreException { | ||
|
||
mockedMultiTenantUtils.when(() -> MultitenantUtils | ||
.getTenantAwareUsername(eq(TEST_USER_NAME))).thenReturn(TEST_USER_NAME); | ||
mockedUserCoreUtil.when(() -> UserCoreUtil.removeDomainFromName(eq(TEST_USER_NAME))).thenReturn(TEST_USER_NAME); | ||
mockedIdentityUtil.when(() -> IdentityUtil.extractDomainFromName(anyString())) | ||
.thenReturn(TEST_SECONDARY_USERSTORE_DOMAIN); | ||
when(realmConfiguration.getTenantId()).thenReturn(TEST_TENANT_ID); | ||
mockedIdentityUtil.when(() -> IdentityTenantUtil.getTenantDomain(TEST_TENANT_ID)) | ||
.thenReturn(TEST_TENANT_DOMAIN_NAME); | ||
|
||
when(inputValidationManagementService.getInputValidationConfiguration(anyString())) | ||
.thenReturn(Arrays.asList(validationConfiguration)); | ||
when(validationConfiguration.getField()).thenReturn("username"); | ||
mockedIdentityUtil.when(() -> IdentityUtil.getProperty(Constants.INPUT_VALIDATION_USERNAME_ENABLED_CONFIG)) | ||
.thenReturn("false"); | ||
when(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USER_NAME_JAVA_REG_EX)) | ||
.thenReturn(null); | ||
when(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USER_NAME_JAVA_REG)) | ||
.thenReturn("^[\\S]{5,30}$"); | ||
|
||
// regex read from fallback key | ||
boolean isMatchUsernameRegex = | ||
userSelfRegistrationManager.isMatchUserNameRegex(TEST_TENANT_DOMAIN_NAME, TEST_USER_NAME); | ||
assertTrue(isMatchUsernameRegex); | ||
|
||
mockedMultiTenantUtils.when(() -> MultitenantUtils | ||
.getTenantAwareUsername(eq(TEST_INVALID_USER_NAME))).thenReturn(TEST_INVALID_USER_NAME); | ||
mockedUserCoreUtil.when(() -> UserCoreUtil.removeDomainFromName(eq(TEST_INVALID_USER_NAME))) | ||
.thenReturn(TEST_INVALID_USER_NAME); | ||
isMatchUsernameRegex = | ||
userSelfRegistrationManager.isMatchUserNameRegex(TEST_TENANT_DOMAIN_NAME, TEST_INVALID_USER_NAME); | ||
assertFalse(isMatchUsernameRegex); | ||
|
||
// regex read main key | ||
when(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USER_NAME_JAVA_REG_EX)) | ||
.thenReturn("^[\\S]{5,30}$"); | ||
when(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USER_NAME_JAVA_REG)) | ||
.thenReturn(null); | ||
isMatchUsernameRegex = | ||
userSelfRegistrationManager.isMatchUserNameRegex(TEST_TENANT_DOMAIN_NAME, TEST_USER_NAME); | ||
assertTrue(isMatchUsernameRegex); | ||
|
||
mockedMultiTenantUtils.when(() -> MultitenantUtils | ||
.getTenantAwareUsername(eq(TEST_INVALID_USER_NAME))).thenReturn(TEST_INVALID_USER_NAME); | ||
mockedUserCoreUtil.when(() -> UserCoreUtil.removeDomainFromName(eq(TEST_INVALID_USER_NAME))) | ||
.thenReturn(TEST_INVALID_USER_NAME); | ||
isMatchUsernameRegex = | ||
userSelfRegistrationManager.isMatchUserNameRegex(TEST_TENANT_DOMAIN_NAME, TEST_INVALID_USER_NAME); | ||
assertFalse(isMatchUsernameRegex); | ||
|
||
} | ||
|
||
@Test | ||
public void testPreValidatePasswordWithConfirmationKey() throws Exception { | ||
|
||
|