Skip to content

Commit

Permalink
Merge pull request #21921 from PasinduYeshan/test-multi-emails
Browse files Browse the repository at this point in the history
Exclude multiple emails and mobiles related claims from ReadWriteLDAPUserStoreManagerTestCase
  • Loading branch information
PasinduYeshan authored Dec 5, 2024
2 parents 7f03707 + 4645042 commit 5c0aba7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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();
Expand All @@ -52,5 +60,11 @@ protected void setUserPassword() {
protected void setUserRole() {
newUserRole = "ReadWriteLDAPUserRole";
}

@Override
protected Set<String> getExcludedClaims() {

return UNSUPPORTED_CLAIMS;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -80,6 +84,16 @@ public void clean() throws Exception {
}
}

/**
* Retrieves a set of skipped claim URIs.
*
* @return Set of skipped claim URIs.
*/
protected Set<String> getExcludedClaims() {

return Collections.emptySet();
}

@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.is", description = "Get all the role names")
public void testGetAllRoleNames() throws Exception {
Expand Down Expand Up @@ -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<String> 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());
Expand Down

0 comments on commit 5c0aba7

Please sign in to comment.