From f7220bda13643bf5fb23a3beacc4791bf96b0812 Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Fri, 18 Oct 2024 14:01:51 +0530 Subject: [PATCH 1/4] Add configs. --- .../recovery/IdentityRecoveryConstants.java | 2 ++ .../connector/RecoveryConfigImpl.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) 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 1b4faf3df7..04ee63b86d 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 @@ -579,6 +579,8 @@ public static class ConnectorConfig { public static final String FORCE_ADD_PW_RECOVERY_QUESTION = "Recovery.Question.Password.Forced.Enable"; public static final String FORCE_MIN_NO_QUESTION_ANSWERED = "Recovery.Question.MinQuestionsToAnswer"; public static final String USERNAME_RECOVERY_ENABLE = "Recovery.Notification.Username.Enable"; + public static final String USERNAME_RECOVERY_EMAIL_ENABLE = "Recovery.Notification.Username.Email.Enable"; + public static final String USERNAME_RECOVERY_SMS_ENABLE = "Recovery.Notification.Username.SMS.Enable"; public static final String QUESTION_CHALLENGE_SEPARATOR = "Recovery.Question.Password.Separator"; public static final String QUESTION_MIN_NO_ANSWER = "Recovery.Question.Password.MinAnswers"; public static final String EXPIRY_TIME = "Recovery.ExpiryTime"; diff --git a/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImpl.java b/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImpl.java index 74ef59ffb6..218e43aa0f 100644 --- a/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImpl.java +++ b/components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImpl.java @@ -99,6 +99,10 @@ public Map getPropertyNameMapping() { nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.QUESTION_MIN_NO_ANSWER, "Number of questions " + "required for password recovery"); nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE, "Username recovery"); + nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE, + "Notification based username recovery via EMAIL"); + nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE, + "Notification based username recovery via SMS"); nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE, "Enable reCaptcha for username recovery"); nameMapping.put(IdentityRecoveryConstants.ConnectorConfig.EXPIRY_TIME, "Recovery link expiry time in minutes"); @@ -193,6 +197,8 @@ public String[] getPropertyNames() { properties.add(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_ENABLE); properties.add(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_MAX_FAILED_ATTEMPTS); properties.add(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE); + properties.add(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE); + properties.add(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE); properties.add(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE); properties.add(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_INTERNALLY_MANAGE); properties.add(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_SEND_RECOVERY_NOTIFICATION_SUCCESS); @@ -227,6 +233,8 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG String enableRecoveryQuestionPasswordReCaptcha = "true"; String recoveryQuestionPasswordReCaptchaMaxFailedAttempts = "2"; String enableUsernameRecovery = "false"; + String enableUsernameRecoveryEmail = "false"; + String enableUsernameRecoverySMS = "false"; String enableNotificationInternallyManage = "true"; String expiryTime = "1440"; String expiryTimeSMSOTP = "1"; @@ -272,6 +280,10 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_MAX_FAILED_ATTEMPTS); String usernameRecovery = IdentityUtil.getProperty( IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE); + String usernameRecoveryEmail = IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE); + String usernameRecoverySMS = IdentityUtil.getProperty( + IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE); String notificationInternallyManged = IdentityUtil.getProperty( IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_INTERNALLY_MANAGE); String expiryTimeProperty = IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.EXPIRY_TIME); @@ -351,6 +363,14 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG } if (StringUtils.isNotEmpty(usernameRecovery)) { enableUsernameRecovery = usernameRecovery; + // Setting the username recovery value to keep backward compatibility. + enableUsernameRecoveryEmail = usernameRecovery; + } + if (StringUtils.isNotEmpty(usernameRecoveryEmail)){ + enableUsernameRecoveryEmail = usernameRecoveryEmail; + } + if (StringUtils.isNotEmpty(usernameRecoverySMS)) { + enableUsernameRecoverySMS = usernameRecoverySMS; } if (StringUtils.isNotEmpty(expiryTimeProperty)) { expiryTime = expiryTimeProperty; @@ -433,6 +453,10 @@ public Properties getDefaultPropertyValues(String tenantDomain) throws IdentityG recoveryQuestionPasswordReCaptchaMaxFailedAttempts); defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE, enableUsernameRecovery); + defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE, + enableUsernameRecoveryEmail); + defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE, + enableUsernameRecoverySMS); defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE, enableUsernameRecoveryReCaptcha); defaultProperties.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_INTERNALLY_MANAGE, @@ -518,6 +542,12 @@ public Map getMetaData() { meta.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE, getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + meta.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + + meta.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE, + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); + meta.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE, getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue())); From 4eac02982b6dd9353dfd0e38eb570ce2cd07891a Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Mon, 21 Oct 2024 07:35:19 +0530 Subject: [PATCH 2/4] Add tests for the configs. --- .../recovery/connector/RecoveryConfigImplTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java index beaf4d247a..5f63547db2 100644 --- a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java +++ b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java @@ -105,6 +105,10 @@ public void testGetPropertyNameMapping() { nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.QUESTION_MIN_NO_ANSWER, "Number of " + "questions required for password recovery"); nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE, "Username recovery"); + nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE, + "Notification based username recovery via EMAIL"); + nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE, + "Notification based username recovery via SMS"); nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE, "Enable reCaptcha for username recovery"); nameMappingExpected.put(IdentityRecoveryConstants.ConnectorConfig.EXPIRY_TIME, @@ -206,6 +210,8 @@ public void testGetPropertyNames() { propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_ENABLE); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_MAX_FAILED_ATTEMPTS); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE); + propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE); + propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_INTERNALLY_MANAGE); propertiesExpected.add(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_SEND_RECOVERY_NOTIFICATION_SUCCESS); @@ -241,6 +247,8 @@ public void testGetDefaultPropertyValues() throws IdentityGovernanceException { String testEnableRecoveryQuestionPasswordReCaptcha = "true"; String testRecoveryQuestionPasswordReCaptchaMaxFailedAttempts = "2"; String testEnableUsernameRecovery = "false"; + String testEnableUsernameRecoveryEmail = "false"; + String testEnableUsernameRecoverySMS = "false"; String testEnableNotificationInternallyManage = "true"; String testExpiryTime = "1440"; String testExpiryTimeSMSOTP = "1"; @@ -286,6 +294,10 @@ public void testGetDefaultPropertyValues() throws IdentityGovernanceException { testRecoveryQuestionPasswordReCaptchaMaxFailedAttempts); defaultPropertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE, testEnableUsernameRecovery); + defaultPropertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE, + testEnableUsernameRecoveryEmail); + defaultPropertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE, + testEnableUsernameRecoverySMS); defaultPropertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE, enableUsernameRecoveryReCaptcha); defaultPropertiesExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_INTERNALLY_MANAGE, From 73454b544b8d043daac7f05e480180190326686a Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Mon, 21 Oct 2024 13:38:26 +0530 Subject: [PATCH 3/4] Add tests for the metadata function. --- .../connector/RecoveryConfigImplTest.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java index 5f63547db2..159dd129f6 100644 --- a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java +++ b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java @@ -17,9 +17,11 @@ */ package org.wso2.carbon.identity.recovery.connector; +import com.hazelcast.org.apache.calcite.runtime.Resources; import org.apache.commons.lang.StringUtils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import org.wso2.carbon.identity.application.common.model.Property; import org.wso2.carbon.identity.governance.IdentityGovernanceException; import org.wso2.carbon.identity.governance.IdentityMgtConstants; import org.wso2.carbon.identity.recovery.IdentityRecoveryConstants; @@ -32,6 +34,7 @@ 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 RecoveryConfigImpl class. @@ -339,6 +342,114 @@ public void testGetDefaultPropertyValues() throws IdentityGovernanceException { assertEquals(defaultProperties, defaultPropertiesExpected, "Maps are not equal"); } + @Test + public void testGetMetaData() { + Map metaDataExpected = new HashMap<>(); + + Property testNotificationBasedPasswordRecovery = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testPasswordRecoverySendOtpInEmail = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testPasswordRecoveryUseUppercaseCharactersInOtp = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testPasswordRecoveryUseLowercaseCharactersInOtp = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testPasswordRecoveryUseNumbersInOtp = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testPasswordRecoveryOtpLength = + getPropertyObject(IdentityMgtConstants.DataTypes.STRING.getValue()); + Property testPasswordRecoveryRecaptchaEnable = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testQuestionBasedPwRecovery = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testQuestionMinNoAnswer = + getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue()); + Property testEnforceChallengeQuestionAnswerUniqueness = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testRecoveryQuestionPasswordRecaptchaEnable = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testRecoveryQuestionPasswordRecaptchaMaxFailedAttempts = + getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue()); + Property testUsernameRecoveryEnable = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testUsernameRecoveryEmailEnable = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testUsernameRecoverySmsEnable = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testUsernameRecoveryRecaptchaEnable = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testNotificationInternallyManage = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testExpiryTime = + getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue()); + Property testPasswordRecoverySmsOtpExpiryTime = + getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue()); + Property testNotificationSendRecoveryNotificationSuccess = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testNotificationSendRecoverySecurityStart = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testForceAddPwRecoveryQuestion = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testForceMinNoQuestionAnswered = + getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue()); + Property testEnableAutoLoginAfterPasswordReset = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testChallengeQuestionAnswerRegex = + getPropertyObject(IdentityMgtConstants.DataTypes.STRING.getValue()); + Property testRecoveryCallbackRegex = + getPropertyObject(IdentityMgtConstants.DataTypes.STRING.getValue()); + Property testRecoveryNotificationPasswordMaxFailedAttempts = + getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue()); + Property testRecoveryNotificationPasswordMaxResendAttempts = + getPropertyObject(IdentityMgtConstants.DataTypes.INTEGER.getValue()); + Property testPasswordRecoveryEmailLinkEnable = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testPasswordRecoverySmsOtpEnable = + getPropertyObject(IdentityMgtConstants.DataTypes.BOOLEAN.getValue()); + Property testPasswordRecoverySmsOtpRegex = + getPropertyObject(IdentityMgtConstants.DataTypes.STRING.getValue()); + + // Adding properties to the expected metadata map. + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_BASED_PW_RECOVERY, testNotificationBasedPasswordRecovery); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SEND_OTP_IN_EMAIL, testPasswordRecoverySendOtpInEmail); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_USE_UPPERCASE_CHARACTERS_IN_OTP, testPasswordRecoveryUseUppercaseCharactersInOtp); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_USE_LOWERCASE_CHARACTERS_IN_OTP, testPasswordRecoveryUseLowercaseCharactersInOtp); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_USE_NUMBERS_IN_OTP, testPasswordRecoveryUseNumbersInOtp); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_OTP_LENGTH, testPasswordRecoveryOtpLength); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_RECAPTCHA_ENABLE, testPasswordRecoveryRecaptchaEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.QUESTION_BASED_PW_RECOVERY, testQuestionBasedPwRecovery); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.QUESTION_MIN_NO_ANSWER, testQuestionMinNoAnswer); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENFORCE_CHALLENGE_QUESTION_ANSWER_UNIQUENESS, testEnforceChallengeQuestionAnswerUniqueness); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_ENABLE, testRecoveryQuestionPasswordRecaptchaEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_MAX_FAILED_ATTEMPTS, testRecoveryQuestionPasswordRecaptchaMaxFailedAttempts); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE, testUsernameRecoveryEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE, testUsernameRecoveryEmailEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE, testUsernameRecoverySmsEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE, testUsernameRecoveryRecaptchaEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_INTERNALLY_MANAGE, testNotificationInternallyManage); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.EXPIRY_TIME, testExpiryTime); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SMS_OTP_EXPIRY_TIME, testPasswordRecoverySmsOtpExpiryTime); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_SEND_RECOVERY_NOTIFICATION_SUCCESS, testNotificationSendRecoveryNotificationSuccess); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_SEND_RECOVERY_SECURITY_START, testNotificationSendRecoverySecurityStart); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.FORCE_ADD_PW_RECOVERY_QUESTION, testForceAddPwRecoveryQuestion); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.FORCE_MIN_NO_QUESTION_ANSWERED, testForceMinNoQuestionAnswered); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_AUTO_LGOIN_AFTER_PASSWORD_RESET, testEnableAutoLoginAfterPasswordReset); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.CHALLENGE_QUESTION_ANSWER_REGEX, testChallengeQuestionAnswerRegex); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_CALLBACK_REGEX, testRecoveryCallbackRegex); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_NOTIFICATION_PASSWORD_MAX_FAILED_ATTEMPTS, testRecoveryNotificationPasswordMaxFailedAttempts); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_NOTIFICATION_PASSWORD_MAX_RESEND_ATTEMPTS, testRecoveryNotificationPasswordMaxResendAttempts); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_EMAIL_LINK_ENABLE, testPasswordRecoveryEmailLinkEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SMS_OTP_ENABLE, testPasswordRecoverySmsOtpEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SMS_OTP_REGEX, testPasswordRecoverySmsOtpRegex); + + // Fetching actual metadata from the method. + Map metaData = recoveryConfigImpl.getMetaData(); + + // Asserting that the expected and actual maps are equal. + assertEquals(metaData, metaDataExpected); + } + + @Test public void testGetDefaultProperties() throws IdentityGovernanceException { From fd94896fd331b3cc5925c696cf9b0fd54708cada Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Mon, 21 Oct 2024 13:41:30 +0530 Subject: [PATCH 4/4] Reformat the code. --- .../connector/RecoveryConfigImplTest.java | 92 +++++++++++++------ 1 file changed, 63 insertions(+), 29 deletions(-) diff --git a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java index 159dd129f6..0adf11c12c 100644 --- a/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java +++ b/components/org.wso2.carbon.identity.recovery/src/test/java/org/wso2/carbon/identity/recovery/connector/RecoveryConfigImplTest.java @@ -410,37 +410,71 @@ public void testGetMetaData() { getPropertyObject(IdentityMgtConstants.DataTypes.STRING.getValue()); // Adding properties to the expected metadata map. - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_BASED_PW_RECOVERY, testNotificationBasedPasswordRecovery); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SEND_OTP_IN_EMAIL, testPasswordRecoverySendOtpInEmail); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_USE_UPPERCASE_CHARACTERS_IN_OTP, testPasswordRecoveryUseUppercaseCharactersInOtp); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_USE_LOWERCASE_CHARACTERS_IN_OTP, testPasswordRecoveryUseLowercaseCharactersInOtp); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_USE_NUMBERS_IN_OTP, testPasswordRecoveryUseNumbersInOtp); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_OTP_LENGTH, testPasswordRecoveryOtpLength); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_RECAPTCHA_ENABLE, testPasswordRecoveryRecaptchaEnable); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.QUESTION_BASED_PW_RECOVERY, testQuestionBasedPwRecovery); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_BASED_PW_RECOVERY, + testNotificationBasedPasswordRecovery); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SEND_OTP_IN_EMAIL, + testPasswordRecoverySendOtpInEmail); + metaDataExpected.put( + IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_USE_UPPERCASE_CHARACTERS_IN_OTP, + testPasswordRecoveryUseUppercaseCharactersInOtp); + metaDataExpected.put( + IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_USE_LOWERCASE_CHARACTERS_IN_OTP, + testPasswordRecoveryUseLowercaseCharactersInOtp); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_USE_NUMBERS_IN_OTP, + testPasswordRecoveryUseNumbersInOtp); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_OTP_LENGTH, + testPasswordRecoveryOtpLength); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_RECAPTCHA_ENABLE, + testPasswordRecoveryRecaptchaEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.QUESTION_BASED_PW_RECOVERY, + testQuestionBasedPwRecovery); metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.QUESTION_MIN_NO_ANSWER, testQuestionMinNoAnswer); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENFORCE_CHALLENGE_QUESTION_ANSWER_UNIQUENESS, testEnforceChallengeQuestionAnswerUniqueness); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_ENABLE, testRecoveryQuestionPasswordRecaptchaEnable); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_MAX_FAILED_ATTEMPTS, testRecoveryQuestionPasswordRecaptchaMaxFailedAttempts); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE, testUsernameRecoveryEnable); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE, testUsernameRecoveryEmailEnable); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE, testUsernameRecoverySmsEnable); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE, testUsernameRecoveryRecaptchaEnable); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_INTERNALLY_MANAGE, testNotificationInternallyManage); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENFORCE_CHALLENGE_QUESTION_ANSWER_UNIQUENESS, + testEnforceChallengeQuestionAnswerUniqueness); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_ENABLE, + testRecoveryQuestionPasswordRecaptchaEnable); + metaDataExpected.put( + IdentityRecoveryConstants.ConnectorConfig.RECOVERY_QUESTION_PASSWORD_RECAPTCHA_MAX_FAILED_ATTEMPTS, + testRecoveryQuestionPasswordRecaptchaMaxFailedAttempts); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_ENABLE, + testUsernameRecoveryEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_EMAIL_ENABLE, + testUsernameRecoveryEmailEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_SMS_ENABLE, + testUsernameRecoverySmsEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.USERNAME_RECOVERY_RECAPTCHA_ENABLE, + testUsernameRecoveryRecaptchaEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_INTERNALLY_MANAGE, + testNotificationInternallyManage); metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.EXPIRY_TIME, testExpiryTime); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SMS_OTP_EXPIRY_TIME, testPasswordRecoverySmsOtpExpiryTime); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_SEND_RECOVERY_NOTIFICATION_SUCCESS, testNotificationSendRecoveryNotificationSuccess); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_SEND_RECOVERY_SECURITY_START, testNotificationSendRecoverySecurityStart); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.FORCE_ADD_PW_RECOVERY_QUESTION, testForceAddPwRecoveryQuestion); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.FORCE_MIN_NO_QUESTION_ANSWERED, testForceMinNoQuestionAnswered); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_AUTO_LGOIN_AFTER_PASSWORD_RESET, testEnableAutoLoginAfterPasswordReset); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.CHALLENGE_QUESTION_ANSWER_REGEX, testChallengeQuestionAnswerRegex); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_CALLBACK_REGEX, testRecoveryCallbackRegex); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_NOTIFICATION_PASSWORD_MAX_FAILED_ATTEMPTS, testRecoveryNotificationPasswordMaxFailedAttempts); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_NOTIFICATION_PASSWORD_MAX_RESEND_ATTEMPTS, testRecoveryNotificationPasswordMaxResendAttempts); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_EMAIL_LINK_ENABLE, testPasswordRecoveryEmailLinkEnable); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SMS_OTP_ENABLE, testPasswordRecoverySmsOtpEnable); - metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SMS_OTP_REGEX, testPasswordRecoverySmsOtpRegex); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SMS_OTP_EXPIRY_TIME, + testPasswordRecoverySmsOtpExpiryTime); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_SEND_RECOVERY_NOTIFICATION_SUCCESS, + testNotificationSendRecoveryNotificationSuccess); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.NOTIFICATION_SEND_RECOVERY_SECURITY_START, + testNotificationSendRecoverySecurityStart); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.FORCE_ADD_PW_RECOVERY_QUESTION, + testForceAddPwRecoveryQuestion); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.FORCE_MIN_NO_QUESTION_ANSWERED, + testForceMinNoQuestionAnswered); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.ENABLE_AUTO_LGOIN_AFTER_PASSWORD_RESET, + testEnableAutoLoginAfterPasswordReset); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.CHALLENGE_QUESTION_ANSWER_REGEX, + testChallengeQuestionAnswerRegex); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.RECOVERY_CALLBACK_REGEX, + testRecoveryCallbackRegex); + metaDataExpected.put( + IdentityRecoveryConstants.ConnectorConfig.RECOVERY_NOTIFICATION_PASSWORD_MAX_FAILED_ATTEMPTS, + testRecoveryNotificationPasswordMaxFailedAttempts); + metaDataExpected.put( + IdentityRecoveryConstants.ConnectorConfig.RECOVERY_NOTIFICATION_PASSWORD_MAX_RESEND_ATTEMPTS, + testRecoveryNotificationPasswordMaxResendAttempts); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_EMAIL_LINK_ENABLE, + testPasswordRecoveryEmailLinkEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SMS_OTP_ENABLE, + testPasswordRecoverySmsOtpEnable); + metaDataExpected.put(IdentityRecoveryConstants.ConnectorConfig.PASSWORD_RECOVERY_SMS_OTP_REGEX, + testPasswordRecoverySmsOtpRegex); // Fetching actual metadata from the method. Map metaData = recoveryConfigImpl.getMetaData();