diff --git a/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/IdentityRecoveryConstants.java b/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/IdentityRecoveryConstants.java index 0bbe6e995..89a02917e 100644 --- a/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/IdentityRecoveryConstants.java +++ b/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/IdentityRecoveryConstants.java @@ -635,6 +635,7 @@ public static class ConnectorConfig { "UseNumbersInOTP"; public static final String SELF_REGISTRATION_OTP_LENGTH = "SelfRegistration.OTP.OTPLength"; public static final String SEND_CONFIRMATION_NOTIFICATION = "SelfRegistration.SendConfirmationOnCreation"; + public static final String SHOW_USERNAME_UNAVAILABILITY = "SelfRegistration.ShowUsernameUnavailability"; public static final String SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE = "SelfRegistration.Notification" + ".InternallyManage"; public static final String SELF_REGISTRATION_RE_CAPTCHA = "SelfRegistration.ReCaptcha"; diff --git a/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/SelfRegistrationConfigImpl.java b/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/SelfRegistrationConfigImpl.java index e889530ec..e1fd72026 100644 --- a/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/SelfRegistrationConfigImpl.java +++ b/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/SelfRegistrationConfigImpl.java @@ -99,6 +99,8 @@ public Map getPropertyNameMapping() { "OTP length"); nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION, "Enable Account Confirmation On Creation"); + nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY, + "Show username unavailability"); nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE, "Manage notifications sending internally"); nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA, "Prompt reCaptcha"); @@ -144,6 +146,8 @@ public Map getPropertyDescriptionMapping() { "Length of the OTP for SMS and e-mail verifications. OTP length must be 4-10."); descriptionMapping.put(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION, "Enable user account confirmation when the user account is not locked on creation"); + descriptionMapping.put(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY, + "Show a descriptive error message to the user if the username is already taken. However, this may lead to username enumeration"); descriptionMapping.put(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE, "Disable if the client application handles notification sending"); descriptionMapping.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA, @@ -184,6 +188,7 @@ public String[] getPropertyNames() { properties.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_NUMBERS_IN_OTP); properties.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_OTP_LENGTH); properties.add(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION); + properties.add(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY); properties.add(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE); properties.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA); properties.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_VERIFICATION_CODE_EXPIRY_TIME); @@ -210,6 +215,7 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG String useNumbersInOTP = StringUtils.EMPTY; String otpLength = "6"; String enableSendNotificationOnCreation = "false"; + String showUsernameUnavailability = "true"; String enableNotificationInternallyManage = "true"; String enableSelfRegistrationReCaptcha = "true"; String verificationCodeExpiryTime = "1440"; @@ -237,6 +243,8 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_OTP_LENGTH); String sendNotificationOnCreationProperty = IdentityUtil.getProperty( IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION); + String showUsernameUnavailabilityProperty = IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY); String notificationInternallyMangedProperty = IdentityUtil.getProperty( IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE); String reCaptchaProperty = IdentityUtil.getProperty( @@ -282,6 +290,9 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG if (StringUtils.isNotEmpty(sendNotificationOnCreationProperty)) { enableSendNotificationOnCreation = sendNotificationOnCreationProperty; } + if (StringUtils.isNotEmpty(showUsernameUnavailabilityProperty)) { + showUsernameUnavailability = showUsernameUnavailabilityProperty; + } if (StringUtils.isNotEmpty(notificationInternallyMangedProperty)) { enableNotificationInternallyManage = notificationInternallyMangedProperty; } @@ -329,6 +340,8 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG otpLength); defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION, enableSendNotificationOnCreation); + defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY, + showUsernameUnavailability); defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE, enableNotificationInternallyManage); defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA, @@ -399,6 +412,9 @@ public Map getMetaData() { meta.put(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION, getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + meta.put(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + meta.put(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE, getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); diff --git a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/SelfRegistrationConfigImplTest.java b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/SelfRegistrationConfigImplTest.java index 7465a1681..ad696270d 100644 --- a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/SelfRegistrationConfigImplTest.java +++ b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/SelfRegistrationConfigImplTest.java @@ -18,8 +18,14 @@ package org.wso2.carbon.identity.recovery.connector; import org.apache.commons.lang.StringUtils; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import org.wso2.carbon.identity.application.common.model.Property; +import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.governance.IdentityGovernanceException; import org.wso2.carbon.identity.governance.IdentityMgtConstants; import org.wso2.carbon.identity.recovery.IdentityRecoveryConstants; @@ -35,12 +41,14 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; +import static org.wso2.carbon.identity.governance.IdentityGovernanceUtil.getPropertyObject; /** * This class does unit test coverage for SelfRegistrationConfigImpl class. */ public class SelfRegistrationConfigImplTest { + private MockedStatic mockedIdentityUtil; private SelfRegistrationConfigImpl selfRegistrationConfigImpl; private static final String CONNECTOR_NAME = "self-sign-up"; private static final String CATEGORY = "User Onboarding"; @@ -53,12 +61,24 @@ public class SelfRegistrationConfigImplTest { private static final String CONSENT_LIST_URL = "/carbon/consent/list-purposes.jsp?purposeGroup=" + SYSTEM_PURPOSE_GROUP + "&purposeGroupType=" + SIGNUP_PURPOSE_GROUP_TYPE; + @BeforeMethod + public void setUp() { + + mockedIdentityUtil = Mockito.mockStatic(IdentityUtil.class); + } + @BeforeTest public void Init() { selfRegistrationConfigImpl = new SelfRegistrationConfigImpl(); } + @AfterMethod + public void tearDown() { + + mockedIdentityUtil.close(); + } + @Test public void testGetName() { @@ -98,9 +118,11 @@ public void testGetPropertyNameMapping() { "Lock user account on creation"); nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SEND_OTP_IN_EMAIL, "Send OTP in e-mail"); - nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_UPPERCASE_CHARACTERS_IN_OTP, + nameMappingExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_UPPERCASE_CHARACTERS_IN_OTP, "Include uppercase characters in OTP"); - nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_LOWERCASE_CHARACTERS_IN_OTP, + nameMappingExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_LOWERCASE_CHARACTERS_IN_OTP, "Include lowercase characters in OTP"); nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_NUMBERS_IN_OTP, "Include numbers in OTP"); @@ -108,12 +130,17 @@ public void testGetPropertyNameMapping() { "OTP length"); nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION, "Enable Account Confirmation On Creation"); + nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY, + "Show username unavailability"); nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE, "Manage notifications sending internally"); - nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA, "Prompt reCaptcha"); - nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_VERIFICATION_CODE_EXPIRY_TIME, + nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA, + "Prompt reCaptcha"); + nameMappingExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_VERIFICATION_CODE_EXPIRY_TIME, "User self registration verification link expiry time"); - nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SMSOTP_VERIFICATION_CODE_EXPIRY_TIME, + nameMappingExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SMSOTP_VERIFICATION_CODE_EXPIRY_TIME, "User self registration SMS OTP expiry time"); nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SMS_OTP_REGEX, "User self registration SMS OTP regex"); @@ -155,6 +182,8 @@ public void testGetPropertyDescriptionMapping() { "Length of the OTP for SMS and e-mail verifications. OTP length must be 4-10."); descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION, "Enable user account confirmation when the user account is not locked on creation"); + descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY, + "Show a descriptive error message to the user if the username is already taken. However, this may lead to username enumeration"); descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE, "Disable if the client application handles notification sending"); descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA, @@ -179,7 +208,8 @@ public void testGetPropertyDescriptionMapping() { "Prompt reCaptcha verification for resend confirmation"); descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_AUTO_LOGIN, "User will be logged in automatically after completing the Account Confirmation "); - descriptionMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_AUTO_LOGIN_ALIAS_NAME, + descriptionMappingExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_AUTO_LOGIN_ALIAS_NAME, "Alias of the key used to sign to cookie. The public key has to be imported to the keystore. "); Map descriptionMapping = selfRegistrationConfigImpl.getPropertyDescriptionMapping(); @@ -193,11 +223,14 @@ public void testGetPropertyNames() { propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.ENABLE_SELF_SIGNUP); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.ACCOUNT_LOCK_ON_CREATION); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SEND_OTP_IN_EMAIL); - propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_UPPERCASE_CHARACTERS_IN_OTP); - propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_LOWERCASE_CHARACTERS_IN_OTP); + propertiesExpected.add( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_UPPERCASE_CHARACTERS_IN_OTP); + propertiesExpected.add( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_LOWERCASE_CHARACTERS_IN_OTP); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_NUMBERS_IN_OTP); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_OTP_LENGTH); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION); + propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA); propertiesExpected @@ -231,6 +264,7 @@ public void testGetDefaultPropertyValues() throws IdentityGovernanceException { String testUseNumbersInOTP = StringUtils.EMPTY; String testOtpLength = "6"; String testEnableSendNotificationOnCreation = "false"; + String testShowUsernameUnavailability = "true"; String testEnableNotificationInternallyManage = "true"; String testEnableSelfRegistrationReCaptcha = "true"; String testVerificationCodeExpiryTime = "1440"; @@ -242,15 +276,75 @@ public void testGetDefaultPropertyValues() throws IdentityGovernanceException { String enableSelfRegistrationAutoLogin = "false"; String enableSelfRegistrationAutoLoginAlias = "wso2carbon"; + mockedIdentityUtil.when( + () -> IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.ENABLE_SELF_SIGNUP)) + .thenReturn(testEnableSelfSignUp); + mockedIdentityUtil.when( + () -> IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.ACCOUNT_LOCK_ON_CREATION)) + .thenReturn(testEnableAccountLockOnCreation); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SEND_OTP_IN_EMAIL)) + .thenReturn(testEnableSendOTPInEmail); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_UPPERCASE_CHARACTERS_IN_OTP)) + .thenReturn(testUseUppercaseCharactersInOTP); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_LOWERCASE_CHARACTERS_IN_OTP)) + .thenReturn(testUseLowercaseCharactersInOTP); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_NUMBERS_IN_OTP)) + .thenReturn(testUseNumbersInOTP); + mockedIdentityUtil.when( + () -> IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_OTP_LENGTH)) + .thenReturn(testOtpLength); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION)) + .thenReturn(testEnableSendNotificationOnCreation); + mockedIdentityUtil.when( + () -> IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY)) + .thenReturn(testShowUsernameUnavailability); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE)) + .thenReturn(testEnableNotificationInternallyManage); + mockedIdentityUtil.when( + () -> IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA)) + .thenReturn(testEnableSelfRegistrationReCaptcha); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_VERIFICATION_CODE_EXPIRY_TIME)) + .thenReturn(testVerificationCodeExpiryTime); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SMSOTP_VERIFICATION_CODE_EXPIRY_TIME)) + .thenReturn(testVerificationSMSOTPExpiryTime); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SMS_OTP_REGEX)) + .thenReturn(testVerificationSMSOTPRegex); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_CALLBACK_REGEX)) + .thenReturn(selfRegistrationCallbackRegex); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_NOTIFY_ACCOUNT_CONFIRMATION)) + .thenReturn(enableSelfSignUpConfirmationNotification); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.RESEND_CONFIRMATION_RECAPTCHA_ENABLE)) + .thenReturn(enableResendConfirmationRecaptcha); + mockedIdentityUtil.when( + () -> IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_AUTO_LOGIN)) + .thenReturn(enableSelfRegistrationAutoLogin); + mockedIdentityUtil.when(() -> IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_AUTO_LOGIN_ALIAS_NAME)) + .thenReturn(enableSelfRegistrationAutoLoginAlias); + Map propertiesExpected = new HashMap<>(); propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_SELF_SIGNUP, testEnableSelfSignUp); propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.ACCOUNT_LOCK_ON_CREATION, testEnableAccountLockOnCreation); propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SEND_OTP_IN_EMAIL, testEnableSendOTPInEmail); - propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_UPPERCASE_CHARACTERS_IN_OTP, + propertiesExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_UPPERCASE_CHARACTERS_IN_OTP, testUseUppercaseCharactersInOTP); - propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_LOWERCASE_CHARACTERS_IN_OTP, + propertiesExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_LOWERCASE_CHARACTERS_IN_OTP, testUseLowercaseCharactersInOTP); propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_NUMBERS_IN_OTP, testUseNumbersInOTP); @@ -258,6 +352,8 @@ public void testGetDefaultPropertyValues() throws IdentityGovernanceException { testOtpLength); propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION, testEnableSendNotificationOnCreation); + propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY, + testShowUsernameUnavailability); propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE, testEnableNotificationInternallyManage); propertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA, @@ -305,4 +401,75 @@ public void testGetDefaultProperties() throws IdentityGovernanceException { tenantDomain); assertNull(defaultPropertyValues); } + + @Test + public void testGetMetadata() { + + Map metaDataExpected = new HashMap<>(); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_SELF_SIGNUP, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.ACCOUNT_LOCK_ON_CREATION, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SEND_OTP_IN_EMAIL, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_UPPERCASE_CHARACTERS_IN_OTP, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_LOWERCASE_CHARACTERS_IN_OTP, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_USE_NUMBERS_IN_OTP, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_OTP_LENGTH, + getPropertyObject(IdentityMgtConstants.DataTypes.STRING.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SEND_CONFIRMATION_NOTIFICATION, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SHOW_USERNAME_UNAVAILABILITY, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SIGN_UP_NOTIFICATION_INTERNALLY_MANAGE, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_RE_CAPTCHA, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_VERIFICATION_CODE_EXPIRY_TIME, + getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue())); + + metaDataExpected.put( + IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SMSOTP_VERIFICATION_CODE_EXPIRY_TIME, + getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_SMS_OTP_REGEX, + getPropertyObject(IdentityMgtConstants.DataTypes.STRING.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_AUTO_LOGIN, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_AUTO_LOGIN_ALIAS_NAME, + getPropertyObject(IdentityMgtConstants.DataTypes.STRING.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_NOTIFY_ACCOUNT_CONFIRMATION, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RESEND_CONFIRMATION_RECAPTCHA_ENABLE, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + metaDataExpected.put(LIST_PURPOSE_PROPERTY_KEY, + getPropertyObject(IdentityMgtConstants.DataTypes.URI.getValue())); + + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_CALLBACK_REGEX, + getPropertyObject(IdentityMgtConstants.DataTypes.STRING.getValue())); + + Map metaData = selfRegistrationConfigImpl.getMetaData(); + assertEquals(metaData, metaDataExpected, "Maps are not equal"); + } }