From 46450424cda69b1fd806b17db01ccb373e4b4602 Mon Sep 17 00:00:00 2001 From: Pasindu Yeshan Date: Thu, 5 Dec 2024 01:08:03 +0530 Subject: [PATCH] Exclude multi emails mobiles related claims from LDAP usm test. --- ...ReadWriteLDAPUserStoreManagerTestCase.java | 18 ++++++- .../UserManagementServiceAbstractTest.java | 48 ++++++++++++------- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/user/mgt/ReadWriteLDAPUserStoreManagerTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/user/mgt/ReadWriteLDAPUserStoreManagerTestCase.java index 8f98366ab90..bcadedb470a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/user/mgt/ReadWriteLDAPUserStoreManagerTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/user/mgt/ReadWriteLDAPUserStoreManagerTestCase.java @@ -21,12 +21,20 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager; -import java.io.File; +import java.util.Arrays; +import java.util.Set; +import java.util.HashSet; public class ReadWriteLDAPUserStoreManagerTestCase extends UserManagementServiceAbstractTest { + // These attributes are not supported by the default LDAP schema. + private static final Set UNSUPPORTED_CLAIMS = new HashSet<>(Arrays.asList( + "http://wso2.org/claims/emailAddresses", + "http://wso2.org/claims/verifiedEmailAddresses", + "http://wso2.org/claims/mobileNumbers", + "http://wso2.org/claims/verifiedMobileNumbers")); + @BeforeClass(alwaysRun = true) public void configureServer() throws Exception { super.doInit(); @@ -52,5 +60,11 @@ protected void setUserPassword() { protected void setUserRole() { newUserRole = "ReadWriteLDAPUserRole"; } + + @Override + protected Set getExcludedClaims() { + + return UNSUPPORTED_CLAIMS; + } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/user/mgt/UserManagementServiceAbstractTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/user/mgt/UserManagementServiceAbstractTest.java index fb95862912f..59275740bb3 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/user/mgt/UserManagementServiceAbstractTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/user/mgt/UserManagementServiceAbstractTest.java @@ -36,7 +36,11 @@ import org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient; import org.wso2.identity.integration.common.utils.ISIntegrationTest; +import java.util.Arrays; import java.io.File; +import java.util.Collections; +import java.util.Set; + import javax.activation.DataHandler; import javax.activation.FileDataSource; @@ -80,6 +84,16 @@ public void clean() throws Exception { } } + /** + * Retrieves a set of skipped claim URIs. + * + * @return Set of skipped claim URIs. + */ + protected Set getExcludedClaims() { + + return Collections.emptySet(); + } + @SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE}) @Test(groups = "wso2.is", description = "Get all the role names") public void testGetAllRoleNames() throws Exception { @@ -304,27 +318,25 @@ public void testListUserByClaim() throws Exception { = new UserProfileMgtServiceClient(backendURL, getSessionCookie()); UserProfileDTO profile = userProfileMgtServiceClient.getUserProfile(newUserName, "default"); - UserFieldDTO[] fields = userProfileMgtServiceClient.getProfileFieldsForInternalStore().getFieldValues(); String profileConfigs = profile.getProfileName(); - for (UserFieldDTO field : fields) { - if (field.getDisplayName().equalsIgnoreCase("Last Name")) { - field.setFieldValue(newUserName + "LastName"); - continue; - } - - if (field.getRequired()) { - if (field.getDisplayName().equalsIgnoreCase("Email")) { - field.setFieldValue(newUserName + "@wso2.com"); - } else { - field.setFieldValue(newUserName); + Set excludedClaims = getExcludedClaims(); + + UserFieldDTO[] fields = Arrays.stream( + userProfileMgtServiceClient.getProfileFieldsForInternalStore().getFieldValues()) + .filter(field -> !excludedClaims.contains(field.getClaimUri())) + .map(field -> { + if ("Last Name".equalsIgnoreCase(field.getDisplayName())) { + field.setFieldValue(newUserName + "LastName"); + } else if (field.getRequired()) { + field.setFieldValue("Email".equalsIgnoreCase(field.getDisplayName()) + ? newUserName + "@wso2.com" + : newUserName); + } else if (field.getFieldValue() == null) { + field.setFieldValue(""); } - continue; - } - if (field.getFieldValue() == null) { - field.setFieldValue(""); - } + return field; + }).toArray(UserFieldDTO[]::new); - } //creating a new profile with updated values UserProfileDTO newProfile = new UserProfileDTO(); newProfile.setProfileName(profile.getProfileName());