Skip to content

Add integration test for efficient filtering multi valued attributes #23619

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

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 @@ -40,6 +40,7 @@ public class LocalClaimRes {
private String regEx = null;
private Boolean required = null;
private Boolean supportedByDefault = null;
private Boolean multiValued = null;

public enum UniquenessScopeEnum {
NONE, WITHIN_USERSTORE, ACROSS_USERSTORES,
Expand Down Expand Up @@ -209,6 +210,19 @@ public void setSupportedByDefault(Boolean supportedByDefault) {
this.supportedByDefault = supportedByDefault;
}

/**
* Specifies if the claim can hold multiple values.
**/
@ApiModelProperty(value = "Specifies if the claim can hold multiple values.")
@JsonProperty("multiValued")
public Boolean getMultiValued() {
return multiValued;
}

public void setMultiValued(Boolean multiValued) {
this.multiValued = multiValued;
}

/**
* Specifies the scope of uniqueness validation for the claim value.
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SCIM2BaseTestCase extends ISIntegrationTest {
public static final String GIVEN_NAME_ATTRIBUTE = "givenName";
public static final String EMAIL_TYPE_WORK_ATTRIBUTE = "work";
public static final String EMAIL_TYPE_HOME_ATTRIBUTE = "home";
public static final String EMAIL_ADDRESSES_ATTRIBUTE = "emailAddresses";
public static final String ID_ATTRIBUTE = "id";
public static final String PASSWORD_ATTRIBUTE = "password";
public static final String EMAILS_ATTRIBUTE = "emails";
Expand All @@ -59,6 +60,7 @@ public class SCIM2BaseTestCase extends ISIntegrationTest {
public static final String LIST_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:ListResponse";
public static final String RESOURCE_TYPE_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:ResourceType";
public static final String ERROR_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:Error";
public static final String USER_SYSTEM_SCHEMA = "urn:scim:wso2:schema";

private ServerConfigurationManager serverConfigurationManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
Expand All @@ -41,7 +40,6 @@
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.integration.common.utils.LoginLogoutClient;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import org.wso2.identity.integration.common.clients.claim.metadata.mgt.ClaimMetadataManagementServiceClient;
import org.wso2.identity.integration.common.utils.ISIntegrationTest;
Expand All @@ -51,7 +49,9 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.EMAILS_ATTRIBUTE;
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.EMAIL_ADDRESSES_ATTRIBUTE;
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.EMAIL_TYPE_HOME_ATTRIBUTE;
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.EMAIL_TYPE_WORK_ATTRIBUTE;
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.ERROR_SCHEMA;
Expand All @@ -69,6 +69,7 @@
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.SERVER_URL;
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.TYPE_PARAM;
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.USER_NAME_ATTRIBUTE;
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.USER_SYSTEM_SCHEMA;
import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.VALUE_PARAM;

public class SCIM2UserTestCase extends ISIntegrationTest {
Expand Down Expand Up @@ -160,6 +161,13 @@ public void testCreateUser() throws Exception {

rootObject.put(PASSWORD_ATTRIBUTE, PASSWORD);

JSONArray emailAddresses = new JSONArray();
emailAddresses.add(EMAIL_TYPE_WORK_CLAIM_VALUE);
emailAddresses.add(EMAIL_TYPE_HOME_CLAIM_VALUE);
JSONObject emailAddressesObject = new JSONObject();
emailAddressesObject.put(EMAIL_ADDRESSES_ATTRIBUTE, emailAddresses);
rootObject.put(USER_SYSTEM_SCHEMA, emailAddressesObject);

StringEntity entity = new StringEntity(rootObject.toString());
request.setEntity(entity);

Expand Down Expand Up @@ -301,6 +309,7 @@ public void testFilterUser() throws Exception {
validateFilteredUser(USER_NAME_ATTRIBUTE, CONTAINS, USERNAME.substring(2, 4));
validateFilteredUser(USER_NAME_ATTRIBUTE, STARTWITH, USERNAME.substring(0, 3));
validateFilteredUser(USER_NAME_ATTRIBUTE, ENDWITH, USERNAME.substring(4, USERNAME.length()));
validateFilteredUserByEmailAddresses(EMAIL_ADDRESSES_ATTRIBUTE, CONTAINS, EMAIL_TYPE_HOME_CLAIM_VALUE);
}

private void validateFilteredUser(String attributeName, String operator, String attributeValue) throws IOException {
Expand All @@ -325,6 +334,34 @@ private void validateFilteredUser(String attributeName, String operator, String
assertEquals(userId, this.userId);
}

private void validateFilteredUserByEmailAddresses(String attributeName, String operator, String attributeValue)
throws IOException {

String userResourcePath = getPath() + "?filter=" + USER_SYSTEM_SCHEMA + ":" + attributeName + operator
+ attributeValue;
HttpGet request = new HttpGet(userResourcePath);
request.addHeader(HttpHeaders.AUTHORIZATION, getAuthzHeader());
request.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");
request.addHeader(HttpHeaders.ACCEPT, "application/scim+json");
HttpResponse response = client.execute(request);
assertEquals(response.getStatusLine().getStatusCode(), 200, "User " +
"has not been retrieved successfully");

Object responseObj = JSONValue.parse(EntityUtils.toString(response.getEntity()));
EntityUtils.consume(response.getEntity());

JSONObject userResources = ((JSONObject) ((JSONArray) ((JSONObject) responseObj)
.get("Resources")).get(0));
JSONArray emailsArray = (JSONArray) ((JSONObject) userResources.get(USER_SYSTEM_SCHEMA)).get(attributeName);

for (Object email: emailsArray) {
if (email.equals(attributeValue)) {
return;
}
}
fail();
}

@Test(dependsOnMethods = "testFilterUser")
public void testDeleteUser() throws Exception {
String userResourcePath = getPath() + "/" + userId;
Expand Down