Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude multiple emails and mobiles related claims from ReadWriteLDAPUserStoreManagerTestCase #21921

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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