Skip to content

Commit

Permalink
Merge pull request #20557 from RushanNanayakkara/master
Browse files Browse the repository at this point in the history
Integration tests for SMS OTP for Password Recovery Feature
  • Loading branch information
sadilchamishka authored Jun 27, 2024
2 parents 037a14a + 4eb517e commit 887d8d9
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Map;

import static org.wso2.identity.integration.test.utils.CommonConstants.DEFAULT_TOMCAT_PORT;

Expand All @@ -52,6 +53,10 @@ public class ChallengeQuestionsUITestCase extends OAuth2ServiceAbstractIntegrati
private static final String ENABLE_PASSWORD_QS_RECOVERY_PROP_KEY = "Recovery.Question.Password.Enable";
private static final String ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY =
"Recovery.Notification.Password.Enable";
private static final String ENABLE_PASSWORD_EMAIL_LINK_RECOVERY_PROP_KEY =
"Recovery.Notification.Password.emailLink.Enable";
private static final String ENABLE_PASSWORD_SMS_OTP_RECOVERY_PROP_KEY =
"Recovery.Notification.Password.smsOtp.Enable";
private static final String OIDC_APP_NAME = "playground2";
private IdentityProvider superTenantResidentIDP;
private ServerConfigurationManager serverConfigurationManager;
Expand Down Expand Up @@ -112,8 +117,12 @@ private void createOIDCApplication() throws Exception {
@Test(groups = "wso2.is", description = "Check Password recovery option recovery Page")
public void testRecovery() throws Exception {

updateResidentIDPProperty(superTenantResidentIDP, ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "true");
updateResidentIDPProperty(superTenantResidentIDP, ENABLE_PASSWORD_QS_RECOVERY_PROP_KEY, "true");
updateResidentIDPProperties(superTenantResidentIDP, Map.of(
ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "true",
ENABLE_PASSWORD_EMAIL_LINK_RECOVERY_PROP_KEY, "true",
ENABLE_PASSWORD_SMS_OTP_RECOVERY_PROP_KEY, "true",
ENABLE_PASSWORD_QS_RECOVERY_PROP_KEY, "true"
));
String content = sendRecoveryRequest();
Assert.assertTrue(content.contains(RECOVERY_ENDPOINT_QS_CONTENT));
Assert.assertTrue(content.contains(RECOVERY_ENDPOINT_NOTIFICATION_CONTENT));
Expand All @@ -130,6 +139,18 @@ private void updateResidentIDPProperty(IdentityProvider residentIdp, String prop
updateResidentIDP(residentIdp);
}

private void updateResidentIDPProperties(IdentityProvider residentIdp, Map<String,String> properties)
throws Exception {

IdentityProviderProperty[] idpProperties = residentIdp.getIdpProperties();
for (IdentityProviderProperty providerProperty : idpProperties) {
if (properties.containsKey(providerProperty.getName())) {
providerProperty.setValue(properties.get(providerProperty.getName()));
}
}
updateResidentIDP(residentIdp);
}

private void updateResidentIDP(IdentityProvider residentIdentityProvider) throws Exception {

FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.wso2.identity.integration.test.utils.OAuth2Constant;

import java.io.IOException;
import java.util.Map;

import static org.wso2.identity.integration.test.utils.CommonConstants.DEFAULT_TOMCAT_PORT;

Expand All @@ -55,11 +56,16 @@ public class PreferenceAPIIntegrationUITestCase extends OAuth2ServiceAbstractInt
private static final String ENABLE_PASSWORD_QS_RECOVERY_PROP_KEY = "Recovery.Question.Password.Enable";
private static final String ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY =
"Recovery.Notification.Password.Enable";
private static final String ENABLE_PASSWORD_EMAIL_LINK_RECOVERY_PROP_KEY =
"Recovery.Notification.Password.emailLink.Enable";
private static final String ENABLE_PASSWORD_SMS_OTP_RECOVERY_PROP_KEY =
"Recovery.Notification.Password.smsOtp.Enable";
private static final String CALLBACK_URL = "https://localhost/callback";
private static final String RECOVERY_USERNAME_CONTENT = "id=\"usernameRecoverLink\"";
private static final String RECOVERY_PASSWORD_CONTENT = "id=\"passwordRecoverLink\"";
private static final String RECOVERY_ENDPOINT_QS_CONTENT = "name=\"recoveryOption\" value=\"SECURITY_QUESTIONS\"";
private static final String RECOVERY_ENDPOINT_NOTIFICATION_CONTENT = "name=\"recoveryOption\" value=\"EMAIL\"";
private static final String RECOVERY_ENDPOINT_NOTIFICATION_EMAIL_LINK_CONTENT = "name=\"recoveryOption\" value=\"EMAIL\"";
private static final String RECOVERY_ENDPOINT_NOTIFICATION_SMS_OTP_CONTENT = "name=\"recoveryOption\" value=\"SMSOTP\"";
private static final String CREATE_ACCOUNT_CONTENT = "id=\"registerLink\"";
private static final String RECOVERY_ENDPOINT_URL = "/accountrecoveryendpoint/recoveraccountrouter.do";

Expand Down Expand Up @@ -120,11 +126,13 @@ public void atEnd() throws Exception {
@AfterMethod
public void resetResidentIDP() throws Exception {

updateResidentIDPProperty(superTenantResidentIDP, ENABLE_SELF_REGISTRATION_PROP_KEY, "false");
updateResidentIDPProperty(superTenantResidentIDP, ENABLE_USERNAME_RECOVERY_PROP_KEY, "false");
updateResidentIDPProperty(superTenantResidentIDP, ENABLE_PASSWORD_QS_RECOVERY_PROP_KEY, "false");
updateResidentIDPProperty(superTenantResidentIDP, ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "false");

updateResidentIDPProperties(superTenantResidentIDP, Map.of(
ENABLE_SELF_REGISTRATION_PROP_KEY, "false",
ENABLE_USERNAME_RECOVERY_PROP_KEY, "false",
ENABLE_PASSWORD_QS_RECOVERY_PROP_KEY, "false",
ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "false",
ENABLE_PASSWORD_EMAIL_LINK_RECOVERY_PROP_KEY, "false",
ENABLE_PASSWORD_SMS_OTP_RECOVERY_PROP_KEY, "false"));
}

@Test(groups = "wso2.is", description = "Check Initial Login Page")
Expand Down Expand Up @@ -161,9 +169,21 @@ public void testQSPasswordRecovery() throws Exception {
}

@Test(groups = "wso2.is", description = "Check Notification Password recovery Login Page")
public void testNotificationPasswordRecovery() throws Exception {
public void testNotificationPasswordEmailLinkRecovery() throws Exception {

updateResidentIDPProperty(superTenantResidentIDP, ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "true");
updateResidentIDPProperties(superTenantResidentIDP, Map.of(
ENABLE_PASSWORD_EMAIL_LINK_RECOVERY_PROP_KEY, "true",
ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "true"));
String content = sendAuthorizeRequest();
Assert.assertTrue(content.contains(RECOVERY_PASSWORD_CONTENT));
}

@Test(groups = "wso2.is", description = "Check Notification Password recovery Login Page")
public void testNotificationPasswordSMSOTPRecovery() throws Exception {

updateResidentIDPProperties(superTenantResidentIDP, Map.of(
ENABLE_PASSWORD_SMS_OTP_RECOVERY_PROP_KEY, "true",
ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "true"));
String content = sendAuthorizeRequest();
Assert.assertTrue(content.contains(RECOVERY_PASSWORD_CONTENT));
}
Expand All @@ -174,16 +194,33 @@ public void testRecoveryQSOnly() throws Exception {
updateResidentIDPProperty(superTenantResidentIDP, ENABLE_PASSWORD_QS_RECOVERY_PROP_KEY, "true");
String content = sendRecoveryRequest();
Assert.assertTrue(content.contains(RECOVERY_ENDPOINT_QS_CONTENT));
Assert.assertFalse(content.contains(RECOVERY_ENDPOINT_NOTIFICATION_CONTENT));
Assert.assertFalse(content.contains(RECOVERY_ENDPOINT_NOTIFICATION_EMAIL_LINK_CONTENT));
Assert.assertFalse(content.contains(RECOVERY_ENDPOINT_NOTIFICATION_SMS_OTP_CONTENT));
}

@Test(groups = "wso2.is", description = "Check Notification recovery option recovery Page")
public void testRecoveryNotificationEmailLinkOnly() throws Exception {

updateResidentIDPProperties(superTenantResidentIDP, Map.of(
ENABLE_PASSWORD_EMAIL_LINK_RECOVERY_PROP_KEY, "true",
ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "true"));
String content = sendRecoveryRequest();
Assert.assertFalse(content.contains(RECOVERY_ENDPOINT_QS_CONTENT));
Assert.assertFalse(content.contains(RECOVERY_ENDPOINT_NOTIFICATION_SMS_OTP_CONTENT));
Assert.assertTrue(content.contains(RECOVERY_ENDPOINT_NOTIFICATION_EMAIL_LINK_CONTENT));
}

@Test(groups = "wso2.is", description = "Check Notification recovery option recovery Page")
public void testRecoveryNotificationOnly() throws Exception {
public void testRecoveryNotificationSMSOTPOnly() throws Exception {


updateResidentIDPProperty(superTenantResidentIDP, ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "true");
updateResidentIDPProperties(superTenantResidentIDP, Map.of(
ENABLE_PASSWORD_SMS_OTP_RECOVERY_PROP_KEY, "true",
ENABLE_PASSWORD_NOTIFICATION_RECOVERY_PROP_KEY, "true"));
String content = sendRecoveryRequest();
Assert.assertFalse(content.contains(RECOVERY_ENDPOINT_QS_CONTENT));
Assert.assertTrue(content.contains(RECOVERY_ENDPOINT_NOTIFICATION_CONTENT));
Assert.assertFalse(content.contains(RECOVERY_ENDPOINT_NOTIFICATION_EMAIL_LINK_CONTENT));
Assert.assertTrue(content.contains(RECOVERY_ENDPOINT_NOTIFICATION_SMS_OTP_CONTENT));
}

private void updateResidentIDPProperty(IdentityProvider residentIdp, String propertyKey, String value) throws Exception {
Expand All @@ -197,6 +234,18 @@ private void updateResidentIDPProperty(IdentityProvider residentIdp, String prop
updateResidentIDP(residentIdp);
}

private void updateResidentIDPProperties(IdentityProvider residentIdp, Map<String,String> properties)
throws Exception {

IdentityProviderProperty[] idpProperties = residentIdp.getIdpProperties();
for (IdentityProviderProperty providerProperty : idpProperties) {
if (properties.containsKey(providerProperty.getName())) {
providerProperty.setValue(properties.get(providerProperty.getName()));
}
}
updateResidentIDP(residentIdp);
}

private void updateResidentIDP(IdentityProvider residentIdentityProvider) throws Exception {

FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs =
Expand Down
Loading

0 comments on commit 887d8d9

Please sign in to comment.