From f8ada0913a50b46b0b8ede06d8a95b42c2398d4d Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Fri, 12 Jul 2024 14:34:16 +0530 Subject: [PATCH 1/4] Integration tests for Organization /meta-attribute GET API --- .../v1/OrganizationManagementFailureTest.java | 19 +++++ .../v1/OrganizationManagementSuccessTest.java | 77 +++++++++++++++++++ .../test/restclients/RestBaseClient.java | 1 + ...er-hospital-organization-request-body.json | 1 + ...er-hospital-organization-request-body.json | 3 +- .../v1/organization-self-service-apis.json | 10 ++- 6 files changed, 107 insertions(+), 4 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java index 3dad1b3dba..d408b85b0a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java @@ -114,6 +114,7 @@ public void testGetM2MAccessToken() throws Exception { public void testSelfOnboardOrganization(String requestBodyPath) throws Exception { String body = readResource(requestBodyPath); + body = body.replace("${parentId}", ""); Response response = getResponseOfPostWithOAuth2(ORGANIZATION_MANAGEMENT_API_BASE_PATH, body, m2mToken); response.then() .log().ifValidationFails() @@ -146,6 +147,24 @@ public void testGetOrganizationsWithUnsupportedAttribute() { } @Test(dependsOnMethods = "testGetOrganizationsWithUnsupportedAttribute") + public void testGetOrganizationsMetaAttributesWithInvalidOperator() { + + String filterQuery = "?filter=attributes ca C&limit=10&recursive=false"; + String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + "/meta-attributes" + filterQuery; + Response response = getResponseOfGetWithOAuth2(endpointURL, m2mToken); + validateErrorResponseWithoutTraceId(response, HttpStatus.SC_BAD_REQUEST, "ORG-60059"); + } + + @Test(dependsOnMethods = "testGetOrganizationsMetaAttributesWithInvalidOperator") + public void testGetOrganizationsMetaAttributesWithUnsupportedAttribute() { + + String filterQuery = "?filter=attribute co S&limit=10&recursive=false"; + String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + "/meta-attributes" + filterQuery; + Response response = getResponseOfGetWithOAuth2(endpointURL, m2mToken); + validateErrorResponseWithoutTraceId(response, HttpStatus.SC_BAD_REQUEST, "ORG-60023"); + } + + @Test(dependsOnMethods = "testGetOrganizationsMetaAttributesWithUnsupportedAttribute") public void testGetDiscoveryConfigWithoutAddingConfig() { String endpointURL = ORGANIZATION_CONFIGS_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java index c226d5d09b..3f0bb5e0ad 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java @@ -18,6 +18,8 @@ package org.wso2.identity.integration.test.rest.api.server.organization.management.v1; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.nimbusds.oauth2.sdk.AccessTokenResponse; import com.nimbusds.oauth2.sdk.AuthorizationGrant; import com.nimbusds.oauth2.sdk.ClientCredentialsGrant; @@ -41,6 +43,7 @@ import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; @@ -81,6 +84,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.core.IsNull.notNullValue; import static org.testng.Assert.assertNotNull; +import static org.wso2.identity.integration.test.restclients.RestBaseClient.API_SERVER_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.CONTENT_TYPE_ATTRIBUTE; import static org.wso2.identity.integration.test.restclients.RestBaseClient.ORGANIZATION_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.TENANT_PATH; @@ -92,6 +96,7 @@ public class OrganizationManagementSuccessTest extends OrganizationManagementBaseTest { private String organizationID; + private String childOrganizationID; private String selfServiceAppId; private String selfServiceAppClientId; private String selfServiceAppClientSecret; @@ -223,6 +228,7 @@ public void getM2MAccessToken() throws Exception { public void testSelfOnboardOrganization() throws IOException { String body = readResource("add-greater-hospital-organization-request-body.json"); + body = body.replace("${parentId}", ""); Response response = getResponseOfPostWithOAuth2(ORGANIZATION_MANAGEMENT_API_BASE_PATH, body, m2mToken); response.then() .log().ifValidationFails() @@ -381,6 +387,64 @@ public void unShareB2BApplication() throws JSONException { } @Test(dependsOnMethods = "unShareB2BApplication") + public void testOnboardChildOrganization() throws IOException { + + String body = readResource("add-smaller-hospital-organization-request-body.json"); + body = body.replace("${parentId}", organizationID); + HttpPost request = new HttpPost(serverURL + TENANT_PATH + tenant + PATH_SEPARATOR + ORGANIZATION_PATH + + API_SERVER_PATH + ORGANIZATION_MANAGEMENT_API_BASE_PATH); + Header[] headerList = new Header[3]; + headerList[0] = new BasicHeader("Authorization", "Bearer " + switchedM2MToken); + headerList[1] = new BasicHeader(CONTENT_TYPE_ATTRIBUTE, "application/json"); + headerList[2] = new BasicHeader(HttpHeaders.ACCEPT, "application/json"); + request.setHeaders(headerList); + request.setEntity(new StringEntity(body)); + HttpResponse response = client.execute(request); + Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_CREATED); + + String jsonResponse = EntityUtils.toString(response.getEntity()); + JsonObject responseObject = JsonParser.parseString(jsonResponse).getAsJsonObject(); + childOrganizationID = responseObject.get("id").getAsString(); + assertNotNull(childOrganizationID); + } + + @DataProvider(name = "dataProviderForGetOrganizationsMetaAttributes") + public Object[][] dataProviderForGetOrganizationsMetaAttributes() { + + return new Object[][] { + {"?filter=attributes eq Country&limit=10&recursive=false", false, false}, + {"?filter=attributes eq Region&limit=10&recursive=true", true, false}, + {"?filter=attributes sw C and attributes ew try&limit=10&recursive=false", false, false}, + {"?filter=attributes co A&limit=10&recursive=true", false, true}, + }; + } + + @Test(dependsOnMethods = "testOnboardChildOrganization", + dataProvider = "dataProviderForGetOrganizationsMetaAttributes") + public void testGetOrganizationsMetaAttributes(String filterQuery, boolean isRecursive, boolean expectEmptyList) { + + String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + "/meta-attributes" + filterQuery; + Response response = getResponseOfGetWithOAuth2(endpointURL, m2mToken); + Assert.assertNotNull(response.asString()); + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK); + if (expectEmptyList) { + response.then() + .assertThat().body(equalTo("{}")); + } else if (isRecursive) { + response.then() + .body("attributes.size()", equalTo(1)) + .body("attributes[0]", equalTo("Region")); + } else { + response.then() + .body("attributes.size()", equalTo(1)) + .body("attributes[0]", equalTo("Country")); + } + } + + @Test(dependsOnMethods = "testGetOrganizationsMetaAttributes") public void testAddDiscoveryConfig() throws IOException { String endpointURL = ORGANIZATION_CONFIGS_API_BASE_PATH + ORGANIZATION_DISCOVERY_API_PATH; @@ -505,6 +569,19 @@ public void testDeleteDiscoveryConfig() { } @Test(dependsOnMethods = "testDeleteDiscoveryConfig") + public void testDeleteChildOrganization() throws IOException { + + HttpDelete request = new HttpDelete(serverURL + TENANT_PATH + tenant + PATH_SEPARATOR + ORGANIZATION_PATH + + API_SERVER_PATH + ORGANIZATION_MANAGEMENT_API_BASE_PATH + PATH_SEPARATOR + + childOrganizationID); + Header[] headerList = new Header[1]; + headerList[0] = new BasicHeader("Authorization", "Bearer " + switchedM2MToken); + request.setHeaders(headerList); + HttpResponse response = client.execute(request); + Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_NO_CONTENT); + } + + @Test(dependsOnMethods = "testDeleteChildOrganization") public void testDisablingOrganization() throws IOException { String endpoint = ORGANIZATION_MANAGEMENT_API_BASE_PATH + PATH_SEPARATOR + organizationID; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java index 55a4f34e81..08ce600246 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/RestBaseClient.java @@ -42,6 +42,7 @@ public class RestBaseClient { public static final String CONTENT_TYPE_ATTRIBUTE = "Content-Type"; public static final String AUTHORIZATION_ATTRIBUTE = "Authorization"; public static final String USER_AGENT_ATTRIBUTE = "User-Agent"; + public static final String API_SERVER_PATH = "api/server/v1"; public static final String TENANT_PATH = "t/"; public static final String ORGANIZATION_PATH = "o/"; public static final String PATH_SEPARATOR = "/"; diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/add-greater-hospital-organization-request-body.json b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/add-greater-hospital-organization-request-body.json index 5d868f7897..c3ec183649 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/add-greater-hospital-organization-request-body.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/add-greater-hospital-organization-request-body.json @@ -1,6 +1,7 @@ { "name": "Greater Hospital", "description": "Hospital chain in South Asia", + "parentId": "${parentId}", "attributes": [ { "key": "Country", diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/add-smaller-hospital-organization-request-body.json b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/add-smaller-hospital-organization-request-body.json index dd51eb9813..5b0d2ce334 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/add-smaller-hospital-organization-request-body.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/add-smaller-hospital-organization-request-body.json @@ -1,9 +1,10 @@ { "name": "Smaller Hospital", "description": "Hospital chain in South Asia", + "parentId": "${parentId}", "attributes": [ { - "key": "Country", + "key": "Region", "value": "Sri Lanka" }, { diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/organization-self-service-apis.json b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/organization-self-service-apis.json index d45180bb2d..9a79e36824 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/organization-self-service-apis.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/organization-self-service-apis.json @@ -2,7 +2,7 @@ "/api/server/v1/organizations": [ "internal_organization_view", "internal_organization_create" - ], + ], "/api/server/v1/organizations/discovery": [ "internal_organization_discovery_view", "internal_organization_discovery_update", @@ -16,7 +16,7 @@ "/scim2/Users": [ "internal_user_mgt_view", "internal_user_mgt_create" - ], + ], "/o/scim2/Users": [ "internal_org_user_mgt_create", "internal_org_user_mgt_list" @@ -27,5 +27,9 @@ ], "/o/api/server/v1/applications": [ "internal_org_application_mgt_view" + ], + "/o/api/server/v1/organizations": [ + "internal_org_organization_create", + "internal_org_organization_delete" ] -} \ No newline at end of file +} From eafee3d6d08037c815d2610fd59f737cd12c5a83 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Thu, 18 Jul 2024 10:15:50 +0530 Subject: [PATCH 2/4] Added review suggestion for empty strings --- .../management/v1/OrganizationManagementFailureTest.java | 3 ++- .../management/v1/OrganizationManagementSuccessTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java index d408b85b0a..b20b4494dc 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementFailureTest.java @@ -19,6 +19,7 @@ package org.wso2.identity.integration.test.rest.api.server.organization.management.v1; import io.restassured.response.Response; +import org.apache.commons.lang.StringUtils; import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; import org.apache.http.client.HttpClient; @@ -114,7 +115,7 @@ public void testGetM2MAccessToken() throws Exception { public void testSelfOnboardOrganization(String requestBodyPath) throws Exception { String body = readResource(requestBodyPath); - body = body.replace("${parentId}", ""); + body = body.replace("${parentId}", StringUtils.EMPTY); Response response = getResponseOfPostWithOAuth2(ORGANIZATION_MANAGEMENT_API_BASE_PATH, body, m2mToken); response.then() .log().ifValidationFails() diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java index 3f0bb5e0ad..96db3ab91f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java @@ -228,7 +228,7 @@ public void getM2MAccessToken() throws Exception { public void testSelfOnboardOrganization() throws IOException { String body = readResource("add-greater-hospital-organization-request-body.json"); - body = body.replace("${parentId}", ""); + body = body.replace("${parentId}", StringUtils.EMPTY); Response response = getResponseOfPostWithOAuth2(ORGANIZATION_MANAGEMENT_API_BASE_PATH, body, m2mToken); response.then() .log().ifValidationFails() From e1f57206a3a95698c00eb4cba98e6f52bdcf8939 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Wed, 24 Jul 2024 12:53:08 +0530 Subject: [PATCH 3/4] Added review suggestions to change dataprovidors --- .../v1/OrganizationManagementSuccessTest.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java index 96db3ab91f..843c631e5b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/organization/management/v1/OrganizationManagementSuccessTest.java @@ -259,18 +259,19 @@ public void testGetOrganization() { public Object[][] dataProviderForFilterOrganizations() { return new Object[][] { - {"?filter=name co G&limit=10&recursive=false", false, false}, - {"?filter=attributes.Country co S&limit=10&recursive=false", true, false}, - {"?filter=attributes.Country eq Sri Lanka&limit=10&recursive=false", true, false}, - {"?filter=attributes.Country eq Sri Lanka and name co Greater&limit=10&recursive=false", true, false}, - {"?filter=attributes.Country eq USA&limit=10&recursive=false", false, true} + {"name co G", false, false}, + {"attributes.Country co S", true, false}, + {"attributes.Country eq Sri Lanka", true, false}, + {"attributes.Country eq Sri Lanka and name co Greater", true, false}, + {"attributes.Country eq USA", false, true} }; } @Test(dependsOnMethods = "testGetOrganization", dataProvider = "dataProviderForFilterOrganizations") public void testFilterOrganizations(String filterQuery, boolean expectAttributes, boolean expectEmptyList) { - String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + filterQuery; + String query = "?filter=" + filterQuery + "&limit=1&recursive=false"; + String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + query; Response response = getResponseOfGetWithOAuth2(endpointURL, m2mToken); Assert.assertNotNull(response.asString()); response.then() @@ -412,18 +413,19 @@ public void testOnboardChildOrganization() throws IOException { public Object[][] dataProviderForGetOrganizationsMetaAttributes() { return new Object[][] { - {"?filter=attributes eq Country&limit=10&recursive=false", false, false}, - {"?filter=attributes eq Region&limit=10&recursive=true", true, false}, - {"?filter=attributes sw C and attributes ew try&limit=10&recursive=false", false, false}, - {"?filter=attributes co A&limit=10&recursive=true", false, true}, + {"attributes eq Country", false, false}, + {"attributes sw C and attributes ew try", false, false}, + {"attributes eq Region", true, false}, + {"attributes co A", true, true}, }; } @Test(dependsOnMethods = "testOnboardChildOrganization", dataProvider = "dataProviderForGetOrganizationsMetaAttributes") - public void testGetOrganizationsMetaAttributes(String filterQuery, boolean isRecursive, boolean expectEmptyList) { + public void testGetOrganizationsMetaAttributes(String filter, boolean isRecursive, boolean expectEmptyList) { - String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + "/meta-attributes" + filterQuery; + String query = "?filter=" + filter + "&limit=1&recursive=" + isRecursive; + String endpointURL = ORGANIZATION_MANAGEMENT_API_BASE_PATH + "/meta-attributes" + query; Response response = getResponseOfGetWithOAuth2(endpointURL, m2mToken); Assert.assertNotNull(response.asString()); response.then() From 17ac75f56dc2c4b3d8cffee1be8942716f4c4252 Mon Sep 17 00:00:00 2001 From: Hasini Samarathunga Date: Wed, 24 Jul 2024 13:59:08 +0530 Subject: [PATCH 4/4] Bump identity-api-server and identity-organization-management-core versions --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a75cb56758..11424accb3 100755 --- a/pom.xml +++ b/pom.xml @@ -2362,7 +2362,7 @@ 1.0.7 1.4.42 - 1.1.10 + 1.1.12 1.1.33 1.1.25 @@ -2375,7 +2375,7 @@ 2.0.17 1.3.38 - 1.2.203 + 1.2.212 5.5.9 5.5.8