From 3972ca48d36b78b5aaa0f312fccefc2323718c31 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Wed, 26 Feb 2025 15:13:01 +0530 Subject: [PATCH 01/39] introduce selective sharing tests for one policy per share. --- .../management/v1/UserSharingBaseTest.java | 4 +- .../management/v1/UserSharingSuccessTest.java | 339 ++++++++++++++++-- 2 files changed, 309 insertions(+), 34 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index fd91e3f4b35..d4217141188 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -106,8 +106,8 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String SUPER_ORG = "Super"; - protected static final String APPLICATION_AUDIENCE = "APPLICATION"; - protected static final String ORGANIZATION_AUDIENCE = "ORGANIZATION"; + protected static final String APPLICATION_AUDIENCE = "application"; + protected static final String ORGANIZATION_AUDIENCE = "organization"; protected static final String APP_ROLE_1 = "app-role-1"; protected static final String APP_ROLE_2 = "app-role-2"; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index dac0e488bb8..6c00ef68b98 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -37,6 +37,7 @@ import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyUserCriteria; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; @@ -45,7 +46,10 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Stream; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.everyItem; @@ -157,14 +161,37 @@ public static Object[][] restAPIUserConfigProvider() { }; } - @Test - public void testShareUsersWithOrganizations() { + @DataProvider(name = "generalSharingPolicies") + public Object[][] generalSharingPolicies() { - UserShareRequestBody requestBody = new UserShareRequestBody() + String[] allOrgIds = {l1Org1Id, l1Org2Id, l2Org1Id, l2Org2Id, l2Org3Id, l3Org1Id}; + String[] allOrgNames = + {L1_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L2_ORG_3_NAME, L3_ORG_1_NAME}; + String[] immediateOrgIds = {l1Org1Id, l1Org2Id}; + String[] immediateOrgNames = {L1_ORG_1_NAME, L1_ORG_2_NAME}; + + return new Object[][]{ + {UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY, 6, allOrgIds, allOrgNames}, + {UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_AND_FUTURE_ORGS, 6, allOrgIds, allOrgNames}, + {UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_ORGS_ONLY, 2, immediateOrgIds, + immediateOrgNames}, + {UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_AND_FUTURE_ORGS, 2, immediateOrgIds, + immediateOrgNames} + }; + } + + @Test(dataProvider = "generalSharingPolicies") + public void testShareUsersWithAllOrganizations(UserShareWithAllRequestBody.PolicyEnum policy, int expectedOrgCount, String[] expectedOrgIds, String[] expectedOrgNames) + throws Exception { + + UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() .userCriteria(getUserCriteria()) - .organizations(getOrganizations()); + .policy(policy) + .roles(Arrays.asList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, SUPER_ORG, ORGANIZATION_AUDIENCE))); - Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBody)); + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, toJSONString(requestBody)); response.then() .log().ifValidationFails() @@ -172,10 +199,19 @@ public void testShareUsersWithOrganizations() { .statusCode(HttpStatus.SC_ACCEPTED) .body("status", equalTo("Processing")) .body("details", equalTo("User sharing process triggered successfully.")); + + Thread.sleep(5000); // Wait for the sharing process to complete. + + // Validate shared organizations + testGetSharedOrganizationsWithAllWithoutPagination(expectedOrgCount, expectedOrgIds, expectedOrgNames); + + // Validate shared roles for each shared organization + for (int i = 0; i < expectedOrgCount; i++) { + testGetSharedRolesForOrgWithRolesWithoutPagination(expectedOrgIds[i], expectedOrgNames[i]); + } } - @Test(dependsOnMethods = "testShareUsersWithOrganizations") - public void testGetSharedOrganizationsWithoutPagination() throws Exception { + public void testGetSharedOrganizationsWithAllWithoutPagination(int expectedOrgCount, String[] expectedOrgIds, String[] expectedOrgNames) throws Exception { Response response = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + rootOrgUserId + SHARED_ORGANIZATIONS_PATH); @@ -187,16 +223,32 @@ public void testGetSharedOrganizationsWithoutPagination() throws Exception { .body("links.size()", equalTo(1)) .body("links[0].isEmpty()", equalTo(true)) .body("sharedOrganizations", notNullValue()) - .body("sharedOrganizations.size()", equalTo(4)) - .body("sharedOrganizations.orgId", hasItems(l1Org1Id, l1Org2Id, l2Org1Id, l2Org2Id)) - .body("sharedOrganizations.orgName", - hasItems(L1_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_1_NAME, L1_ORG_2_NAME)) + .body("sharedOrganizations.size()", equalTo(expectedOrgCount)) + .body("sharedOrganizations.orgId", hasItems(expectedOrgIds)) + .body("sharedOrganizations.orgName", hasItems(expectedOrgNames)) .body("sharedOrganizations.sharedType", everyItem(equalTo("SHARED"))) .body("sharedOrganizations.rolesRef", hasItems( - getSharedOrgsRolesRef(rootOrgUserId, l1Org1Id), - getSharedOrgsRolesRef(rootOrgUserId, l1Org2Id), - getSharedOrgsRolesRef(rootOrgUserId, l2Org1Id), - getSharedOrgsRolesRef(rootOrgUserId, l2Org2Id))); + Arrays.stream(expectedOrgIds) + .map(orgId -> getSharedOrgsRolesRef(rootOrgUserId, orgId)) + .toArray(String[]::new))); + } + + public void testGetSharedRolesForOrgWithRolesWithoutPagination(String orgId, String orgName) { + + Response response = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + rootOrgUserId + SHARED_ROLES_PATH, + Collections.singletonMap("orgId", orgId)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body("links.size()", equalTo(1)) // Ensure one empty object inside the array + .body("links[0].isEmpty()", equalTo(true)) // Ensure the object inside is empty + .body("roles", notNullValue()) + .body("roles.size()", equalTo(2)) // Expecting 2 roles per shared organization + .body("roles.displayName", hasItems(APP_ROLE_1, ORG_ROLE_1)) // Ensure both roles exist + .body("roles.audience.display", hasItems(APP_1_NAME, orgName)) // Ensure correct audience + .body("roles.audience.type", hasItems(APPLICATION_AUDIENCE, ORGANIZATION_AUDIENCE)); // Ensure correct types } private UserShareRequestBodyUserCriteria getUserCriteria() { @@ -206,23 +258,6 @@ private UserShareRequestBodyUserCriteria getUserCriteria() { return criteria; } - private List getOrganizations() { - - UserShareRequestBodyOrganizations organizationWithRoles = new UserShareRequestBodyOrganizations(); - organizationWithRoles.setOrgId(l1Org1Id); - organizationWithRoles.setPolicy( - UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); - organizationWithRoles.setRoles( - Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_1, SUPER_ORG, ORGANIZATION_AUDIENCE))); - - UserShareRequestBodyOrganizations organizationWithoutRoles = new UserShareRequestBodyOrganizations(); - organizationWithoutRoles.setOrgId(l1Org2Id); - organizationWithoutRoles.setPolicy(UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY); - - return Arrays.asList(organizationWithRoles, organizationWithoutRoles); - } - private RoleWithAudience createRoleWithAudience(String roleName, String display, String type) { RoleWithAudienceAudience audience = new RoleWithAudienceAudience(); @@ -275,6 +310,11 @@ protected void setupApplicationsAndRoles() throws Exception { clientSecretApp2 = oidcConfigOfApp2.getClientSecret(); createOrganizationRoles(); switchApplicationAudience(app2Id, AssociatedRolesConfig.AllowedAudienceEnum.ORGANIZATION); + // Mark roles and groups as requested claims for the app 2. + updateRequestedClaimsOfApp(app2Id, getClaimConfigurationsWithRolesAndGroups()); + shareApplication(app2Id); + sharedApp2IdInLevel1Org = + oAuth2RestClient.getAppIdUsingAppNameInOrganization(APP_2_NAME, l1Org1SwitchToken); } private void createOrganizationRoles() throws IOException { @@ -360,4 +400,239 @@ private void closeRestClients() throws IOException { scim2RestClient.closeHttpClient(); orgMgtRestClient.closeHttpClient(); } + + + + @DataProvider(name = "selectiveSharingPoliciesWithRoles") + public Object[][] selectiveSharingPoliciesWithRoles() { + return new Object[][]{ + createTestCase(UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY, + new String[]{l1Org1Id}, + new String[]{L1_ORG_1_NAME}, + new RoleWithAudience[]{createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE)}, + createExpectedRoles( + L1_ORG_1_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE) + ), + new String[]{l1Org2Id}, + new String[]{L1_ORG_2_NAME}, + new RoleWithAudience[]{createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE)}, + createExpectedRoles( + L1_ORG_2_NAME, createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE) + ) + ), + createTestCase(UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY, + new String[]{l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id}, + new String[]{L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME}, + new RoleWithAudience[]{ + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE) + }, + createExpectedRoles( + L1_ORG_1_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + L2_ORG_1_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + L2_ORG_2_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + L3_ORG_1_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE) + ), + new String[]{l1Org2Id, l2Org3Id}, + new String[]{L1_ORG_2_NAME, L2_ORG_3_NAME}, + new RoleWithAudience[]{ + createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE) + }, + createExpectedRoles( + L1_ORG_2_NAME, createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE), + L2_ORG_3_NAME, createRoleWithAudience(ORG_ROLE_2, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE) + ) + ), + createTestCase(UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN, + new String[]{l1Org1Id, l2Org1Id, l2Org2Id}, + new String[]{L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME}, + new RoleWithAudience[]{createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE)}, + createExpectedRoles( + L1_ORG_1_NAME, createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE), + L2_ORG_1_NAME, createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE), + L2_ORG_2_NAME, createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE) + ), + new String[]{l1Org2Id, l2Org3Id}, + new String[]{L1_ORG_2_NAME, L2_ORG_3_NAME}, + new RoleWithAudience[]{}, + createExpectedRoles( + L1_ORG_2_NAME, new RoleWithAudience[]{}, + L2_ORG_3_NAME, new RoleWithAudience[]{} + ) + ) + }; + } + + + @Test(dataProvider = "selectiveSharingPoliciesWithRoles") + public void testSelectiveUserSharingWithRoles( + UserShareRequestBodyOrganizations.PolicyEnum policy, + String[] expectedOrgIdsForL1Org1, String[] expectedOrgNamesForL1Org1, RoleWithAudience[] rolesForL1Org1, + Map expectedRolesForL1Org1, + String[] expectedOrgIdsForL1Org2, String[] expectedOrgNamesForL1Org2, RoleWithAudience[] rolesForL1Org2, + Map expectedRolesForL1Org2) throws Exception { + + UserShareRequestBody requestBody = new UserShareRequestBody() + .userCriteria(getUserCriteria()) + .organizations(Arrays.asList( + new UserShareRequestBodyOrganizations() + .orgId(l1Org1Id) + .policy(policy) + .roles(Arrays.asList(rolesForL1Org1)), + new UserShareRequestBodyOrganizations() + .orgId(l1Org2Id) + .policy(policy) + .roles(Arrays.asList(rolesForL1Org2)) + )); + + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body("status", equalTo("Processing")) + .body("details", equalTo("User sharing process triggered successfully.")); + + // Validate shared organizations + validateSharedOrganizations(expectedOrgIdsForL1Org1, expectedOrgNamesForL1Org1, expectedOrgIdsForL1Org2, expectedOrgNamesForL1Org2); + + // Validate roles in shared organizations + validateSharedRoles(expectedOrgIdsForL1Org1, expectedRolesForL1Org1); + validateSharedRoles(expectedOrgIdsForL1Org2, expectedRolesForL1Org2); + } + + private void validateSharedOrganizations(String[] expectedOrgIds1, String[] expectedOrgNames1, String[] expectedOrgIds2, String[] expectedOrgNames2) + throws Exception { + testGetSharedOrganizationsWithAllWithoutPagination(expectedOrgIds1.length + expectedOrgIds2.length, + Stream.concat(Arrays.stream(expectedOrgIds1), Arrays.stream(expectedOrgIds2)).toArray(String[]::new), + Stream.concat(Arrays.stream(expectedOrgNames1), Arrays.stream(expectedOrgNames2)).toArray(String[]::new)); + } + + private void validateSharedRoles(String[] expectedOrgIds, Map expectedRoles) { + for (String orgId : expectedOrgIds) { + String orgName = getOrgNameById(orgId); + testGetSharedRolesForOrgWithRolesWithoutPagination(orgId, orgName, expectedRoles.get(orgName)); + } + } + + private Object[] createTestCase(UserShareRequestBodyOrganizations.PolicyEnum policy, + String[] orgIds1, String[] orgNames1, RoleWithAudience[] roles1, Map expectedRoles1, + String[] orgIds2, String[] orgNames2, RoleWithAudience[] roles2, Map expectedRoles2) { + return new Object[]{policy, orgIds1, orgNames1, roles1, expectedRoles1, orgIds2, orgNames2, roles2, expectedRoles2}; + } + + private Map createExpectedRoles(Object... data) { + Map roleMap = new HashMap<>(); + for (int i = 0; i < data.length; i += 2) { + roleMap.put((String) data[i], new RoleWithAudience[]{(RoleWithAudience) data[i + 1]}); + } + return roleMap; + } + +// @Test(dataProvider = "selectiveSharingPoliciesWithRoles") +// public void testSelectiveUserSharingWithRoles( +// UserShareRequestBodyOrganizations.PolicyEnum policy, +// String[] expectedOrgIdsForL1Org1, String[] expectedOrgNamesForL1Org1, RoleWithAudience[] rolesForL1Org1, +// Map expectedRolesForL1Org1, +// String[] expectedOrgIdsForL1Org2, String[] expectedOrgNamesForL1Org2, RoleWithAudience[] rolesForL1Org2, +// Map expectedRolesForL1Org2) +// throws Exception { +// +// UserShareRequestBody requestBody = new UserShareRequestBody() +// .userCriteria(getUserCriteria()) +// .organizations(Arrays.asList( +// new UserShareRequestBodyOrganizations() +// .orgId(l1Org1Id) +// .policy(policy) +// .roles(Arrays.asList(rolesForL1Org1)), +// new UserShareRequestBodyOrganizations() +// .orgId(l1Org2Id) +// .policy(policy) +// .roles(Arrays.asList(rolesForL1Org2)) +// )); +// +// Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBody)); +// +// response.then() +// .log().ifValidationFails() +// .assertThat() +// .statusCode(HttpStatus.SC_ACCEPTED) +// .body("status", equalTo("Processing")) +// .body("details", equalTo("User sharing process triggered successfully.")); +// +// Thread.sleep(5000); // Wait for sharing process to complete. +// +// // Validate shared organizations +// testGetSharedOrganizationsWithAllWithoutPagination(expectedOrgIdsForL1Org1.length+expectedOrgIdsForL1Org2.length, +// Stream.concat(Arrays.stream(expectedOrgIdsForL1Org1), +// Arrays.stream(expectedOrgIdsForL1Org2)) +// .toArray(String[]::new), +// Stream.concat(Arrays.stream(expectedOrgNamesForL1Org1), +// Arrays.stream(expectedOrgNamesForL1Org2)) +// .toArray(String[]::new)); +// +// // Validate roles in shared organizations +// for (String orgId : expectedOrgIdsForL1Org1) { +// String orgName = getOrgNameById(orgId); +// testGetSharedRolesForOrgWithRolesWithoutPagination(orgId, orgName, +// expectedRolesForL1Org1.get(orgName)); +// } +// for (String orgId : expectedOrgIdsForL1Org2) { +// String orgName = getOrgNameById(orgId); +// testGetSharedRolesForOrgWithRolesWithoutPagination(orgId, orgName, +// expectedRolesForL1Org2.get(orgName)); +// } +// } + + public void testGetSharedRolesForOrgWithRolesWithoutPagination(String orgId, String orgName, RoleWithAudience[] expectedRoles) { + + Response response = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + rootOrgUserId + SHARED_ROLES_PATH, + Collections.singletonMap("orgId", orgId)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body("links.size()", equalTo(1)) + .body("links[0].isEmpty()", equalTo(true)) + .body("roles", notNullValue()) + .body("roles.size()", equalTo(expectedRoles.length)); + + if (expectedRoles.length > 0) { + response.then() + .body("roles.displayName", hasItems( + Arrays.stream(expectedRoles) + .map(RoleWithAudience::getDisplayName) + .toArray(String[]::new))) + .body("roles.audience.display", hasItems( + Arrays.stream(expectedRoles) + .map(role -> role.getAudience().getDisplay()) + .toArray(String[]::new)))// Now directly matching expected audiences + .body("roles.audience.type", hasItems( + Arrays.stream(expectedRoles) + .map(role -> role.getAudience().getType()) + .toArray(String[]::new))); + } + } + + private String getOrgNameById(String orgId) { + if (orgId.equals(l1Org1Id)) { + return L1_ORG_1_NAME; + } else if (orgId.equals(l1Org2Id)) { + return L1_ORG_2_NAME; + } else if (orgId.equals(l2Org1Id)) { + return L2_ORG_1_NAME; + } else if (orgId.equals(l2Org2Id)) { + return L2_ORG_2_NAME; + } else if (orgId.equals(l2Org3Id)) { + return L2_ORG_3_NAME; + } else if (orgId.equals(l3Org1Id)) { + return L3_ORG_1_NAME; + } + return null; + } + + } From 43200391b7da97381264aaa2c84b079bfec3e274 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Wed, 26 Feb 2025 17:26:01 +0530 Subject: [PATCH 02/39] selective share new test with one data object. --- .../management/v1/UserSharingBaseTest.java | 32 +- .../management/v1/UserSharingSuccessTest.java | 566 ++++++++---------- 2 files changed, 276 insertions(+), 322 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index d4217141188..114981900a5 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -81,13 +81,13 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { static final String SHARED_ORGANIZATIONS_PATH = "/shared-organizations"; static final String SHARED_ROLES_PATH = "/shared-roles"; - protected static final String USER_ID = "userId"; - protected static final String ORG_ID = "orgId"; - protected static final String LIMIT_QUERY_PARAM = "limit"; - protected static final String AFTER_QUERY_PARAM = "after"; - protected static final String BEFORE_QUERY_PARAM = "before"; - protected static final String FILTER_QUERY_PARAM = "filter"; - protected static final String RECURSIVE_QUERY_PARAM = "recursive"; + protected static final String PATH_PARAM_USER_ID = "userId"; + protected static final String QUERY_PARAM_ORG_ID = "orgId"; + protected static final String QUERY_PARAM_LIMIT = "limit"; + protected static final String QUERY_PARAM_AFTER = "after"; + protected static final String QUERY_PARAM_BEFORE = "before"; + protected static final String QUERY_PARAM_FILTER = "filter"; + protected static final String QUERY_PARAM_RECURSIVE = "recursive"; protected static final String ERROR_CODE_BAD_REQUEST = "UE-10000"; protected static final String ERROR_CODE_INVALID_PAGINATION_CURSOR = "ORG-60026"; @@ -96,6 +96,7 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String ROOT_ORG_NAME = "Root - Organization"; protected static final String L1_ORG_1_NAME = "L1 - Organization 1"; protected static final String L1_ORG_2_NAME = "L1 - Organization 2"; + protected static final String L1_ORG_3_NAME = "L1 - Organization 3"; protected static final String L2_ORG_1_NAME = "L2 - Organization 1"; protected static final String L2_ORG_2_NAME = "L2 - Organization 2"; protected static final String L2_ORG_3_NAME = "L2 - Organization 3"; @@ -116,8 +117,12 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String ORG_ROLE_2 = "org-role-2"; protected static final String ORG_ROLE_3 = "org-role-3"; - protected static final String ROOT_ORG_USERNAME = "rootUser"; - protected static final String L1_ORG_1_USERNAME = "l1Org1User"; + protected static final String ROOT_ORG_USER_1_USERNAME = "rootUser1"; + protected static final String ROOT_ORG_USER_2_USERNAME = "rootUser2"; + protected static final String ROOT_ORG_USER_3_USERNAME = "rootUser3"; + protected static final String L1_ORG_1_USER_1_USERNAME = "l1Org1User1"; + protected static final String L1_ORG_1_USER_2_USERNAME = "l1Org1User2"; + protected static final String L1_ORG_1_USER_3_USERNAME = "l1Org1User3"; protected static final String INTERNAL_USER_SHARE = "internal_user_share"; protected static final String INTERNAL_USER_UNSHARE = "internal_user_unshare"; @@ -131,6 +136,15 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String ROLES_CLAIM_URI = "http://wso2.org/claims/roles"; protected static final String GROUPS_CLAIM_URI = "http://wso2.org/claims/groups"; + protected static final String MAP_KEY_ORG_DETAILS_ORG_ID = "orgId"; + protected static final String MAP_KEY_ORG_DETAILS_ORG_NAME = "orgName"; + protected static final String MAP_KEY_ORG_DETAILS_POLICY = "policy"; + protected static final String MAP_KEY_ORG_DETAILS_ROLES = "roles"; + protected static final String MAP_KEY_ORG_DETAILS_EXPECTED_ORG_COUNT = "expectedOrgCount"; + protected static final String MAP_KEY_ORG_DETAILS_EXPECTED_ORG_IDS = "expectedOrgIds"; + protected static final String MAP_KEY_ORG_DETAILS_EXPECTED_ORG_NAMES = "expectedOrgNames"; + protected static final String MAP_KEY_ORG_DETAILS_EXPECTED_ROLES_PER_EXPECTED_ORG = "expectedRolesPerExpectedOrg"; + protected static String swaggerDefinition; protected OAuth2RestClient oAuth2RestClient; protected SCIM2RestClient scim2RestClient; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 6c00ef68b98..d16a8a73fe7 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -37,35 +37,43 @@ import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyUserCriteria; -import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; import org.wso2.identity.integration.test.restclients.SCIM2RestClient; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Stream; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; /** * Tests for successful cases of the User Sharing REST APIs. */ public class UserSharingSuccessTest extends UserSharingBaseTest { - private String rootOrgUserId; - private String l1Org1UserId; + private String rootOrgUser1Id; + private String rootOrgUser2Id; + private String rootOrgUser3Id; + private String l1Org1User1Id; + private String l1Org1User2Id; + private String l1Org1User3Id; + private String l1Org1Id; private String l1Org2Id; + private String l1Org3Id; private String l2Org1Id; private String l2Org2Id; private String l2Org3Id; @@ -124,31 +132,10 @@ public void init() throws Exception { @AfterClass(alwaysRun = true) public void testConclude() throws Exception { - // Cleanup users - deleteUserIfExists(rootOrgUserId); - deleteSubOrgUserIfExists(l1Org1UserId, l1Org1SwitchToken); - - // Cleanup roles - deleteRoleIfExists(appRole1Id); - deleteRoleIfExists(appRole2Id); - deleteRoleIfExists(appRole3Id); - deleteRoleIfExists(orgRole1Id); - deleteRoleIfExists(orgRole2Id); - deleteRoleIfExists(orgRole3Id); - - // Cleanup applications - deleteApplicationIfExists(application1WithAppAudienceRoles.getId()); - deleteApplicationIfExists(application2WithOrgAudienceRoles.getId()); - - // Cleanup organizations - deleteSubOrganizationIfExists(l3Org1Id, l2Org1Id); - deleteSubOrganizationIfExists(l2Org3Id, l1Org2Id); - deleteSubOrganizationIfExists(l2Org2Id, l1Org1Id); - deleteSubOrganizationIfExists(l2Org1Id, l1Org1Id); - deleteOrganizationIfExists(l1Org2Id); - deleteOrganizationIfExists(l1Org1Id); - - // Close REST clients + cleanUpUsers(); + cleanUpRoles(); + cleanUpApplications(); + cleanUpOrganizations(); closeRestClients(); } @@ -161,37 +148,30 @@ public static Object[][] restAPIUserConfigProvider() { }; } - @DataProvider(name = "generalSharingPolicies") - public Object[][] generalSharingPolicies() { + // Selective User Sharing. - String[] allOrgIds = {l1Org1Id, l1Org2Id, l2Org1Id, l2Org2Id, l2Org3Id, l3Org1Id}; - String[] allOrgNames = - {L1_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L2_ORG_3_NAME, L3_ORG_1_NAME}; - String[] immediateOrgIds = {l1Org1Id, l1Org2Id}; - String[] immediateOrgNames = {L1_ORG_1_NAME, L1_ORG_2_NAME}; + @DataProvider(name = "selectiveSharingPoliciesWithRoles") + public Object[][] selectiveSharingPoliciesWithRoles() { - return new Object[][]{ - {UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY, 6, allOrgIds, allOrgNames}, - {UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_AND_FUTURE_ORGS, 6, allOrgIds, allOrgNames}, - {UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_ORGS_ONLY, 2, immediateOrgIds, - immediateOrgNames}, - {UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_AND_FUTURE_ORGS, 2, immediateOrgIds, - immediateOrgNames} + List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); + Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingTestCase1(); + Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingTestCase1(); + + return new Object[][] { + { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1 } }; } - @Test(dataProvider = "generalSharingPolicies") - public void testShareUsersWithAllOrganizations(UserShareWithAllRequestBody.PolicyEnum policy, int expectedOrgCount, String[] expectedOrgIds, String[] expectedOrgNames) - throws Exception { + @Test(dataProvider = "selectiveSharingPoliciesWithRoles") + public void testSelectiveUserSharingWithRoles(List userIds, + Map> organizations, + Map expectedResults) { - UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() - .userCriteria(getUserCriteria()) - .policy(policy) - .roles(Arrays.asList( - createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_1, SUPER_ORG, ORGANIZATION_AUDIENCE))); + UserShareRequestBody requestBody = new UserShareRequestBody() + .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) + .organizations(getOrganizationsForSelectiveUserSharing(organizations)); - Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, toJSONString(requestBody)); + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBody)); response.then() .log().ifValidationFails() @@ -200,21 +180,53 @@ public void testShareUsersWithAllOrganizations(UserShareWithAllRequestBody.Polic .body("status", equalTo("Processing")) .body("details", equalTo("User sharing process triggered successfully.")); - Thread.sleep(5000); // Wait for the sharing process to complete. - - // Validate shared organizations - testGetSharedOrganizationsWithAllWithoutPagination(expectedOrgCount, expectedOrgIds, expectedOrgNames); + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + } + } - // Validate shared roles for each shared organization - for (int i = 0; i < expectedOrgCount; i++) { - testGetSharedRolesForOrgWithRolesWithoutPagination(expectedOrgIds[i], expectedOrgNames[i]); + // General User Sharing. + + + /** + * Validate that the user has been shared to the expected organizations with the expected roles. + * + * @param userId The ID of the user to validate. + * @param expectedResults A map containing the expected results, including the expected organization count, + * expected organization IDs, expected organization names, and expected roles per organization. + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are predefined + * in the test data providers. + *

+ */ + @SuppressWarnings("unchecked") + private void validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(String userId, Map expectedResults) { + + testGetSharedOrganizations( + userId, + (int) expectedResults.get(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_COUNT), + (List) expectedResults.get(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_IDS), + (List) expectedResults.get(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_NAMES) + ); + + Map> expectedRolesPerExpectedOrg = (Map>) expectedResults.get(MAP_KEY_ORG_DETAILS_EXPECTED_ROLES_PER_EXPECTED_ORG); + for (Map.Entry> entry : expectedRolesPerExpectedOrg.entrySet()) { + testGetSharedRolesForOrg(userId, entry.getKey(), entry.getValue()); } } - public void testGetSharedOrganizationsWithAllWithoutPagination(int expectedOrgCount, String[] expectedOrgIds, String[] expectedOrgNames) throws Exception { + /** + * Test method for GET /user-sharing/{userId}/shared-organizations. + * + * @param userId The ID of the user to get shared organizations for. + * @param expectedOrgCount The expected number of shared organizations. + * @param expectedOrgIds The expected IDs of the shared organizations. + * @param expectedOrgNames The expected names of the shared organizations. + */ + public void testGetSharedOrganizations(String userId, int expectedOrgCount, List expectedOrgIds, List expectedOrgNames) { Response response = - getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + rootOrgUserId + SHARED_ORGANIZATIONS_PATH); + getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ORGANIZATIONS_PATH); response.then() .log().ifValidationFails() @@ -224,40 +236,155 @@ public void testGetSharedOrganizationsWithAllWithoutPagination(int expectedOrgCo .body("links[0].isEmpty()", equalTo(true)) .body("sharedOrganizations", notNullValue()) .body("sharedOrganizations.size()", equalTo(expectedOrgCount)) - .body("sharedOrganizations.orgId", hasItems(expectedOrgIds)) - .body("sharedOrganizations.orgName", hasItems(expectedOrgNames)) + .body("sharedOrganizations.orgId", hasItems(expectedOrgIds.toArray(new String[0]))) + .body("sharedOrganizations.orgName", hasItems(expectedOrgNames.toArray(new String[0]))) .body("sharedOrganizations.sharedType", everyItem(equalTo("SHARED"))) .body("sharedOrganizations.rolesRef", hasItems( - Arrays.stream(expectedOrgIds) - .map(orgId -> getSharedOrgsRolesRef(rootOrgUserId, orgId)) + expectedOrgIds.stream() + .map(orgId -> getSharedOrgsRolesRef(userId, orgId)) .toArray(String[]::new))); } - public void testGetSharedRolesForOrgWithRolesWithoutPagination(String orgId, String orgName) { + /** + * Test method for GET /user-sharing/{userId}/shared-roles?orgId={orgId}. + * + * @param userId The ID of the user to get shared roles for. + * @param orgId The ID of the organization to get shared roles for. + * @param expectedRoles The expected roles for the user in the specified organization. + */ + public void testGetSharedRolesForOrg(String userId, String orgId, List expectedRoles) { - Response response = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + rootOrgUserId + SHARED_ROLES_PATH, - Collections.singletonMap("orgId", orgId)); + Response response = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH, + Collections.singletonMap(QUERY_PARAM_ORG_ID, orgId)); response.then() .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_OK) - .body("links.size()", equalTo(1)) // Ensure one empty object inside the array - .body("links[0].isEmpty()", equalTo(true)) // Ensure the object inside is empty + .body("links.size()", equalTo(1)) + .body("links[0].isEmpty()", equalTo(true)) .body("roles", notNullValue()) - .body("roles.size()", equalTo(2)) // Expecting 2 roles per shared organization - .body("roles.displayName", hasItems(APP_ROLE_1, ORG_ROLE_1)) // Ensure both roles exist - .body("roles.audience.display", hasItems(APP_1_NAME, orgName)) // Ensure correct audience - .body("roles.audience.type", hasItems(APPLICATION_AUDIENCE, ORGANIZATION_AUDIENCE)); // Ensure correct types + .body("roles.size()", equalTo(expectedRoles.size())); + + if (!expectedRoles.isEmpty()) { + response.then() + .body("roles.displayName", hasItems( + expectedRoles.stream() + .map(RoleWithAudience::getDisplayName) + .toArray(String[]::new))) + .body("roles.audience.display", hasItems( + expectedRoles.stream() + .map(role -> role.getAudience().getDisplay()) + .toArray(String[]::new))) + .body("roles.audience.type", hasItems( + expectedRoles.stream() + .map(role -> role.getAudience().getType()) + .toArray(String[]::new))); + } } - private UserShareRequestBodyUserCriteria getUserCriteria() { + /** + * Creates a `UserShareRequestBodyUserCriteria` object with the given user IDs. + * + * @param userIds The list of user IDs to be included in the criteria. + * @return A `UserShareRequestBodyUserCriteria` object containing the specified user IDs. + */ + private UserShareRequestBodyUserCriteria getUserCriteriaForBaseUserSharing(List userIds) { UserShareRequestBodyUserCriteria criteria = new UserShareRequestBodyUserCriteria(); - criteria.setUserIds(Collections.singletonList(rootOrgUserId)); + criteria.setUserIds(userIds); return criteria; } + /** + * Converts a map of organization details into a list of `UserShareRequestBodyOrganizations` objects. + * + * @param organizations A map where the key is the organization name and the value is a map of organization details. + * @return A list of `UserShareRequestBodyOrganizations` objects. + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are predefined + * in the test data providers. + *

+ */ + @SuppressWarnings("unchecked") + private List getOrganizationsForSelectiveUserSharing(Map> organizations) { + + List orgs = new ArrayList<>(); + + for (Map.Entry> entry : organizations.entrySet()) { + + Map orgDetails = entry.getValue(); + + UserShareRequestBodyOrganizations org = new UserShareRequestBodyOrganizations(); + org.setOrgId((String) orgDetails.get(MAP_KEY_ORG_DETAILS_ORG_ID)); + org.setPolicy((UserShareRequestBodyOrganizations.PolicyEnum) orgDetails.get(MAP_KEY_ORG_DETAILS_POLICY)); + org.setRoles((List) orgDetails.get(MAP_KEY_ORG_DETAILS_ROLES)); + + orgs.add(org); + } + return orgs; + } + + // Test cases builders for selective user sharing. + + private Map> setOrganizationsForSelectiveUserSharingTestCase1() { + + Map> organizations = new HashMap<>(); + + // Organization 1 + Map org1 = new HashMap<>(); + org1.put(MAP_KEY_ORG_DETAILS_ORG_ID, l1Org1Id); + org1.put(MAP_KEY_ORG_DETAILS_ORG_NAME, L1_ORG_1_NAME); + org1.put(MAP_KEY_ORG_DETAILS_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_ORG_DETAILS_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + organizations.put(L1_ORG_1_NAME, org1); + + // Organization 2 + Map org2 = new HashMap<>(); + org2.put(MAP_KEY_ORG_DETAILS_ORG_ID, l1Org2Id); + org2.put(MAP_KEY_ORG_DETAILS_ORG_NAME, L1_ORG_2_NAME); + org2.put(MAP_KEY_ORG_DETAILS_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); + org2.put(MAP_KEY_ORG_DETAILS_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, SUPER_ORG, ORGANIZATION_AUDIENCE))); + + organizations.put(L1_ORG_2_NAME, org2); + + // Organization 3 + Map org3 = new HashMap<>(); + org3.put(MAP_KEY_ORG_DETAILS_ORG_ID, l1Org3Id); + org3.put(MAP_KEY_ORG_DETAILS_ORG_NAME, L1_ORG_3_NAME); + org3.put(MAP_KEY_ORG_DETAILS_POLICY, SELECTED_ORG_ONLY); + org3.put(MAP_KEY_ORG_DETAILS_ROLES, Collections.emptyList()); + + organizations.put(L1_ORG_3_NAME, org3); + + return organizations; + } + + private Map setExpectedResultsForSelectiveUserSharingTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_COUNT, 7); + expectedResults.put(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l2Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); + + expectedResults.put(MAP_KEY_ORG_DETAILS_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + // Helper Methods. + private RoleWithAudience createRoleWithAudience(String roleName, String display, String type) { RoleWithAudienceAudience audience = new RoleWithAudienceAudience(); @@ -271,10 +398,18 @@ private RoleWithAudience createRoleWithAudience(String roleName, String display, return roleWithAudience; } + private String getSharedOrgsRolesRef(String userId, String orgId) { + + return "/api/server/v1" + USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH + "?orgId=" + orgId; + } + + // Setup and cleanup methods. + private void setupOrganizations() throws Exception { l1Org1Id = orgMgtRestClient.addOrganization(L1_ORG_1_NAME); l1Org2Id = orgMgtRestClient.addOrganization(L1_ORG_2_NAME); + l1Org3Id = orgMgtRestClient.addOrganization(L1_ORG_3_NAME); l2Org1Id = orgMgtRestClient.addSubOrganization(L2_ORG_1_NAME, l1Org1Id); l2Org2Id = orgMgtRestClient.addSubOrganization(L2_ORG_2_NAME, l1Org1Id); l2Org3Id = orgMgtRestClient.addSubOrganization(L2_ORG_3_NAME, l1Org2Id); @@ -340,16 +475,19 @@ private void createApp1RolesWithAppAudience(String app1Id) throws IOException { private void setupUsers() throws Exception { - UserObject rootOrgUser = createUserObject(ROOT_ORG_USERNAME, ROOT_ORG_NAME); - rootOrgUserId = scim2RestClient.createUser(rootOrgUser); - - UserObject l1Org1User = createUserObject(L1_ORG_1_USERNAME, L1_ORG_1_NAME); - l1Org1UserId = scim2RestClient.createSubOrgUser(l1Org1User, l1Org1SwitchToken); - } - - private String getSharedOrgsRolesRef(String userId, String orgId) { + UserObject rootOrgUser1 = createUserObject(ROOT_ORG_USER_1_USERNAME, ROOT_ORG_NAME); + rootOrgUser1Id = scim2RestClient.createUser(rootOrgUser1); + UserObject rootOrgUser2 = createUserObject(ROOT_ORG_USER_2_USERNAME, ROOT_ORG_NAME); + rootOrgUser2Id = scim2RestClient.createUser(rootOrgUser2); + UserObject rootOrgUser3 = createUserObject(ROOT_ORG_USER_3_USERNAME, ROOT_ORG_NAME); + rootOrgUser3Id = scim2RestClient.createUser(rootOrgUser3); - return "/api/server/v1" + USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH + "?orgId=" + orgId; + UserObject l1Org1User1 = createUserObject(L1_ORG_1_USER_1_USERNAME, L1_ORG_1_NAME); + l1Org1User1Id = scim2RestClient.createSubOrgUser(l1Org1User1, l1Org1SwitchToken); + UserObject l1Org1User2 = createUserObject(L1_ORG_1_USER_2_USERNAME, L1_ORG_1_NAME); + l1Org1User2Id = scim2RestClient.createSubOrgUser(l1Org1User2, l1Org1SwitchToken); + UserObject l1Org1User3 = createUserObject(L1_ORG_1_USER_3_USERNAME, L1_ORG_1_NAME); + l1Org1User3Id = scim2RestClient.createSubOrgUser(l1Org1User3, l1Org1SwitchToken); } private void deleteUserIfExists(String userId) throws Exception { @@ -394,245 +532,47 @@ private void deleteOrganizationIfExists(String orgId) throws Exception { } } - private void closeRestClients() throws IOException { + private void cleanUpUsers() throws Exception { - oAuth2RestClient.closeHttpClient(); - scim2RestClient.closeHttpClient(); - orgMgtRestClient.closeHttpClient(); + deleteUserIfExists(rootOrgUser1Id); + deleteUserIfExists(rootOrgUser2Id); + deleteUserIfExists(rootOrgUser3Id); + deleteSubOrgUserIfExists(l1Org1User1Id, l1Org1SwitchToken); + deleteSubOrgUserIfExists(l1Org1User2Id, l1Org1SwitchToken); + deleteSubOrgUserIfExists(l1Org1User3Id, l1Org1SwitchToken); } + private void cleanUpRoles() throws Exception { - - @DataProvider(name = "selectiveSharingPoliciesWithRoles") - public Object[][] selectiveSharingPoliciesWithRoles() { - return new Object[][]{ - createTestCase(UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY, - new String[]{l1Org1Id}, - new String[]{L1_ORG_1_NAME}, - new RoleWithAudience[]{createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE)}, - createExpectedRoles( - L1_ORG_1_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE) - ), - new String[]{l1Org2Id}, - new String[]{L1_ORG_2_NAME}, - new RoleWithAudience[]{createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE)}, - createExpectedRoles( - L1_ORG_2_NAME, createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE) - ) - ), - createTestCase(UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY, - new String[]{l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id}, - new String[]{L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME}, - new RoleWithAudience[]{ - createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_1, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE) - }, - createExpectedRoles( - L1_ORG_1_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - L2_ORG_1_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - L2_ORG_2_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - L3_ORG_1_NAME, createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE) - ), - new String[]{l1Org2Id, l2Org3Id}, - new String[]{L1_ORG_2_NAME, L2_ORG_3_NAME}, - new RoleWithAudience[]{ - createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE) - }, - createExpectedRoles( - L1_ORG_2_NAME, createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE), - L2_ORG_3_NAME, createRoleWithAudience(ORG_ROLE_2, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE) - ) - ), - createTestCase(UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN, - new String[]{l1Org1Id, l2Org1Id, l2Org2Id}, - new String[]{L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME}, - new RoleWithAudience[]{createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE)}, - createExpectedRoles( - L1_ORG_1_NAME, createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE), - L2_ORG_1_NAME, createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE), - L2_ORG_2_NAME, createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE) - ), - new String[]{l1Org2Id, l2Org3Id}, - new String[]{L1_ORG_2_NAME, L2_ORG_3_NAME}, - new RoleWithAudience[]{}, - createExpectedRoles( - L1_ORG_2_NAME, new RoleWithAudience[]{}, - L2_ORG_3_NAME, new RoleWithAudience[]{} - ) - ) - }; + deleteRoleIfExists(appRole1Id); + deleteRoleIfExists(appRole2Id); + deleteRoleIfExists(appRole3Id); + deleteRoleIfExists(orgRole1Id); + deleteRoleIfExists(orgRole2Id); + deleteRoleIfExists(orgRole3Id); } + private void cleanUpApplications() throws Exception { - @Test(dataProvider = "selectiveSharingPoliciesWithRoles") - public void testSelectiveUserSharingWithRoles( - UserShareRequestBodyOrganizations.PolicyEnum policy, - String[] expectedOrgIdsForL1Org1, String[] expectedOrgNamesForL1Org1, RoleWithAudience[] rolesForL1Org1, - Map expectedRolesForL1Org1, - String[] expectedOrgIdsForL1Org2, String[] expectedOrgNamesForL1Org2, RoleWithAudience[] rolesForL1Org2, - Map expectedRolesForL1Org2) throws Exception { - - UserShareRequestBody requestBody = new UserShareRequestBody() - .userCriteria(getUserCriteria()) - .organizations(Arrays.asList( - new UserShareRequestBodyOrganizations() - .orgId(l1Org1Id) - .policy(policy) - .roles(Arrays.asList(rolesForL1Org1)), - new UserShareRequestBodyOrganizations() - .orgId(l1Org2Id) - .policy(policy) - .roles(Arrays.asList(rolesForL1Org2)) - )); - - Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBody)); - - response.then() - .log().ifValidationFails() - .assertThat() - .statusCode(HttpStatus.SC_ACCEPTED) - .body("status", equalTo("Processing")) - .body("details", equalTo("User sharing process triggered successfully.")); - - // Validate shared organizations - validateSharedOrganizations(expectedOrgIdsForL1Org1, expectedOrgNamesForL1Org1, expectedOrgIdsForL1Org2, expectedOrgNamesForL1Org2); - - // Validate roles in shared organizations - validateSharedRoles(expectedOrgIdsForL1Org1, expectedRolesForL1Org1); - validateSharedRoles(expectedOrgIdsForL1Org2, expectedRolesForL1Org2); - } - - private void validateSharedOrganizations(String[] expectedOrgIds1, String[] expectedOrgNames1, String[] expectedOrgIds2, String[] expectedOrgNames2) - throws Exception { - testGetSharedOrganizationsWithAllWithoutPagination(expectedOrgIds1.length + expectedOrgIds2.length, - Stream.concat(Arrays.stream(expectedOrgIds1), Arrays.stream(expectedOrgIds2)).toArray(String[]::new), - Stream.concat(Arrays.stream(expectedOrgNames1), Arrays.stream(expectedOrgNames2)).toArray(String[]::new)); + deleteApplicationIfExists(application1WithAppAudienceRoles.getId()); + deleteApplicationIfExists(application2WithOrgAudienceRoles.getId()); } - private void validateSharedRoles(String[] expectedOrgIds, Map expectedRoles) { - for (String orgId : expectedOrgIds) { - String orgName = getOrgNameById(orgId); - testGetSharedRolesForOrgWithRolesWithoutPagination(orgId, orgName, expectedRoles.get(orgName)); - } - } + private void cleanUpOrganizations() throws Exception { - private Object[] createTestCase(UserShareRequestBodyOrganizations.PolicyEnum policy, - String[] orgIds1, String[] orgNames1, RoleWithAudience[] roles1, Map expectedRoles1, - String[] orgIds2, String[] orgNames2, RoleWithAudience[] roles2, Map expectedRoles2) { - return new Object[]{policy, orgIds1, orgNames1, roles1, expectedRoles1, orgIds2, orgNames2, roles2, expectedRoles2}; + deleteSubOrganizationIfExists(l3Org1Id, l2Org1Id); + deleteSubOrganizationIfExists(l2Org3Id, l1Org2Id); + deleteSubOrganizationIfExists(l2Org2Id, l1Org1Id); + deleteSubOrganizationIfExists(l2Org1Id, l1Org1Id); + deleteOrganizationIfExists(l1Org3Id); + deleteOrganizationIfExists(l1Org2Id); + deleteOrganizationIfExists(l1Org1Id); } - private Map createExpectedRoles(Object... data) { - Map roleMap = new HashMap<>(); - for (int i = 0; i < data.length; i += 2) { - roleMap.put((String) data[i], new RoleWithAudience[]{(RoleWithAudience) data[i + 1]}); - } - return roleMap; - } - -// @Test(dataProvider = "selectiveSharingPoliciesWithRoles") -// public void testSelectiveUserSharingWithRoles( -// UserShareRequestBodyOrganizations.PolicyEnum policy, -// String[] expectedOrgIdsForL1Org1, String[] expectedOrgNamesForL1Org1, RoleWithAudience[] rolesForL1Org1, -// Map expectedRolesForL1Org1, -// String[] expectedOrgIdsForL1Org2, String[] expectedOrgNamesForL1Org2, RoleWithAudience[] rolesForL1Org2, -// Map expectedRolesForL1Org2) -// throws Exception { -// -// UserShareRequestBody requestBody = new UserShareRequestBody() -// .userCriteria(getUserCriteria()) -// .organizations(Arrays.asList( -// new UserShareRequestBodyOrganizations() -// .orgId(l1Org1Id) -// .policy(policy) -// .roles(Arrays.asList(rolesForL1Org1)), -// new UserShareRequestBodyOrganizations() -// .orgId(l1Org2Id) -// .policy(policy) -// .roles(Arrays.asList(rolesForL1Org2)) -// )); -// -// Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBody)); -// -// response.then() -// .log().ifValidationFails() -// .assertThat() -// .statusCode(HttpStatus.SC_ACCEPTED) -// .body("status", equalTo("Processing")) -// .body("details", equalTo("User sharing process triggered successfully.")); -// -// Thread.sleep(5000); // Wait for sharing process to complete. -// -// // Validate shared organizations -// testGetSharedOrganizationsWithAllWithoutPagination(expectedOrgIdsForL1Org1.length+expectedOrgIdsForL1Org2.length, -// Stream.concat(Arrays.stream(expectedOrgIdsForL1Org1), -// Arrays.stream(expectedOrgIdsForL1Org2)) -// .toArray(String[]::new), -// Stream.concat(Arrays.stream(expectedOrgNamesForL1Org1), -// Arrays.stream(expectedOrgNamesForL1Org2)) -// .toArray(String[]::new)); -// -// // Validate roles in shared organizations -// for (String orgId : expectedOrgIdsForL1Org1) { -// String orgName = getOrgNameById(orgId); -// testGetSharedRolesForOrgWithRolesWithoutPagination(orgId, orgName, -// expectedRolesForL1Org1.get(orgName)); -// } -// for (String orgId : expectedOrgIdsForL1Org2) { -// String orgName = getOrgNameById(orgId); -// testGetSharedRolesForOrgWithRolesWithoutPagination(orgId, orgName, -// expectedRolesForL1Org2.get(orgName)); -// } -// } - - public void testGetSharedRolesForOrgWithRolesWithoutPagination(String orgId, String orgName, RoleWithAudience[] expectedRoles) { - - Response response = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + rootOrgUserId + SHARED_ROLES_PATH, - Collections.singletonMap("orgId", orgId)); - - response.then() - .log().ifValidationFails() - .assertThat() - .statusCode(HttpStatus.SC_OK) - .body("links.size()", equalTo(1)) - .body("links[0].isEmpty()", equalTo(true)) - .body("roles", notNullValue()) - .body("roles.size()", equalTo(expectedRoles.length)); - - if (expectedRoles.length > 0) { - response.then() - .body("roles.displayName", hasItems( - Arrays.stream(expectedRoles) - .map(RoleWithAudience::getDisplayName) - .toArray(String[]::new))) - .body("roles.audience.display", hasItems( - Arrays.stream(expectedRoles) - .map(role -> role.getAudience().getDisplay()) - .toArray(String[]::new)))// Now directly matching expected audiences - .body("roles.audience.type", hasItems( - Arrays.stream(expectedRoles) - .map(role -> role.getAudience().getType()) - .toArray(String[]::new))); - } - } + private void closeRestClients() throws IOException { - private String getOrgNameById(String orgId) { - if (orgId.equals(l1Org1Id)) { - return L1_ORG_1_NAME; - } else if (orgId.equals(l1Org2Id)) { - return L1_ORG_2_NAME; - } else if (orgId.equals(l2Org1Id)) { - return L2_ORG_1_NAME; - } else if (orgId.equals(l2Org2Id)) { - return L2_ORG_2_NAME; - } else if (orgId.equals(l2Org3Id)) { - return L2_ORG_3_NAME; - } else if (orgId.equals(l3Org1Id)) { - return L3_ORG_1_NAME; - } - return null; + oAuth2RestClient.closeHttpClient(); + scim2RestClient.closeHttpClient(); + orgMgtRestClient.closeHttpClient(); } - - } From 68f32b95675c3e607014b3fa3c9e662b12b55629 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Thu, 27 Feb 2025 02:21:11 +0530 Subject: [PATCH 03/39] general user share with 4 test cases and one more test case for selective user share. --- .../management/v1/UserSharingBaseTest.java | 20 +- .../management/v1/UserSharingSuccessTest.java | 318 ++++++++++++++++-- 2 files changed, 300 insertions(+), 38 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 114981900a5..e26a7239ae1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -136,14 +136,18 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String ROLES_CLAIM_URI = "http://wso2.org/claims/roles"; protected static final String GROUPS_CLAIM_URI = "http://wso2.org/claims/groups"; - protected static final String MAP_KEY_ORG_DETAILS_ORG_ID = "orgId"; - protected static final String MAP_KEY_ORG_DETAILS_ORG_NAME = "orgName"; - protected static final String MAP_KEY_ORG_DETAILS_POLICY = "policy"; - protected static final String MAP_KEY_ORG_DETAILS_ROLES = "roles"; - protected static final String MAP_KEY_ORG_DETAILS_EXPECTED_ORG_COUNT = "expectedOrgCount"; - protected static final String MAP_KEY_ORG_DETAILS_EXPECTED_ORG_IDS = "expectedOrgIds"; - protected static final String MAP_KEY_ORG_DETAILS_EXPECTED_ORG_NAMES = "expectedOrgNames"; - protected static final String MAP_KEY_ORG_DETAILS_EXPECTED_ROLES_PER_EXPECTED_ORG = "expectedRolesPerExpectedOrg"; + protected static final String MAP_KEY_SELECTIVE_ORG_ID = "orgId"; + protected static final String MAP_KEY_SELECTIVE_ORG_NAME = "orgName"; + protected static final String MAP_KEY_SELECTIVE_POLICY = "selectivePolicy"; + protected static final String MAP_KEY_SELECTIVE_ROLES = "selectiveRoles"; + + protected static final String MAP_KEY_GENERAL_POLICY = "generalPolicy"; + protected static final String MAP_KEY_GENERAL_ROLES = "generalRoles"; + + protected static final String MAP_KEY_EXPECTED_ORG_COUNT = "expectedOrgCount"; + protected static final String MAP_KEY_EXPECTED_ORG_IDS = "expectedOrgIds"; + protected static final String MAP_KEY_EXPECTED_ORG_NAMES = "expectedOrgNames"; + protected static final String MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG = "expectedRolesPerExpectedOrg"; protected static String swaggerDefinition; protected OAuth2RestClient oAuth2RestClient; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index d16a8a73fe7..309fac03bd1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -37,6 +37,7 @@ import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyUserCriteria; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; @@ -55,8 +56,14 @@ import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.notNullValue; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_CHILDREN_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_AND_FUTURE_ORGS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_AND_FUTURE_ORGS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_ORGS_ONLY; /** * Tests for successful cases of the User Sharing REST APIs. @@ -157,15 +164,20 @@ public Object[][] selectiveSharingPoliciesWithRoles() { Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingTestCase1(); + List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); + Map> organizationsForTestCase2 = setOrganizationsForSelectiveUserSharingTestCase2(); + Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserSharingTestCase2(); + return new Object[][] { - { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1 } + { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1 }, + { userIdsForTestCase2, organizationsForTestCase2, expectedResultsForTestCase2 } }; } @Test(dataProvider = "selectiveSharingPoliciesWithRoles") public void testSelectiveUserSharingWithRoles(List userIds, Map> organizations, - Map expectedResults) { + Map expectedResults) throws InterruptedException { UserShareRequestBody requestBody = new UserShareRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) @@ -180,6 +192,7 @@ public void testSelectiveUserSharingWithRoles(List userIds, .body("status", equalTo("Processing")) .body("details", equalTo("User sharing process triggered successfully.")); + Thread.sleep(5000); for (String userId : userIds) { validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); } @@ -187,16 +200,68 @@ public void testSelectiveUserSharingWithRoles(List userIds, // General User Sharing. + @DataProvider(name = "generalSharingPoliciesWithRoles") + public Object[][] generalSharingPoliciesWithRoles() { + + List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); + Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); + Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); + + List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); + Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); + Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); + + List userIdsForTestCase3 = Collections.singletonList(rootOrgUser2Id); + Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingTestCase3(); + Map expectedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingTestCase3(); + + List userIdsForTestCase4 = Arrays.asList(rootOrgUser3Id, rootOrgUser2Id); + Map policyWithRolesForTestCase4 = setPolicyWithRolesForGeneralUserSharingTestCase4(); + Map expectedResultsForTestCase4 = setExpectedResultsForGeneralUserSharingTestCase4(); + + return new Object[][] { + { userIdsForTestCase1, policyWithRolesForTestCase1, expectedResultsForTestCase1 }, + { userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2 }, + { userIdsForTestCase3, policyWithRolesForTestCase3, expectedResultsForTestCase3 }, + { userIdsForTestCase4, policyWithRolesForTestCase4, expectedResultsForTestCase4 } + }; + } + + @Test(dataProvider = "generalSharingPoliciesWithRoles") + public void testGeneralUserSharingWithRoles(List userIds, + Map policyWithRoles, + Map expectedResults) throws InterruptedException { + + UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() + .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) + .policy(getPolicyEnumForGeneralUserSharing(policyWithRoles)) + .roles(getRolesForGeneralUserSharing(policyWithRoles)); + + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body("status", equalTo("Processing")) + .body("details", equalTo("User sharing process triggered successfully.")); + + Thread.sleep(5000); + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + } + } /** * Validate that the user has been shared to the expected organizations with the expected roles. * * @param userId The ID of the user to validate. * @param expectedResults A map containing the expected results, including the expected organization count, - * expected organization IDs, expected organization names, and expected roles per organization. + * expected organization IDs, expected organization names, and expected roles per + * organization. *

- * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are predefined - * in the test data providers. + * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. *

*/ @SuppressWarnings("unchecked") @@ -204,12 +269,12 @@ private void validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(String use testGetSharedOrganizations( userId, - (int) expectedResults.get(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_COUNT), - (List) expectedResults.get(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_IDS), - (List) expectedResults.get(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_NAMES) + (int) expectedResults.get(MAP_KEY_EXPECTED_ORG_COUNT), + (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_IDS), + (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_NAMES) ); - Map> expectedRolesPerExpectedOrg = (Map>) expectedResults.get(MAP_KEY_ORG_DETAILS_EXPECTED_ROLES_PER_EXPECTED_ORG); + Map> expectedRolesPerExpectedOrg = (Map>) expectedResults.get(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG); for (Map.Entry> entry : expectedRolesPerExpectedOrg.entrySet()) { testGetSharedRolesForOrg(userId, entry.getKey(), entry.getValue()); } @@ -302,8 +367,8 @@ private UserShareRequestBodyUserCriteria getUserCriteriaForBaseUserSharing(List< * @param organizations A map where the key is the organization name and the value is a map of organization details. * @return A list of `UserShareRequestBodyOrganizations` objects. *

- * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are predefined - * in the test data providers. + * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. *

*/ @SuppressWarnings("unchecked") @@ -316,15 +381,42 @@ private List getOrganizationsForSelectiveUser Map orgDetails = entry.getValue(); UserShareRequestBodyOrganizations org = new UserShareRequestBodyOrganizations(); - org.setOrgId((String) orgDetails.get(MAP_KEY_ORG_DETAILS_ORG_ID)); - org.setPolicy((UserShareRequestBodyOrganizations.PolicyEnum) orgDetails.get(MAP_KEY_ORG_DETAILS_POLICY)); - org.setRoles((List) orgDetails.get(MAP_KEY_ORG_DETAILS_ROLES)); + org.setOrgId((String) orgDetails.get(MAP_KEY_SELECTIVE_ORG_ID)); + org.setPolicy((UserShareRequestBodyOrganizations.PolicyEnum) orgDetails.get(MAP_KEY_SELECTIVE_POLICY)); + org.setRoles((List) orgDetails.get(MAP_KEY_SELECTIVE_ROLES)); orgs.add(org); } return orgs; } + /** + * Retrieves the policy enum for general user sharing from the provided map. + * + * @param policyWithRoles A map containing the policy and roles for general user sharing. + * @return The policy enum for general user sharing. + */ + private UserShareWithAllRequestBody.PolicyEnum getPolicyEnumForGeneralUserSharing(Map policyWithRoles) { + + return (UserShareWithAllRequestBody.PolicyEnum)policyWithRoles.get(MAP_KEY_GENERAL_POLICY) ; + } + + /** + * Retrieves the roles for general user sharing from the provided map. + * + * @param policyWithRoles A map containing the policy and roles for general user sharing. + * @return A list of `RoleWithAudience` objects representing the roles for general user sharing. + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. + *

+ */ + @SuppressWarnings("unchecked") + private List getRolesForGeneralUserSharing(Map policyWithRoles) { + + return (List) policyWithRoles.get(MAP_KEY_GENERAL_ROLES); + } + // Test cases builders for selective user sharing. private Map> setOrganizationsForSelectiveUserSharingTestCase1() { @@ -333,28 +425,31 @@ private Map> setOrganizationsForSelectiveUserSharing // Organization 1 Map org1 = new HashMap<>(); - org1.put(MAP_KEY_ORG_DETAILS_ORG_ID, l1Org1Id); - org1.put(MAP_KEY_ORG_DETAILS_ORG_NAME, L1_ORG_1_NAME); - org1.put(MAP_KEY_ORG_DETAILS_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); - org1.put(MAP_KEY_ORG_DETAILS_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + org1.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org1Id); + org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, + APPLICATION_AUDIENCE))); organizations.put(L1_ORG_1_NAME, org1); // Organization 2 Map org2 = new HashMap<>(); - org2.put(MAP_KEY_ORG_DETAILS_ORG_ID, l1Org2Id); - org2.put(MAP_KEY_ORG_DETAILS_ORG_NAME, L1_ORG_2_NAME); - org2.put(MAP_KEY_ORG_DETAILS_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); - org2.put(MAP_KEY_ORG_DETAILS_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, SUPER_ORG, ORGANIZATION_AUDIENCE))); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org2Id); + org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); + org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, + APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, SUPER_ORG, ORGANIZATION_AUDIENCE))); organizations.put(L1_ORG_2_NAME, org2); // Organization 3 Map org3 = new HashMap<>(); - org3.put(MAP_KEY_ORG_DETAILS_ORG_ID, l1Org3Id); - org3.put(MAP_KEY_ORG_DETAILS_ORG_NAME, L1_ORG_3_NAME); - org3.put(MAP_KEY_ORG_DETAILS_POLICY, SELECTED_ORG_ONLY); - org3.put(MAP_KEY_ORG_DETAILS_ROLES, Collections.emptyList()); + org3.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org3Id); + org3.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_3_NAME); + org3.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_ONLY); + org3.put(MAP_KEY_SELECTIVE_ROLES, Collections.emptyList()); organizations.put(L1_ORG_3_NAME, org3); @@ -365,9 +460,9 @@ private Map setExpectedResultsForSelectiveUserSharingTestCase1() Map expectedResults = new HashMap<>(); - expectedResults.put(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); - expectedResults.put(MAP_KEY_ORG_DETAILS_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); @@ -378,7 +473,170 @@ private Map setExpectedResultsForSelectiveUserSharingTestCase1() expectedRolesPerExpectedOrg.put(l2Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); - expectedResults.put(MAP_KEY_ORG_DETAILS_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map> setOrganizationsForSelectiveUserSharingTestCase2() { + + Map> organizations = new HashMap<>(); + + // Organization 2 + Map org2 = new HashMap<>(); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org2Id); + org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); + org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(ORG_ROLE_1, SUPER_ORG, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, SUPER_ORG, ORGANIZATION_AUDIENCE))); + + organizations.put(L1_ORG_2_NAME, org2); + + // Organization 3 + Map org3 = new HashMap<>(); + org3.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org3Id); + org3.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_3_NAME); + org3.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN); + org3.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); + + organizations.put(L1_ORG_3_NAME, org3); + + return organizations; + } + + private Map setExpectedResultsForSelectiveUserSharingTestCase2() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l2Org3Id, Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setPolicyWithRolesForGeneralUserSharingTestCase1() { + + Map policyWithRoles = new HashMap<>(); + + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, ALL_EXISTING_ORGS_ONLY); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + return policyWithRoles; + } + + private Map setExpectedResultsForGeneralUserSharingTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setPolicyWithRolesForGeneralUserSharingTestCase2() { + + Map policyWithRoles = new HashMap<>(); + + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, ALL_EXISTING_AND_FUTURE_ORGS); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.emptyList()); + + return policyWithRoles; + } + + private Map setExpectedResultsForGeneralUserSharingTestCase2() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setPolicyWithRolesForGeneralUserSharingTestCase3() { + + Map policyWithRoles = new HashMap<>(); + + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_ORGS_ONLY); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, SUPER_ORG, ORGANIZATION_AUDIENCE))); + + return policyWithRoles; + } + + private Map setExpectedResultsForGeneralUserSharingTestCase3() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l1Org2Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setPolicyWithRolesForGeneralUserSharingTestCase4() { + + Map policyWithRoles = new HashMap<>(); + + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_AND_FUTURE_ORGS); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, SUPER_ORG, ORGANIZATION_AUDIENCE))); + + return policyWithRoles; + } + + private Map setExpectedResultsForGeneralUserSharingTestCase4() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l1Org2Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l1Org1Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); return expectedResults; } From ecb76840f8b9c42e8552a376e706398aa9e6cce9 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Thu, 27 Feb 2025 12:18:16 +0530 Subject: [PATCH 04/39] general user unsharing. --- .../management/v1/UserSharingSuccessTest.java | 84 +++++++++++++++++-- 1 file changed, 76 insertions(+), 8 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 309fac03bd1..f2b157928aa 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -38,6 +38,8 @@ import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyUserCriteria; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareRequestBodyUserCriteria; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareWithAllRequestBody; import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; @@ -157,8 +159,8 @@ public static Object[][] restAPIUserConfigProvider() { // Selective User Sharing. - @DataProvider(name = "selectiveSharingPoliciesWithRoles") - public Object[][] selectiveSharingPoliciesWithRoles() { + @DataProvider(name = "selectiveUserSharingDataProvider") + public Object[][] selectiveUserSharingDataProvider() { List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingTestCase1(); @@ -174,8 +176,8 @@ public Object[][] selectiveSharingPoliciesWithRoles() { }; } - @Test(dataProvider = "selectiveSharingPoliciesWithRoles") - public void testSelectiveUserSharingWithRoles(List userIds, + @Test(dataProvider = "selectiveUserSharingDataProvider") + public void testSelectiveUserSharing(List userIds, Map> organizations, Map expectedResults) throws InterruptedException { @@ -200,8 +202,8 @@ public void testSelectiveUserSharingWithRoles(List userIds, // General User Sharing. - @DataProvider(name = "generalSharingPoliciesWithRoles") - public Object[][] generalSharingPoliciesWithRoles() { + @DataProvider(name = "generalUserSharingDataProvider") + public Object[][] generalUserSharingDataProvider() { List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); @@ -227,8 +229,8 @@ public Object[][] generalSharingPoliciesWithRoles() { }; } - @Test(dataProvider = "generalSharingPoliciesWithRoles") - public void testGeneralUserSharingWithRoles(List userIds, + @Test(dataProvider = "generalUserSharingDataProvider") + public void testGeneralUserSharing(List userIds, Map policyWithRoles, Map expectedResults) throws InterruptedException { @@ -252,6 +254,45 @@ public void testGeneralUserSharingWithRoles(List userIds, } } + // General User Unsharing. + + @DataProvider(name = "generalUserUnsharingDataProvider") + public Object[][] generalUserUnsharingDataProvider() { + + List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); + List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id); + List userIdsForTestCase3 = Collections.emptyList(); + Map expectedResultsForTestCase = setExpectedResultsForGeneralUserUnsharingTestCase1(); + + return new Object[][] { + { userIdsForTestCase1, expectedResultsForTestCase}, + { userIdsForTestCase2, expectedResultsForTestCase}, + { userIdsForTestCase3, expectedResultsForTestCase} + }; + } + + @Test(dataProvider = "generalUserUnsharingDataProvider") + public void testGeneralUserUnsharing(List userIds, + Map expectedResults) throws InterruptedException { + + UserUnshareWithAllRequestBody requestBody = new UserUnshareWithAllRequestBody() + .userCriteria(getUserCriteriaForBaseUserUnsharing(userIds)); + + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + UNSHARE_WITH_ALL_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body("status", equalTo("Processing")) + .body("details", equalTo("User unsharing process triggered successfully.")); + + Thread.sleep(5000); + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + } + } + /** * Validate that the user has been shared to the expected organizations with the expected roles. * @@ -361,6 +402,19 @@ private UserShareRequestBodyUserCriteria getUserCriteriaForBaseUserSharing(List< return criteria; } + /** + * Creates a `UserUnshareRequestBodyUserCriteria` object with the given user IDs. + * + * @param userIds The list of user IDs to be included in the criteria. + * @return A `UserUnshareRequestBodyUserCriteria` object containing the specified user IDs. + */ + private UserUnshareRequestBodyUserCriteria getUserCriteriaForBaseUserUnsharing(List userIds) { + + UserUnshareRequestBodyUserCriteria criteria = new UserUnshareRequestBodyUserCriteria(); + criteria.setUserIds(userIds); + return criteria; + } + /** * Converts a map of organization details into a list of `UserShareRequestBodyOrganizations` objects. * @@ -641,6 +695,20 @@ private Map setExpectedResultsForGeneralUserSharingTestCase4() { return expectedResults; } + private Map setExpectedResultsForGeneralUserUnsharingTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + // Helper Methods. private RoleWithAudience createRoleWithAudience(String roleName, String display, String type) { From 295f4a2b258586d36b146ca90c94038e03734445 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Thu, 27 Feb 2025 15:04:41 +0530 Subject: [PATCH 05/39] selective user unsharing with 4 test cases. --- .../management/v1/UserSharingSuccessTest.java | 141 +++++++++++++++++- 1 file changed, 140 insertions(+), 1 deletion(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index f2b157928aa..268b130165d 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -38,6 +38,7 @@ import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyUserCriteria; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareRequestBodyUserCriteria; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareWithAllRequestBody; import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; @@ -260,7 +261,7 @@ public void testGeneralUserSharing(List userIds, public Object[][] generalUserUnsharingDataProvider() { List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); - List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id); + List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); List userIdsForTestCase3 = Collections.emptyList(); Map expectedResultsForTestCase = setExpectedResultsForGeneralUserUnsharingTestCase1(); @@ -293,6 +294,73 @@ public void testGeneralUserUnsharing(List userIds, } } + // Selective User Unsharing. + + @DataProvider(name = "selectiveUserUnsharingDataProvider") + public Object[][] selectiveUserUnsharingDataProvider() { + + + List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); + Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); + Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); + List removingOrgIdsForTestCase1 = Arrays.asList(l1Org1Id, l1Org2Id); + Map expectedUnsharedResultsForTestCase1 = setExpectedUnsharedResultsForGeneralUserSharingTestCase1(); + + List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); + Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); + Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); + List removingOrgIdsForTestCase2 = Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id); + Map expectedUnsharedResultsForTestCase2 = setExpectedUnsharedResultsForGeneralUserSharingTestCase2(); + + List userIdsForTestCase3 = Collections.singletonList(rootOrgUser2Id); + Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingTestCase3(); + Map expectedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingTestCase3(); + List removingOrgIdsForTestCase3 = Arrays.asList(l1Org1Id, l1Org3Id); + Map expectedUnsharedResultsForTestCase3 = setExpectedUnsharedResultsForGeneralUserSharingTestCase3(); + + List userIdsForTestCase4 = Arrays.asList(rootOrgUser3Id, rootOrgUser2Id); + Map policyWithRolesForTestCase4 = setPolicyWithRolesForGeneralUserSharingTestCase4(); + Map expectedResultsForTestCase4 = setExpectedResultsForGeneralUserSharingTestCase4(); + List removingOrgIdsForTestCase4 = Collections.singletonList(l1Org1Id); + Map expectedUnsharedResultsForTestCase4 = setExpectedUnsharedResultsForGeneralUserSharingTestCase4(); + + return new Object[][] { + { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, removingOrgIdsForTestCase1, expectedUnsharedResultsForTestCase1}, + { userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2, removingOrgIdsForTestCase2, expectedUnsharedResultsForTestCase2}, + { userIdsForTestCase3, policyWithRolesForTestCase3, expectedResultsForTestCase3, removingOrgIdsForTestCase3, expectedUnsharedResultsForTestCase3}, + { userIdsForTestCase4, policyWithRolesForTestCase4, expectedResultsForTestCase4, removingOrgIdsForTestCase4, expectedUnsharedResultsForTestCase4} + }; + } + + @Test(dataProvider = "selectiveUserUnsharingDataProvider") + public void testSelectiveUserUnsharing(List userIds, + Map policyWithRoles, + Map expectedSharedResults, + List removingOrgIds, + Map expectedUnsharedResults) throws InterruptedException { + + testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); + + UserUnshareRequestBody requestBody = new UserUnshareRequestBody() + .userCriteria(getUserCriteriaForBaseUserUnsharing(userIds)) + .organizations(removingOrgIds); + + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + UNSHARE_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body("status", equalTo("Processing")) + .body("details", equalTo("User unsharing process triggered successfully.")); + + Thread.sleep(5000); + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedUnsharedResults); + } + } + + /** * Validate that the user has been shared to the expected organizations with the expected roles. * @@ -709,6 +777,77 @@ private Map setExpectedResultsForGeneralUserUnsharingTestCase1() return expectedResults; } + private Map setExpectedUnsharedResultsForGeneralUserSharingTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 5); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l2Org1Id, l2Org2Id, l3Org1Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setExpectedUnsharedResultsForGeneralUserSharingTestCase2() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setExpectedUnsharedResultsForGeneralUserSharingTestCase3() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 1); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setExpectedUnsharedResultsForGeneralUserSharingTestCase4() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 2); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + // Helper Methods. private RoleWithAudience createRoleWithAudience(String roleName, String display, String type) { From 6a7cb11ae91be4ead3e3a9da48f854fa1ac0e9f4 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Thu, 27 Feb 2025 15:27:07 +0530 Subject: [PATCH 06/39] change order of the test cases based on general sharing policies. --- .../management/v1/UserSharingSuccessTest.java | 109 ++++++++++-------- 1 file changed, 58 insertions(+), 51 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 268b130165d..5eee0319491 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -206,19 +206,23 @@ public void testSelectiveUserSharing(List userIds, @DataProvider(name = "generalUserSharingDataProvider") public Object[][] generalUserSharingDataProvider() { + // ALL EXISTING List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); - List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); + // IMMEDIATE EXISTING AND FUTURE + List userIdsForTestCase2 = Arrays.asList(rootOrgUser3Id, rootOrgUser2Id); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); + // IMMEDIATE EXISTING List userIdsForTestCase3 = Collections.singletonList(rootOrgUser2Id); Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingTestCase3(); Map expectedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingTestCase3(); - List userIdsForTestCase4 = Arrays.asList(rootOrgUser3Id, rootOrgUser2Id); + // ALL EXISTING AND FUTURE + List userIdsForTestCase4 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); Map policyWithRolesForTestCase4 = setPolicyWithRolesForGeneralUserSharingTestCase4(); Map expectedResultsForTestCase4 = setExpectedResultsForGeneralUserSharingTestCase4(); @@ -299,36 +303,39 @@ public void testGeneralUserUnsharing(List userIds, @DataProvider(name = "selectiveUserUnsharingDataProvider") public Object[][] selectiveUserUnsharingDataProvider() { - + // ALL EXISTING List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); List removingOrgIdsForTestCase1 = Arrays.asList(l1Org1Id, l1Org2Id); Map expectedUnsharedResultsForTestCase1 = setExpectedUnsharedResultsForGeneralUserSharingTestCase1(); - List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); + // IMMEDIATE EXISTING AND FUTURE + List userIdsForTestCase2 = Arrays.asList(rootOrgUser3Id, rootOrgUser2Id); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); - Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); - List removingOrgIdsForTestCase2 = Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id); + Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); + List removingOrgIdsForTestCase2 = Collections.singletonList(l1Org1Id); Map expectedUnsharedResultsForTestCase2 = setExpectedUnsharedResultsForGeneralUserSharingTestCase2(); - List userIdsForTestCase3 = Collections.singletonList(rootOrgUser2Id); - Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingTestCase3(); - Map expectedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingTestCase3(); - List removingOrgIdsForTestCase3 = Arrays.asList(l1Org1Id, l1Org3Id); - Map expectedUnsharedResultsForTestCase3 = setExpectedUnsharedResultsForGeneralUserSharingTestCase3(); - - List userIdsForTestCase4 = Arrays.asList(rootOrgUser3Id, rootOrgUser2Id); - Map policyWithRolesForTestCase4 = setPolicyWithRolesForGeneralUserSharingTestCase4(); - Map expectedResultsForTestCase4 = setExpectedResultsForGeneralUserSharingTestCase4(); - List removingOrgIdsForTestCase4 = Collections.singletonList(l1Org1Id); - Map expectedUnsharedResultsForTestCase4 = setExpectedUnsharedResultsForGeneralUserSharingTestCase4(); +// // IMMEDIATE EXISTING +// List userIdsForTestCase3 = Collections.singletonList(rootOrgUser2Id); +// Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingTestCase3(); +// Map expectedSharedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingTestCase3(); +// List removingOrgIdsForTestCase3 = Arrays.asList(l1Org1Id, l1Org3Id); +// Map expectedUnsharedResultsForTestCase3 = setExpectedUnsharedResultsForGeneralUserSharingTestCase3(); +// +// // ALL EXISTING AND FUTURE +// List userIdsForTestCase4 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); +// Map policyWithRolesForTestCase4 = setPolicyWithRolesForGeneralUserSharingTestCase4(); +// Map expectedSharedResultsForTestCase4 = setExpectedResultsForGeneralUserSharingTestCase4(); +// List removingOrgIdsForTestCase4 = Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id); +// Map expectedUnsharedResultsForTestCase4 = setExpectedUnsharedResultsForGeneralUserSharingTestCase4(); return new Object[][] { { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, removingOrgIdsForTestCase1, expectedUnsharedResultsForTestCase1}, - { userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2, removingOrgIdsForTestCase2, expectedUnsharedResultsForTestCase2}, - { userIdsForTestCase3, policyWithRolesForTestCase3, expectedResultsForTestCase3, removingOrgIdsForTestCase3, expectedUnsharedResultsForTestCase3}, - { userIdsForTestCase4, policyWithRolesForTestCase4, expectedResultsForTestCase4, removingOrgIdsForTestCase4, expectedUnsharedResultsForTestCase4} + { userIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, removingOrgIdsForTestCase2, expectedUnsharedResultsForTestCase2} +// { userIdsForTestCase3, policyWithRolesForTestCase3, expectedSharedResultsForTestCase3, removingOrgIdsForTestCase3, expectedUnsharedResultsForTestCase3}, +// { userIdsForTestCase4, policyWithRolesForTestCase4, expectedSharedResultsForTestCase4, removingOrgIdsForTestCase4, expectedUnsharedResultsForTestCase4} }; } @@ -679,8 +686,8 @@ private Map setPolicyWithRolesForGeneralUserSharingTestCase2() { Map policyWithRoles = new HashMap<>(); - policyWithRoles.put(MAP_KEY_GENERAL_POLICY, ALL_EXISTING_AND_FUTURE_ORGS); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.emptyList()); + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_AND_FUTURE_ORGS); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, SUPER_ORG, ORGANIZATION_AUDIENCE))); return policyWithRoles; } @@ -689,18 +696,14 @@ private Map setExpectedResultsForGeneralUserSharingTestCase2() { Map expectedResults = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l1Org2Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l1Org1Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -739,8 +742,8 @@ private Map setPolicyWithRolesForGeneralUserSharingTestCase4() { Map policyWithRoles = new HashMap<>(); - policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_AND_FUTURE_ORGS); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, SUPER_ORG, ORGANIZATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, ALL_EXISTING_AND_FUTURE_ORGS); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.emptyList()); return policyWithRoles; } @@ -749,14 +752,18 @@ private Map setExpectedResultsForGeneralUserSharingTestCase4() { Map expectedResults = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l1Org2Id, l1Org3Id)); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org1Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -801,14 +808,13 @@ private Map setExpectedUnsharedResultsForGeneralUserSharingTestC Map expectedResults = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l2Org3Id, l1Org3Id)); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 2); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -835,13 +841,14 @@ private Map setExpectedUnsharedResultsForGeneralUserSharingTestC Map expectedResults = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 2); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l1Org3Id)); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); From 6e30990cf3bc56d5a0cf45f8d6abe35b1614cf7d Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Thu, 27 Feb 2025 15:28:15 +0530 Subject: [PATCH 07/39] complete selective user unshare. --- .../management/v1/UserSharingSuccessTest.java | 50 ------------------- 1 file changed, 50 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 5eee0319491..eb3b207301d 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -317,25 +317,9 @@ public Object[][] selectiveUserUnsharingDataProvider() { List removingOrgIdsForTestCase2 = Collections.singletonList(l1Org1Id); Map expectedUnsharedResultsForTestCase2 = setExpectedUnsharedResultsForGeneralUserSharingTestCase2(); -// // IMMEDIATE EXISTING -// List userIdsForTestCase3 = Collections.singletonList(rootOrgUser2Id); -// Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingTestCase3(); -// Map expectedSharedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingTestCase3(); -// List removingOrgIdsForTestCase3 = Arrays.asList(l1Org1Id, l1Org3Id); -// Map expectedUnsharedResultsForTestCase3 = setExpectedUnsharedResultsForGeneralUserSharingTestCase3(); -// -// // ALL EXISTING AND FUTURE -// List userIdsForTestCase4 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); -// Map policyWithRolesForTestCase4 = setPolicyWithRolesForGeneralUserSharingTestCase4(); -// Map expectedSharedResultsForTestCase4 = setExpectedResultsForGeneralUserSharingTestCase4(); -// List removingOrgIdsForTestCase4 = Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id); -// Map expectedUnsharedResultsForTestCase4 = setExpectedUnsharedResultsForGeneralUserSharingTestCase4(); - return new Object[][] { { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, removingOrgIdsForTestCase1, expectedUnsharedResultsForTestCase1}, { userIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, removingOrgIdsForTestCase2, expectedUnsharedResultsForTestCase2} -// { userIdsForTestCase3, policyWithRolesForTestCase3, expectedSharedResultsForTestCase3, removingOrgIdsForTestCase3, expectedUnsharedResultsForTestCase3}, -// { userIdsForTestCase4, policyWithRolesForTestCase4, expectedSharedResultsForTestCase4, removingOrgIdsForTestCase4, expectedUnsharedResultsForTestCase4} }; } @@ -821,40 +805,6 @@ private Map setExpectedUnsharedResultsForGeneralUserSharingTestC return expectedResults; } - private Map setExpectedUnsharedResultsForGeneralUserSharingTestCase3() { - - Map expectedResults = new HashMap<>(); - - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 1); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id)); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME)); - - Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - - expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); - - return expectedResults; - } - - private Map setExpectedUnsharedResultsForGeneralUserSharingTestCase4() { - - Map expectedResults = new HashMap<>(); - - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l2Org3Id, l1Org3Id)); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); - - Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); - - expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); - - return expectedResults; - } - // Helper Methods. private RoleWithAudience createRoleWithAudience(String roleName, String display, String type) { From 0a7ea17625503d4d073fef747292bf74394677d0 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sat, 1 Mar 2025 13:00:14 +0530 Subject: [PATCH 08/39] make appDetails map. --- .../management/v1/UserSharingBaseTest.java | 6 +- .../management/v1/UserSharingSuccessTest.java | 231 +++++++++++++----- 2 files changed, 168 insertions(+), 69 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index e26a7239ae1..8894fcec740 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -93,7 +93,7 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String ERROR_CODE_INVALID_PAGINATION_CURSOR = "ORG-60026"; protected static final String ERROR_CODE_SERVER_ERROR = "SE-50000"; - protected static final String ROOT_ORG_NAME = "Root - Organization"; + protected static final String ROOT_ORG_NAME = "Super"; protected static final String L1_ORG_1_NAME = "L1 - Organization 1"; protected static final String L1_ORG_2_NAME = "L1 - Organization 2"; protected static final String L1_ORG_3_NAME = "L1 - Organization 3"; @@ -102,11 +102,11 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String L2_ORG_3_NAME = "L2 - Organization 3"; protected static final String L3_ORG_1_NAME = "L3 - Organization 1"; + protected static final String ROOT_ORG_ID = "10084a8d-113f-4211-a0d5-efe36b082211"; + protected static final String APP_1_NAME = "App 1"; protected static final String APP_2_NAME = "App 2"; - protected static final String SUPER_ORG = "Super"; - protected static final String APPLICATION_AUDIENCE = "application"; protected static final String ORGANIZATION_AUDIENCE = "organization"; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index eb3b207301d..7fbe77f4d96 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -19,6 +19,7 @@ package org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1; import io.restassured.response.Response; +import org.apache.commons.lang.StringUtils; import org.apache.http.HttpStatus; import org.json.JSONObject; import org.testng.annotations.AfterClass; @@ -53,16 +54,18 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; -import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_AND_FUTURE_ORGS; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_AND_FUTURE_ORGS; @@ -80,7 +83,7 @@ public class UserSharingSuccessTest extends UserSharingBaseTest { private String l1Org1User2Id; private String l1Org1User3Id; - + private Map> orgDetails = new HashMap<>(); private String l1Org1Id; private String l1Org2Id; private String l1Org3Id; @@ -89,21 +92,9 @@ public class UserSharingSuccessTest extends UserSharingBaseTest { private String l2Org3Id; private String l3Org1Id; - private String l1Org1SwitchToken; - private String l2Org1SwitchToken; - - private String appId1; - private String appId2; - private String sharedApp1IdInLevel1Org; - private String sharedApp2IdInLevel1Org; - - private ApplicationResponseModel application1WithAppAudienceRoles; - private ApplicationResponseModel application2WithOrgAudienceRoles; - private String clientIdApp1; - private String clientSecretApp1; - private String clientIdApp2; - private String clientSecretApp2; - + Map app1Details; + Map app2Details; + private String appRole1Id; private String appRole2Id; private String appRole3Id; @@ -133,7 +124,6 @@ public void init() throws Exception { new JSONObject(readResource(AUTHORIZED_APIS_JSON))); setupOrganizations(); - setupTokens(); setupApplicationsAndRoles(); setupUsers(); } @@ -553,7 +543,7 @@ private Map> setOrganizationsForSelectiveUserSharing org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_1, SUPER_ORG, ORGANIZATION_AUDIENCE))); + createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); organizations.put(L1_ORG_2_NAME, org2); @@ -600,7 +590,7 @@ private Map> setOrganizationsForSelectiveUserSharing org2.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org2Id); org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); - org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(ORG_ROLE_1, SUPER_ORG, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, SUPER_ORG, ORGANIZATION_AUDIENCE))); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); organizations.put(L1_ORG_2_NAME, org2); @@ -671,7 +661,7 @@ private Map setPolicyWithRolesForGeneralUserSharingTestCase2() { Map policyWithRoles = new HashMap<>(); policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_AND_FUTURE_ORGS); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, SUPER_ORG, ORGANIZATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); return policyWithRoles; } @@ -699,7 +689,7 @@ private Map setPolicyWithRolesForGeneralUserSharingTestCase3() { Map policyWithRoles = new HashMap<>(); policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_ORGS_ONLY); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, SUPER_ORG, ORGANIZATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); return policyWithRoles; } @@ -829,52 +819,153 @@ private String getSharedOrgsRolesRef(String userId, String orgId) { private void setupOrganizations() throws Exception { - l1Org1Id = orgMgtRestClient.addOrganization(L1_ORG_1_NAME); - l1Org2Id = orgMgtRestClient.addOrganization(L1_ORG_2_NAME); - l1Org3Id = orgMgtRestClient.addOrganization(L1_ORG_3_NAME); - l2Org1Id = orgMgtRestClient.addSubOrganization(L2_ORG_1_NAME, l1Org1Id); - l2Org2Id = orgMgtRestClient.addSubOrganization(L2_ORG_2_NAME, l1Org1Id); - l2Org3Id = orgMgtRestClient.addSubOrganization(L2_ORG_3_NAME, l1Org2Id); - l3Org1Id = orgMgtRestClient.addSubOrganization(L3_ORG_1_NAME, l2Org1Id); + // Create Level 1 Organizations + l1Org1Id = addOrganization(L1_ORG_1_NAME); + l1Org2Id = addOrganization(L1_ORG_2_NAME); + l1Org3Id = addOrganization(L1_ORG_3_NAME); + + // Create Level 2 Organizations + l2Org1Id = addSubOrganization(L2_ORG_1_NAME, l1Org1Id, 2); + l2Org2Id = addSubOrganization(L2_ORG_2_NAME, l1Org1Id, 2); + l2Org3Id = addSubOrganization(L2_ORG_3_NAME, l1Org2Id, 2); + + // Create Level 3 Organization + l3Org1Id = addSubOrganization(L3_ORG_1_NAME, l2Org1Id, 3); } - private void setupTokens() throws Exception { + private String addOrganization(String orgName) throws Exception { + String orgId = orgMgtRestClient.addOrganization(orgName); + setOrgDetails(orgName, orgId, ROOT_ORG_ID, 1); + return orgId; + } + + private String addSubOrganization(String orgName, String parentId, int orgLevel) throws Exception { + String orgId = orgMgtRestClient.addSubOrganization(orgName, parentId); + setOrgDetails(orgName, orgId, parentId, orgLevel); + return orgId; + } + + private void setOrgDetails(String orgName, String orgId, String parentId, int orgLevel) throws Exception { + + Map orgDetail = new HashMap<>(); + orgDetail.put("orgName", orgName); + orgDetail.put("orgId", orgId); + orgDetail.put("parentOrgId", parentId); + orgDetail.put("orgSwitchToken", orgMgtRestClient.switchM2MToken(orgId)); + orgDetail.put("orgLevel", orgLevel); + orgDetails.put(orgName, orgDetail); - l1Org1SwitchToken = orgMgtRestClient.switchM2MToken(l1Org1Id); - l2Org1SwitchToken = orgMgtRestClient.switchM2MToken(l2Org1Id); } protected void setupApplicationsAndRoles() throws Exception { - // Create a new application which consume application audience roles and share with all children. - application1WithAppAudienceRoles = addApplication(APP_1_NAME); - String app1Id = application1WithAppAudienceRoles.getId(); - OpenIDConnectConfiguration oidcConfigOfApp1 = oAuth2RestClient.getOIDCInboundDetails(app1Id); - clientIdApp1 = oidcConfigOfApp1.getClientId(); - clientSecretApp1 = oidcConfigOfApp1.getClientSecret(); - createApp1RolesWithAppAudience(app1Id); - // Mark roles and groups as requested claims for the app 1. - updateRequestedClaimsOfApp(app1Id, getClaimConfigurationsWithRolesAndGroups()); - shareApplication(app1Id); - sharedApp1IdInLevel1Org = - oAuth2RestClient.getAppIdUsingAppNameInOrganization(APP_1_NAME, l1Org1SwitchToken); - - // Create a new application which consume organization audience roles and share with all children. - application2WithOrgAudienceRoles = addApplication(APP_2_NAME); - String app2Id = application2WithOrgAudienceRoles.getId(); - OpenIDConnectConfiguration oidcConfigOfApp2 = oAuth2RestClient.getOIDCInboundDetails(app2Id); - clientIdApp2 = oidcConfigOfApp2.getClientId(); - clientSecretApp2 = oidcConfigOfApp2.getClientSecret(); - createOrganizationRoles(); - switchApplicationAudience(app2Id, AssociatedRolesConfig.AllowedAudienceEnum.ORGANIZATION); + Map organizationRoles = createOrganizationRoles(); + app1Details = createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); + app2Details = createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, organizationRoles.keySet().stream().collect(Collectors.toList())); + } + + private Map createApplication(String appName, String audience, List roleNames) throws Exception{ + + Map createdAppDetails = new HashMap<>(); + + ApplicationResponseModel application = addApplication(appName); + String appId = application.getId(); + OpenIDConnectConfiguration oidcConfig = oAuth2RestClient.getOIDCInboundDetails(appId); + String clientId = oidcConfig.getClientId(); + String clientSecret = oidcConfig.getClientSecret(); + Map roleIdsByName = new HashMap<>(); + + if (StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience)){ + + Audience appRoleAudience = new Audience(APPLICATION_AUDIENCE, appId); + for (String roleName : roleNames) { + RoleV2 appRole = new RoleV2(appRoleAudience, roleName, Collections.emptyList(), Collections.emptyList()); + String roleId = scim2RestClient.addV2Role(appRole); + roleIdsByName.put(roleName, roleId); + } + createdAppDetails.put("appAudience", APPLICATION_AUDIENCE); + + } else { + + switchApplicationAudience(appId, AssociatedRolesConfig.AllowedAudienceEnum.ORGANIZATION); + + for (String roleName: roleNames){ + String roleId = scim2RestClient.getRoleIdByName(roleName); + roleIdsByName.put(roleName, roleId); + } + createdAppDetails.put("appAudience", ORGANIZATION_AUDIENCE); + } + // Mark roles and groups as requested claims for the app 2. - updateRequestedClaimsOfApp(app2Id, getClaimConfigurationsWithRolesAndGroups()); - shareApplication(app2Id); - sharedApp2IdInLevel1Org = - oAuth2RestClient.getAppIdUsingAppNameInOrganization(APP_2_NAME, l1Org1SwitchToken); + updateRequestedClaimsOfApp(appId, getClaimConfigurationsWithRolesAndGroups()); + shareApplication(appId); + + Map appDetailsOfSubOrgs = new HashMap<>(); + for (Map.Entry> entry : orgDetails.entrySet()) { + String orgName = entry.getKey(); + Map orgDetail = entry.getValue(); + + Map appDetailsOfSubOrg = getAppDetailsOfSubOrg(appName, audience, roleNames, orgDetail); + appDetailsOfSubOrgs.put(orgName, appDetailsOfSubOrg); + } + + createdAppDetails.put("appName", appName); + createdAppDetails.put("appId", appId); + createdAppDetails.put("clientId", clientId); + createdAppDetails.put("clientSecret", clientSecret); + createdAppDetails.put("roleNames", roleNames); + createdAppDetails.put("roleIdsByName", roleIdsByName); + createdAppDetails.put("appDetailsOfSubOrgs", appDetailsOfSubOrgs); + + return createdAppDetails; + } - private void createOrganizationRoles() throws IOException { + + private Map getAppDetailsOfSubOrg(String appName, String audience, List roleNames, + Map orgDetail) throws Exception { + + Map subOrgAppDetails = new HashMap<>(); + + String subOrgName = (String) orgDetail.get("orgName"); + String subOrgId = (String) orgDetail.get("orgId"); + String subOrgSwitchToken = (String) orgDetail.get("orgSwitchToken"); + + String subOrgAppId = oAuth2RestClient.getAppIdUsingAppNameInOrganization(appName, subOrgSwitchToken); + + Map subOrgRoleIdsByName = StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience) ? + getSubOrgRoleIdsByName(roleNames, subOrgAppId, subOrgSwitchToken) : + getSubOrgRoleIdsByName(roleNames, subOrgId, subOrgSwitchToken); + + subOrgAppDetails.put("subOrgName", subOrgName); + subOrgAppDetails.put("appName", appName); + subOrgAppDetails.put("appId", subOrgAppId); + subOrgAppDetails.put("roleNames", roleNames); + subOrgAppDetails.put("roleIdsByName", subOrgRoleIdsByName); + + return subOrgAppDetails; + } + + private Map getSubOrgRoleIdsByName (List roleNames, String audienceValue, String subOrgSwitchToken) throws Exception { + + Map roleIdsByName = new HashMap<>(); + for (String roleName : roleNames) { + String sharedAppRoleId = + scim2RestClient.getRoleIdByNameAndAudienceInSubOrg(roleName, audienceValue, subOrgSwitchToken); + roleIdsByName.put(roleName, sharedAppRoleId); + } + return roleIdsByName; + } + + private void validateAPPIdsNotNull(String... appIds) { + for (String appId : appIds) { + assertNotNull("Application ID is null", appId); + } + } + + private Map createOrganizationRoles() throws IOException { + + Map orgRoleIdsByName = new HashMap<>(); RoleV2 orgRole1 = new RoleV2(null, ORG_ROLE_1, Collections.emptyList(), Collections.emptyList()); orgRole1Id = scim2RestClient.addV2Role(orgRole1); @@ -882,6 +973,12 @@ private void createOrganizationRoles() throws IOException { orgRole2Id = scim2RestClient.addV2Role(orgRole2); RoleV2 orgRole3 = new RoleV2(null, ORG_ROLE_3, Collections.emptyList(), Collections.emptyList()); orgRole3Id = scim2RestClient.addV2Role(orgRole3); + + orgRoleIdsByName.put(ORG_ROLE_1, orgRole1Id); + orgRoleIdsByName.put(ORG_ROLE_2, orgRole2Id); + orgRoleIdsByName.put(ORG_ROLE_3, orgRole3Id); + + return orgRoleIdsByName; } private void createApp1RolesWithAppAudience(String app1Id) throws IOException { @@ -905,11 +1002,11 @@ private void setupUsers() throws Exception { rootOrgUser3Id = scim2RestClient.createUser(rootOrgUser3); UserObject l1Org1User1 = createUserObject(L1_ORG_1_USER_1_USERNAME, L1_ORG_1_NAME); - l1Org1User1Id = scim2RestClient.createSubOrgUser(l1Org1User1, l1Org1SwitchToken); + l1Org1User1Id = scim2RestClient.createSubOrgUser(l1Org1User1, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); UserObject l1Org1User2 = createUserObject(L1_ORG_1_USER_2_USERNAME, L1_ORG_1_NAME); - l1Org1User2Id = scim2RestClient.createSubOrgUser(l1Org1User2, l1Org1SwitchToken); + l1Org1User2Id = scim2RestClient.createSubOrgUser(l1Org1User2, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); UserObject l1Org1User3 = createUserObject(L1_ORG_1_USER_3_USERNAME, L1_ORG_1_NAME); - l1Org1User3Id = scim2RestClient.createSubOrgUser(l1Org1User3, l1Org1SwitchToken); + l1Org1User3Id = scim2RestClient.createSubOrgUser(l1Org1User3, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); } private void deleteUserIfExists(String userId) throws Exception { @@ -959,9 +1056,9 @@ private void cleanUpUsers() throws Exception { deleteUserIfExists(rootOrgUser1Id); deleteUserIfExists(rootOrgUser2Id); deleteUserIfExists(rootOrgUser3Id); - deleteSubOrgUserIfExists(l1Org1User1Id, l1Org1SwitchToken); - deleteSubOrgUserIfExists(l1Org1User2Id, l1Org1SwitchToken); - deleteSubOrgUserIfExists(l1Org1User3Id, l1Org1SwitchToken); + deleteSubOrgUserIfExists(l1Org1User1Id, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); + deleteSubOrgUserIfExists(l1Org1User2Id, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); + deleteSubOrgUserIfExists(l1Org1User3Id, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); } private void cleanUpRoles() throws Exception { @@ -976,8 +1073,10 @@ private void cleanUpRoles() throws Exception { private void cleanUpApplications() throws Exception { - deleteApplicationIfExists(application1WithAppAudienceRoles.getId()); - deleteApplicationIfExists(application2WithOrgAudienceRoles.getId()); + //deleteApplicationIfExists(application1WithAppAudienceRoles.getId()); + //deleteApplicationIfExists(application2WithOrgAudienceRoles.getId()); + deleteApplicationIfExists(app1Details.get("appId").toString()); + deleteApplicationIfExists(app2Details.get("appId").toString()); } private void cleanUpOrganizations() throws Exception { From 1f106248f40c0de156abd4ea21d41f3f901a8550 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sun, 2 Mar 2025 10:36:04 +0530 Subject: [PATCH 09/39] remove old methods and add new support methods. --- .../management/v1/UserSharingSuccessTest.java | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 7fbe77f4d96..07c8f3eaeb3 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -94,7 +94,7 @@ public class UserSharingSuccessTest extends UserSharingBaseTest { Map app1Details; Map app2Details; - + private String appRole1Id; private String appRole2Id; private String appRole3Id; @@ -861,7 +861,7 @@ protected void setupApplicationsAndRoles() throws Exception { Map organizationRoles = createOrganizationRoles(); app1Details = createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); - app2Details = createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, organizationRoles.keySet().stream().collect(Collectors.toList())); + app2Details = createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(organizationRoles.keySet())); } private Map createApplication(String appName, String audience, List roleNames) throws Exception{ @@ -918,7 +918,6 @@ private Map createApplication(String appName, String audience, L createdAppDetails.put("appDetailsOfSubOrgs", appDetailsOfSubOrgs); return createdAppDetails; - } @@ -957,12 +956,6 @@ private Map getSubOrgRoleIdsByName (List roleNames, Stri return roleIdsByName; } - private void validateAPPIdsNotNull(String... appIds) { - for (String appId : appIds) { - assertNotNull("Application ID is null", appId); - } - } - private Map createOrganizationRoles() throws IOException { Map orgRoleIdsByName = new HashMap<>(); @@ -981,17 +974,6 @@ private Map createOrganizationRoles() throws IOException { return orgRoleIdsByName; } - private void createApp1RolesWithAppAudience(String app1Id) throws IOException { - - Audience app1RoleAudience = new Audience(APPLICATION_AUDIENCE, app1Id); - RoleV2 appRole1 = new RoleV2(app1RoleAudience, APP_ROLE_1, Collections.emptyList(), Collections.emptyList()); - appRole1Id = scim2RestClient.addV2Role(appRole1); - RoleV2 appRole2 = new RoleV2(app1RoleAudience, APP_ROLE_2, Collections.emptyList(), Collections.emptyList()); - appRole2Id = scim2RestClient.addV2Role(appRole2); - RoleV2 appRole3 = new RoleV2(app1RoleAudience, APP_ROLE_3, Collections.emptyList(), Collections.emptyList()); - appRole3Id = scim2RestClient.addV2Role(appRole3); - } - private void setupUsers() throws Exception { UserObject rootOrgUser1 = createUserObject(ROOT_ORG_USER_1_USERNAME, ROOT_ORG_NAME); @@ -1073,8 +1055,6 @@ private void cleanUpRoles() throws Exception { private void cleanUpApplications() throws Exception { - //deleteApplicationIfExists(application1WithAppAudienceRoles.getId()); - //deleteApplicationIfExists(application2WithOrgAudienceRoles.getId()); deleteApplicationIfExists(app1Details.get("appId").toString()); deleteApplicationIfExists(app2Details.get("appId").toString()); } @@ -1096,4 +1076,9 @@ private void closeRestClients() throws IOException { scim2RestClient.closeHttpClient(); orgMgtRestClient.closeHttpClient(); } + + private String getOrgId(String orgName) { + + return orgDetails.get(orgName).get("orgId").toString(); + } } From ab01719b68a1ee85c03f86418f13af81c8e69b8b Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sun, 2 Mar 2025 11:44:13 +0530 Subject: [PATCH 10/39] move userIds to userDetails Map. --- .../management/v1/UserSharingBaseTest.java | 5 +- .../management/v1/UserSharingSuccessTest.java | 256 ++++++++++-------- 2 files changed, 140 insertions(+), 121 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 8894fcec740..653f0ea1b00 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -117,6 +117,8 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String ORG_ROLE_2 = "org-role-2"; protected static final String ORG_ROLE_3 = "org-role-3"; + protected static final String USER_DOMAIN_PRIMARY = "PRIMARY"; + protected static final String ROOT_ORG_USER_1_USERNAME = "rootUser1"; protected static final String ROOT_ORG_USER_2_USERNAME = "rootUser2"; protected static final String ROOT_ORG_USER_3_USERNAME = "rootUser3"; @@ -355,8 +357,9 @@ protected RequestedClaimConfiguration getRequestedClaim(String claimUri) { protected static UserObject createUserObject(String userName, String orgName) { + String domainQualifiedUserName = USER_DOMAIN_PRIMARY + "/" + userName; UserObject user = new UserObject() - .userName("PRIMARY/" + userName) + .userName(domainQualifiedUserName) .password("Admin123") .name(new Name().givenName(userName).familyName(orgName)) .emails(new ArrayList<>()); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 07c8f3eaeb3..6e0b43db768 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -54,14 +54,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; @@ -76,24 +73,9 @@ */ public class UserSharingSuccessTest extends UserSharingBaseTest { - private String rootOrgUser1Id; - private String rootOrgUser2Id; - private String rootOrgUser3Id; - private String l1Org1User1Id; - private String l1Org1User2Id; - private String l1Org1User3Id; - + private Map> userDetails = new HashMap<>(); private Map> orgDetails = new HashMap<>(); - private String l1Org1Id; - private String l1Org2Id; - private String l1Org3Id; - private String l2Org1Id; - private String l2Org2Id; - private String l2Org3Id; - private String l3Org1Id; - - Map app1Details; - Map app2Details; + private Map> appDetails = new HashMap<>(); private String appRole1Id; private String appRole2Id; @@ -153,11 +135,11 @@ public static Object[][] restAPIUserConfigProvider() { @DataProvider(name = "selectiveUserSharingDataProvider") public Object[][] selectiveUserSharingDataProvider() { - List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingTestCase1(); - List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); Map> organizationsForTestCase2 = setOrganizationsForSelectiveUserSharingTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserSharingTestCase2(); @@ -197,22 +179,22 @@ public void testSelectiveUserSharing(List userIds, public Object[][] generalUserSharingDataProvider() { // ALL EXISTING - List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); // IMMEDIATE EXISTING AND FUTURE - List userIdsForTestCase2 = Arrays.asList(rootOrgUser3Id, rootOrgUser2Id); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); // IMMEDIATE EXISTING - List userIdsForTestCase3 = Collections.singletonList(rootOrgUser2Id); + List userIdsForTestCase3 = Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingTestCase3(); Map expectedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingTestCase3(); // ALL EXISTING AND FUTURE - List userIdsForTestCase4 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); + List userIdsForTestCase4 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); Map policyWithRolesForTestCase4 = setPolicyWithRolesForGeneralUserSharingTestCase4(); Map expectedResultsForTestCase4 = setExpectedResultsForGeneralUserSharingTestCase4(); @@ -254,8 +236,8 @@ public void testGeneralUserSharing(List userIds, @DataProvider(name = "generalUserUnsharingDataProvider") public Object[][] generalUserUnsharingDataProvider() { - List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); - List userIdsForTestCase2 = Arrays.asList(rootOrgUser1Id, rootOrgUser2Id, rootOrgUser3Id); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); List userIdsForTestCase3 = Collections.emptyList(); Map expectedResultsForTestCase = setExpectedResultsForGeneralUserUnsharingTestCase1(); @@ -294,17 +276,17 @@ public void testGeneralUserUnsharing(List userIds, public Object[][] selectiveUserUnsharingDataProvider() { // ALL EXISTING - List userIdsForTestCase1 = Collections.singletonList(rootOrgUser1Id); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); - List removingOrgIdsForTestCase1 = Arrays.asList(l1Org1Id, l1Org2Id); + List removingOrgIdsForTestCase1 = Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME)); Map expectedUnsharedResultsForTestCase1 = setExpectedUnsharedResultsForGeneralUserSharingTestCase1(); // IMMEDIATE EXISTING AND FUTURE - List userIdsForTestCase2 = Arrays.asList(rootOrgUser3Id, rootOrgUser2Id); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); - List removingOrgIdsForTestCase2 = Collections.singletonList(l1Org1Id); + List removingOrgIdsForTestCase2 = Collections.singletonList(getOrgId(L1_ORG_1_NAME)); Map expectedUnsharedResultsForTestCase2 = setExpectedUnsharedResultsForGeneralUserSharingTestCase2(); return new Object[][] { @@ -528,7 +510,7 @@ private Map> setOrganizationsForSelectiveUserSharing // Organization 1 Map org1 = new HashMap<>(); - org1.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org1Id); + org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, @@ -538,7 +520,7 @@ private Map> setOrganizationsForSelectiveUserSharing // Organization 2 Map org2 = new HashMap<>(); - org2.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org2Id); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, @@ -549,7 +531,7 @@ private Map> setOrganizationsForSelectiveUserSharing // Organization 3 Map org3 = new HashMap<>(); - org3.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org3Id); + org3.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_3_NAME)); org3.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_3_NAME); org3.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_ONLY); org3.put(MAP_KEY_SELECTIVE_ROLES, Collections.emptyList()); @@ -564,17 +546,17 @@ private Map setExpectedResultsForSelectiveUserSharingTestCase1() Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l2Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.emptyList()); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -587,7 +569,7 @@ private Map> setOrganizationsForSelectiveUserSharing // Organization 2 Map org2 = new HashMap<>(); - org2.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org2Id); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); @@ -596,7 +578,7 @@ private Map> setOrganizationsForSelectiveUserSharing // Organization 3 Map org3 = new HashMap<>(); - org3.put(MAP_KEY_SELECTIVE_ORG_ID, l1Org3Id); + org3.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_3_NAME)); org3.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_3_NAME); org3.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN); org3.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); @@ -611,13 +593,13 @@ private Map setExpectedResultsForSelectiveUserSharingTestCase2() Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l2Org3Id, Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -639,17 +621,17 @@ private Map setExpectedResultsForGeneralUserSharingTestCase1() { Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -671,13 +653,13 @@ private Map setExpectedResultsForGeneralUserSharingTestCase2() { Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l1Org2Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org1Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -699,13 +681,13 @@ private Map setExpectedResultsForGeneralUserSharingTestCase3() { Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l1Org2Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -727,17 +709,17 @@ private Map setExpectedResultsForGeneralUserSharingTestCase4() { Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org1Id, l2Org1Id, l2Org2Id, l3Org1Id, l1Org2Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org1Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l1Org2Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.emptyList()); - expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.emptyList()); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.emptyList()); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.emptyList()); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.emptyList()); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.emptyList()); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.emptyList()); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.emptyList()); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.emptyList()); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -763,15 +745,15 @@ private Map setExpectedUnsharedResultsForGeneralUserSharingTestC Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 5); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l2Org1Id, l2Org2Id, l3Org1Id, l2Org3Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l2Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l2Org2Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l3Org1Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l2Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org3Id, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -783,12 +765,12 @@ private Map setExpectedUnsharedResultsForGeneralUserSharingTestC Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 2); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(l1Org2Id, l1Org3Id)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(l1Org2Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(l1Org3Id, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -820,17 +802,17 @@ private String getSharedOrgsRolesRef(String userId, String orgId) { private void setupOrganizations() throws Exception { // Create Level 1 Organizations - l1Org1Id = addOrganization(L1_ORG_1_NAME); - l1Org2Id = addOrganization(L1_ORG_2_NAME); - l1Org3Id = addOrganization(L1_ORG_3_NAME); + addOrganization(L1_ORG_1_NAME); + addOrganization(L1_ORG_2_NAME); + addOrganization(L1_ORG_3_NAME); // Create Level 2 Organizations - l2Org1Id = addSubOrganization(L2_ORG_1_NAME, l1Org1Id, 2); - l2Org2Id = addSubOrganization(L2_ORG_2_NAME, l1Org1Id, 2); - l2Org3Id = addSubOrganization(L2_ORG_3_NAME, l1Org2Id, 2); + addSubOrganization(L2_ORG_1_NAME, getOrgId(L1_ORG_1_NAME), 2); + addSubOrganization(L2_ORG_2_NAME, getOrgId(L1_ORG_1_NAME), 2); + addSubOrganization(L2_ORG_3_NAME, getOrgId(L1_ORG_2_NAME), 2); // Create Level 3 Organization - l3Org1Id = addSubOrganization(L3_ORG_1_NAME, l2Org1Id, 3); + addSubOrganization(L3_ORG_1_NAME, getOrgId(L2_ORG_1_NAME), 3); } private String addOrganization(String orgName) throws Exception { @@ -854,14 +836,13 @@ private void setOrgDetails(String orgName, String orgId, String parentId, int or orgDetail.put("orgSwitchToken", orgMgtRestClient.switchM2MToken(orgId)); orgDetail.put("orgLevel", orgLevel); orgDetails.put(orgName, orgDetail); - } protected void setupApplicationsAndRoles() throws Exception { Map organizationRoles = createOrganizationRoles(); - app1Details = createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); - app2Details = createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(organizationRoles.keySet())); + createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); + createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(organizationRoles.keySet())); } private Map createApplication(String appName, String audience, List roleNames) throws Exception{ @@ -917,6 +898,7 @@ private Map createApplication(String appName, String audience, L createdAppDetails.put("roleIdsByName", roleIdsByName); createdAppDetails.put("appDetailsOfSubOrgs", appDetailsOfSubOrgs); + appDetails.put(appName, createdAppDetails); return createdAppDetails; } @@ -976,19 +958,45 @@ private Map createOrganizationRoles() throws IOException { private void setupUsers() throws Exception { - UserObject rootOrgUser1 = createUserObject(ROOT_ORG_USER_1_USERNAME, ROOT_ORG_NAME); - rootOrgUser1Id = scim2RestClient.createUser(rootOrgUser1); - UserObject rootOrgUser2 = createUserObject(ROOT_ORG_USER_2_USERNAME, ROOT_ORG_NAME); - rootOrgUser2Id = scim2RestClient.createUser(rootOrgUser2); - UserObject rootOrgUser3 = createUserObject(ROOT_ORG_USER_3_USERNAME, ROOT_ORG_NAME); - rootOrgUser3Id = scim2RestClient.createUser(rootOrgUser3); - - UserObject l1Org1User1 = createUserObject(L1_ORG_1_USER_1_USERNAME, L1_ORG_1_NAME); - l1Org1User1Id = scim2RestClient.createSubOrgUser(l1Org1User1, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); - UserObject l1Org1User2 = createUserObject(L1_ORG_1_USER_2_USERNAME, L1_ORG_1_NAME); - l1Org1User2Id = scim2RestClient.createSubOrgUser(l1Org1User2, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); - UserObject l1Org1User3 = createUserObject(L1_ORG_1_USER_3_USERNAME, L1_ORG_1_NAME); - l1Org1User3Id = scim2RestClient.createSubOrgUser(l1Org1User3, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); + createUser(createUserObject(ROOT_ORG_USER_1_USERNAME, ROOT_ORG_NAME)); + createUser(createUserObject(ROOT_ORG_USER_2_USERNAME, ROOT_ORG_NAME)); + createUser(createUserObject(ROOT_ORG_USER_3_USERNAME, ROOT_ORG_NAME)); + + createSuborgUser(createUserObject(L1_ORG_1_USER_1_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); + createSuborgUser(createUserObject(L1_ORG_1_USER_2_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); + createSuborgUser(createUserObject(L1_ORG_1_USER_3_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); + } + + private String createUser(UserObject user) throws Exception{ + + String userId = scim2RestClient.createUser(user); + + Map userDetail = new HashMap<>(); + userDetail.put("username", user.getUserName()); + userDetail.put("userId", userId); + userDetail.put("isRootOrgUser", true); + userDetail.put("orgName", ROOT_ORG_NAME); + userDetail.put("orgId", ROOT_ORG_ID); + userDetail.put("orgLevel", 1); + + userDetails.put(user.getUserName(), userDetail); + return userId; + } + + private String createSuborgUser(UserObject user, String suborg) throws Exception{ + + String userId = scim2RestClient.createSubOrgUser(user, (String) orgDetails.get(suborg).get("orgSwitchToken")); + + Map userDetail = new HashMap<>(); + userDetail.put("username", user.getUserName()); + userDetail.put("userId", userId); + userDetail.put("isRootOrgUser", false); + userDetail.put("orgName", suborg); + userDetail.put("orgId", orgDetails.get(suborg).get("orgId")); + userDetail.put("orgLevel", orgDetails.get(suborg).get("orgLevel")); + + userDetails.put(user.getUserName(), userDetail); + return userId; } private void deleteUserIfExists(String userId) throws Exception { @@ -1035,12 +1043,12 @@ private void deleteOrganizationIfExists(String orgId) throws Exception { private void cleanUpUsers() throws Exception { - deleteUserIfExists(rootOrgUser1Id); - deleteUserIfExists(rootOrgUser2Id); - deleteUserIfExists(rootOrgUser3Id); - deleteSubOrgUserIfExists(l1Org1User1Id, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); - deleteSubOrgUserIfExists(l1Org1User2Id, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); - deleteSubOrgUserIfExists(l1Org1User3Id, (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); + deleteUserIfExists(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); + deleteUserIfExists(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); + deleteUserIfExists(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + deleteSubOrgUserIfExists(getUserId(L1_ORG_1_USER_1_USERNAME, USER_DOMAIN_PRIMARY), (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); + deleteSubOrgUserIfExists(getUserId(L1_ORG_1_USER_2_USERNAME, USER_DOMAIN_PRIMARY), (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); + deleteSubOrgUserIfExists(getUserId(L1_ORG_1_USER_3_USERNAME, USER_DOMAIN_PRIMARY), (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); } private void cleanUpRoles() throws Exception { @@ -1055,19 +1063,21 @@ private void cleanUpRoles() throws Exception { private void cleanUpApplications() throws Exception { - deleteApplicationIfExists(app1Details.get("appId").toString()); - deleteApplicationIfExists(app2Details.get("appId").toString()); + for (Map.Entry> entry : appDetails.entrySet()) { + Map details = entry.getValue(); + deleteApplicationIfExists(details.get("appId").toString()); + } } private void cleanUpOrganizations() throws Exception { - deleteSubOrganizationIfExists(l3Org1Id, l2Org1Id); - deleteSubOrganizationIfExists(l2Org3Id, l1Org2Id); - deleteSubOrganizationIfExists(l2Org2Id, l1Org1Id); - deleteSubOrganizationIfExists(l2Org1Id, l1Org1Id); - deleteOrganizationIfExists(l1Org3Id); - deleteOrganizationIfExists(l1Org2Id); - deleteOrganizationIfExists(l1Org1Id); + deleteSubOrganizationIfExists(getOrgId(L3_ORG_1_NAME), getOrgId(L2_ORG_1_NAME)); + deleteSubOrganizationIfExists(getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_2_NAME)); + deleteSubOrganizationIfExists(getOrgId(L2_ORG_2_NAME), getOrgId(L1_ORG_1_NAME)); + deleteSubOrganizationIfExists(getOrgId(L2_ORG_1_NAME), getOrgId(L1_ORG_1_NAME)); + deleteOrganizationIfExists(getOrgId(L1_ORG_3_NAME)); + deleteOrganizationIfExists(getOrgId(L1_ORG_2_NAME)); + deleteOrganizationIfExists(getOrgId(L1_ORG_1_NAME)); } private void closeRestClients() throws IOException { @@ -1081,4 +1091,10 @@ private String getOrgId(String orgName) { return orgDetails.get(orgName).get("orgId").toString(); } + + private String getUserId(String userName, String userDomain) { + + String domainQualifiedUserName = userDomain + "/" + userName; + return userDetails.get(domainQualifiedUserName).get("userId").toString(); + } } From 1b18de6c807235728e9fc4bc73d390b84c9dddde Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sun, 2 Mar 2025 16:32:08 +0530 Subject: [PATCH 11/39] move roleIds to roleDetails Map. --- .../management/v1/UserSharingSuccessTest.java | 119 +++++++++++++----- 1 file changed, 85 insertions(+), 34 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 6e0b43db768..2ab9ccf0211 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -76,13 +76,7 @@ public class UserSharingSuccessTest extends UserSharingBaseTest { private Map> userDetails = new HashMap<>(); private Map> orgDetails = new HashMap<>(); private Map> appDetails = new HashMap<>(); - - private String appRole1Id; - private String appRole2Id; - private String appRole3Id; - private String orgRole1Id; - private String orgRole2Id; - private String orgRole3Id; + private Map> roleDetails = new HashMap<>(); @Factory(dataProvider = "restAPIUserConfigProvider") public UserSharingSuccessTest(TestUserMode userMode) throws Exception { @@ -115,7 +109,7 @@ public void init() throws Exception { public void testConclude() throws Exception { cleanUpUsers(); - cleanUpRoles(); + cleanUpRoles(APPLICATION_AUDIENCE, ORGANIZATION_AUDIENCE); cleanUpApplications(); cleanUpOrganizations(); closeRestClients(); @@ -840,14 +834,16 @@ private void setOrgDetails(String orgName, String orgId, String parentId, int or protected void setupApplicationsAndRoles() throws Exception { - Map organizationRoles = createOrganizationRoles(); + Map rootOrgOrganizationRoles = createOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); + createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); - createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(organizationRoles.keySet())); + createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(rootOrgOrganizationRoles.keySet())); } private Map createApplication(String appName, String audience, List roleNames) throws Exception{ Map createdAppDetails = new HashMap<>(); + String rootOrgAppName = appName + "/" + ROOT_ORG_NAME; ApplicationResponseModel application = addApplication(appName); String appId = application.getId(); @@ -864,6 +860,7 @@ private Map createApplication(String appName, String audience, L String roleId = scim2RestClient.addV2Role(appRole); roleIdsByName.put(roleName, roleId); } + storeRoleDetails(APPLICATION_AUDIENCE, rootOrgAppName, roleIdsByName); createdAppDetails.put("appAudience", APPLICATION_AUDIENCE); } else { @@ -903,20 +900,20 @@ private Map createApplication(String appName, String audience, L } - private Map getAppDetailsOfSubOrg(String appName, String audience, List roleNames, - Map orgDetail) throws Exception { + private Map getAppDetailsOfSubOrg(String appName, String audience, List roleNames, Map orgDetail) throws Exception { Map subOrgAppDetails = new HashMap<>(); String subOrgName = (String) orgDetail.get("orgName"); String subOrgId = (String) orgDetail.get("orgId"); String subOrgSwitchToken = (String) orgDetail.get("orgSwitchToken"); + String subOrgAppName = appName + "/" + subOrgName; String subOrgAppId = oAuth2RestClient.getAppIdUsingAppNameInOrganization(appName, subOrgSwitchToken); Map subOrgRoleIdsByName = StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience) ? - getSubOrgRoleIdsByName(roleNames, subOrgAppId, subOrgSwitchToken) : - getSubOrgRoleIdsByName(roleNames, subOrgId, subOrgSwitchToken); + getSubOrgRoleIdsByName(roleNames, APPLICATION_AUDIENCE, subOrgAppName, subOrgAppId, subOrgSwitchToken) : + getSubOrgRoleIdsByName(roleNames,ORGANIZATION_AUDIENCE, subOrgName, subOrgId, subOrgSwitchToken); subOrgAppDetails.put("subOrgName", subOrgName); subOrgAppDetails.put("appName", appName); @@ -927,7 +924,7 @@ private Map getAppDetailsOfSubOrg(String appName, String audienc return subOrgAppDetails; } - private Map getSubOrgRoleIdsByName (List roleNames, String audienceValue, String subOrgSwitchToken) throws Exception { + private Map getSubOrgRoleIdsByName(List roleNames, String audienceType, String audienceName, String audienceValue, String subOrgSwitchToken) throws Exception { Map roleIdsByName = new HashMap<>(); for (String roleName : roleNames) { @@ -935,27 +932,42 @@ private Map getSubOrgRoleIdsByName (List roleNames, Stri scim2RestClient.getRoleIdByNameAndAudienceInSubOrg(roleName, audienceValue, subOrgSwitchToken); roleIdsByName.put(roleName, sharedAppRoleId); } + + if (StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audienceType)) { + storeRoleDetails(APPLICATION_AUDIENCE, audienceName, roleIdsByName); + } else { + storeRoleDetails(ORGANIZATION_AUDIENCE, audienceName, roleIdsByName); + } + return roleIdsByName; } - private Map createOrganizationRoles() throws IOException { + private Map createOrganizationRoles(String orgName, List orgRoleNames) throws IOException { Map orgRoleIdsByName = new HashMap<>(); + for (String orgRoleName : orgRoleNames) { + RoleV2 orgRole = new RoleV2(null, orgRoleName, Collections.emptyList(), Collections.emptyList()); + String orgRoleId = scim2RestClient.addV2Role(orgRole); + orgRoleIdsByName.put(orgRoleName, orgRoleId); + } - RoleV2 orgRole1 = new RoleV2(null, ORG_ROLE_1, Collections.emptyList(), Collections.emptyList()); - orgRole1Id = scim2RestClient.addV2Role(orgRole1); - RoleV2 orgRole2 = new RoleV2(null, ORG_ROLE_2, Collections.emptyList(), Collections.emptyList()); - orgRole2Id = scim2RestClient.addV2Role(orgRole2); - RoleV2 orgRole3 = new RoleV2(null, ORG_ROLE_3, Collections.emptyList(), Collections.emptyList()); - orgRole3Id = scim2RestClient.addV2Role(orgRole3); - - orgRoleIdsByName.put(ORG_ROLE_1, orgRole1Id); - orgRoleIdsByName.put(ORG_ROLE_2, orgRole2Id); - orgRoleIdsByName.put(ORG_ROLE_3, orgRole3Id); + storeRoleDetails(ORGANIZATION_AUDIENCE, orgName, orgRoleIdsByName); return orgRoleIdsByName; } + private void storeRoleDetails(String audienceType, String audienceName, Map rolesOfAudience) { + + String key = StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audienceType) + ? APPLICATION_AUDIENCE + : ORGANIZATION_AUDIENCE; + + Map rolesMapOfAudienceType = new HashMap<>(); + rolesMapOfAudienceType.put(audienceName, rolesOfAudience); + + roleDetails.computeIfAbsent(key, k -> new HashMap<>()).putAll(rolesMapOfAudienceType); + } + private void setupUsers() throws Exception { createUser(createUserObject(ROOT_ORG_USER_1_USERNAME, ROOT_ORG_NAME)); @@ -1041,6 +1053,11 @@ private void deleteOrganizationIfExists(String orgId) throws Exception { } } + /** + * Clean up users by deleting them if they exist. + * + * @throws Exception If an error occurs while deleting the users. + */ private void cleanUpUsers() throws Exception { deleteUserIfExists(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); @@ -1051,16 +1068,40 @@ private void cleanUpUsers() throws Exception { deleteSubOrgUserIfExists(getUserId(L1_ORG_1_USER_3_USERNAME, USER_DOMAIN_PRIMARY), (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); } - private void cleanUpRoles() throws Exception { - - deleteRoleIfExists(appRole1Id); - deleteRoleIfExists(appRole2Id); - deleteRoleIfExists(appRole3Id); - deleteRoleIfExists(orgRole1Id); - deleteRoleIfExists(orgRole2Id); - deleteRoleIfExists(orgRole3Id); + /** + * Cleans up roles for the specified audiences if exists. + * Audiences will always be either ORGANIZATION_AUDIENCE or APPLICATION_AUDIENCE or both. + * + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. + *

+ * @param audiences The audiences for which roles need to be cleaned up. + * @throws Exception If an error occurs during the cleanup process. + */ + @SuppressWarnings("unchecked") + private void cleanUpRoles(String... audiences) throws Exception { + + for(String audience : audiences) { + Map orgWiseRolesOfAudience = roleDetails.get(audience); + for (Map.Entry entry : orgWiseRolesOfAudience.entrySet()) { + String audienceName = entry.getKey(); + Map roles = (Map) entry.getValue(); + for (Map.Entry role : roles.entrySet()) { + String roleId = role.getValue(); + if(audienceName.contains(ROOT_ORG_NAME)) { + deleteRoleIfExists(roleId); + } + } + } + } } + /** + * Cleans up applications by deleting them if they exist. + * + * @throws Exception If an error occurs while deleting the applications. + */ private void cleanUpApplications() throws Exception { for (Map.Entry> entry : appDetails.entrySet()) { @@ -1069,6 +1110,11 @@ private void cleanUpApplications() throws Exception { } } + /** + * Cleans up organizations by deleting them if they exist. + * + * @throws Exception If an error occurs while deleting the organizations. + */ private void cleanUpOrganizations() throws Exception { deleteSubOrganizationIfExists(getOrgId(L3_ORG_1_NAME), getOrgId(L2_ORG_1_NAME)); @@ -1080,6 +1126,11 @@ private void cleanUpOrganizations() throws Exception { deleteOrganizationIfExists(getOrgId(L1_ORG_1_NAME)); } + /** + * Close the HTTP clients for OAuth2, SCIM2, and Organization Management. + * + * @throws IOException If an error occurred while closing the HTTP clients. + */ private void closeRestClients() throws IOException { oAuth2RestClient.closeHttpClient(); From 7db3268630e5c9e2c4acb3953740f74a00f8b22d Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sun, 2 Mar 2025 17:11:51 +0530 Subject: [PATCH 12/39] remove hardcode from delete organizations. --- .../management/v1/UserSharingSuccessTest.java | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 2ab9ccf0211..5b3c1ef4031 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -1111,21 +1111,66 @@ private void cleanUpApplications() throws Exception { } /** - * Cleans up organizations by deleting them if they exist. + * Cleans up organizations by deleting them from the deepest level to the root level. * * @throws Exception If an error occurs while deleting the organizations. */ private void cleanUpOrganizations() throws Exception { + // Determine the deepest organization level in the hierarchy + int maxDepth = orgDetails.values().stream() + .mapToInt(details -> (int) details.get("orgLevel")) + .max() + .orElse(1); + + // Delete organizations starting from the deepest level down to the root level + for (int level = maxDepth; level >= 1; level--) { + for (Map.Entry> entry : orgDetails.entrySet()) { + if ((int) entry.getValue().get("orgLevel") == level) { + deleteOrganization(entry.getKey(), entry.getValue()); + } + } + } + } + + private void deleteOrganization(String orgName, Map details) throws Exception { + String orgId = getOrgId(orgName); + String parentOrgId = (String) details.get("parentOrgId"); - deleteSubOrganizationIfExists(getOrgId(L3_ORG_1_NAME), getOrgId(L2_ORG_1_NAME)); - deleteSubOrganizationIfExists(getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_2_NAME)); - deleteSubOrganizationIfExists(getOrgId(L2_ORG_2_NAME), getOrgId(L1_ORG_1_NAME)); - deleteSubOrganizationIfExists(getOrgId(L2_ORG_1_NAME), getOrgId(L1_ORG_1_NAME)); - deleteOrganizationIfExists(getOrgId(L1_ORG_3_NAME)); - deleteOrganizationIfExists(getOrgId(L1_ORG_2_NAME)); - deleteOrganizationIfExists(getOrgId(L1_ORG_1_NAME)); + if ((int) details.get("orgLevel") > 1) { + deleteSubOrganizationIfExists(orgId, parentOrgId); + } else { + deleteOrganizationIfExists(orgId); + } } + + +// private void cleanUpOrganizations() throws Exception { +// +// //cleanup sub organizations +// for (Map.Entry> entry : orgDetails.entrySet()) { +// String orgName = entry.getKey(); +// String orgId = getOrgId(orgName); +// int orgLevel = (int) orgDetails.get(orgName).get("orgLevel"); +// String parentOrgId = (String) orgDetails.get(orgName).get("parentOrgId"); +// +// if (orgLevel!=1) { +// deleteSubOrganizationIfExists(orgId, parentOrgId); +// } +// } +// +// //cleanup organizations +// for (Map.Entry> entry : orgDetails.entrySet()) { +// String orgName = entry.getKey(); +// String orgId = getOrgId(orgName); +// int orgLevel = (int) orgDetails.get(orgName).get("orgLevel"); +// +// if (orgLevel==1) { +// deleteOrganizationIfExists(orgId); +// } +// } +// } + /** * Close the HTTP clients for OAuth2, SCIM2, and Organization Management. * From 0e688dd940121bd0501e838c73ac5817435282b5 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sun, 2 Mar 2025 21:11:17 +0530 Subject: [PATCH 13/39] remove hardcode from delete users. --- .../management/v1/UserSharingSuccessTest.java | 47 +++++-------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 5b3c1ef4031..49d8d5737c4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -989,7 +989,7 @@ private String createUser(UserObject user) throws Exception{ userDetail.put("isRootOrgUser", true); userDetail.put("orgName", ROOT_ORG_NAME); userDetail.put("orgId", ROOT_ORG_ID); - userDetail.put("orgLevel", 1); + userDetail.put("orgLevel", 0); userDetails.put(user.getUserName(), userDetail); return userId; @@ -1060,12 +1060,17 @@ private void deleteOrganizationIfExists(String orgId) throws Exception { */ private void cleanUpUsers() throws Exception { - deleteUserIfExists(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); - deleteUserIfExists(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); - deleteUserIfExists(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); - deleteSubOrgUserIfExists(getUserId(L1_ORG_1_USER_1_USERNAME, USER_DOMAIN_PRIMARY), (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); - deleteSubOrgUserIfExists(getUserId(L1_ORG_1_USER_2_USERNAME, USER_DOMAIN_PRIMARY), (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); - deleteSubOrgUserIfExists(getUserId(L1_ORG_1_USER_3_USERNAME, USER_DOMAIN_PRIMARY), (String) orgDetails.get(L1_ORG_1_NAME).get("orgSwitchToken")); + for (Map.Entry> entry : userDetails.entrySet()) { + String userId = (String) entry.getValue().get("userId"); + String orgName = (String) entry.getValue().get("orgName"); + int orgLevel = (int) entry.getValue().get("orgLevel"); + + if(orgLevel==0) { + deleteUserIfExists(userId); + } else { + deleteSubOrgUserIfExists(userId, (String) orgDetails.get(orgName).get("orgSwitchToken")); + } + } } /** @@ -1143,34 +1148,6 @@ private void deleteOrganization(String orgName, Map details) thr } } - - -// private void cleanUpOrganizations() throws Exception { -// -// //cleanup sub organizations -// for (Map.Entry> entry : orgDetails.entrySet()) { -// String orgName = entry.getKey(); -// String orgId = getOrgId(orgName); -// int orgLevel = (int) orgDetails.get(orgName).get("orgLevel"); -// String parentOrgId = (String) orgDetails.get(orgName).get("parentOrgId"); -// -// if (orgLevel!=1) { -// deleteSubOrganizationIfExists(orgId, parentOrgId); -// } -// } -// -// //cleanup organizations -// for (Map.Entry> entry : orgDetails.entrySet()) { -// String orgName = entry.getKey(); -// String orgId = getOrgId(orgName); -// int orgLevel = (int) orgDetails.get(orgName).get("orgLevel"); -// -// if (orgLevel==1) { -// deleteOrganizationIfExists(orgId); -// } -// } -// } - /** * Close the HTTP clients for OAuth2, SCIM2, and Organization Management. * From 7c699983fe96920837f86cce3c647e7662906db7 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 3 Mar 2025 09:50:07 +0530 Subject: [PATCH 14/39] format. --- .../management/v1/UserSharingSuccessTest.java | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 49d8d5737c4..329672fbebd 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -93,12 +93,7 @@ public UserSharingSuccessTest(TestUserMode userMode) throws Exception { public void init() throws Exception { super.testInit(API_VERSION, swaggerDefinition, tenant); - - oAuth2RestClient = new OAuth2RestClient(serverURL, tenantInfo); - scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); - orgMgtRestClient = new OrgMgtRestClient(context, tenantInfo, serverURL, - new JSONObject(readResource(AUTHORIZED_APIS_JSON))); - + setupRestClients(); setupOrganizations(); setupApplicationsAndRoles(); setupUsers(); @@ -507,8 +502,7 @@ private Map> setOrganizationsForSelectiveUserSharing org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); - org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, - APPLICATION_AUDIENCE))); + org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); organizations.put(L1_ORG_1_NAME, org1); @@ -517,9 +511,7 @@ private Map> setOrganizationsForSelectiveUserSharing org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); - org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, - APPLICATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); organizations.put(L1_ORG_2_NAME, org2); @@ -791,8 +783,26 @@ private String getSharedOrgsRolesRef(String userId, String orgId) { return "/api/server/v1" + USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH + "?orgId=" + orgId; } + private String getOrgId(String orgName) { + + return orgDetails.get(orgName).get("orgId").toString(); + } + + private String getUserId(String userName, String userDomain) { + + String domainQualifiedUserName = userDomain + "/" + userName; + return userDetails.get(domainQualifiedUserName).get("userId").toString(); + } + // Setup and cleanup methods. + private void setupRestClients() throws Exception { + + oAuth2RestClient = new OAuth2RestClient(serverURL, tenantInfo); + scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); + orgMgtRestClient = new OrgMgtRestClient(context, tenantInfo, serverURL, new JSONObject(readResource(AUTHORIZED_APIS_JSON))); + } + private void setupOrganizations() throws Exception { // Create Level 1 Organizations @@ -810,12 +820,14 @@ private void setupOrganizations() throws Exception { } private String addOrganization(String orgName) throws Exception { + String orgId = orgMgtRestClient.addOrganization(orgName); setOrgDetails(orgName, orgId, ROOT_ORG_ID, 1); return orgId; } private String addSubOrganization(String orgName, String parentId, int orgLevel) throws Exception { + String orgId = orgMgtRestClient.addSubOrganization(orgName, parentId); setOrgDetails(orgName, orgId, parentId, orgLevel); return orgId; @@ -1159,15 +1171,4 @@ private void closeRestClients() throws IOException { scim2RestClient.closeHttpClient(); orgMgtRestClient.closeHttpClient(); } - - private String getOrgId(String orgName) { - - return orgDetails.get(orgName).get("orgId").toString(); - } - - private String getUserId(String userName, String userDomain) { - - String domainQualifiedUserName = userDomain + "/" + userName; - return userDetails.get(domainQualifiedUserName).get("userId").toString(); - } } From 15f1abf6250e9a4ca614dcf876076530744fd185 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 3 Mar 2025 10:20:57 +0530 Subject: [PATCH 15/39] move common methods to BaseTest. --- .../management/v1/UserSharingBaseTest.java | 163 +++++++----------- .../management/v1/UserSharingSuccessTest.java | 34 +--- 2 files changed, 74 insertions(+), 123 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 653f0ea1b00..9dcdceb7dd1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -47,6 +47,8 @@ import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.RequestedClaimConfiguration; import org.wso2.identity.integration.test.rest.api.server.common.RESTAPIServerTestBase; import org.wso2.identity.integration.test.rest.api.server.roles.v2.model.Permission; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudienceAudience; import org.wso2.identity.integration.test.rest.api.user.common.model.Email; import org.wso2.identity.integration.test.rest.api.user.common.model.Name; import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; @@ -59,6 +61,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import static org.wso2.identity.integration.test.restclients.RestBaseClient.USER_AGENT_ATTRIBUTE; @@ -160,8 +163,7 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { try { swaggerDefinition = getAPISwaggerDefinition(API_PACKAGE_NAME, API_DEFINITION_NAME); } catch (IOException e) { - Assert.fail(String.format("Unable to read the swagger definition %s from %s", API_DEFINITION_NAME, - API_PACKAGE_NAME), e); + Assert.fail(String.format("Unable to read the swagger definition %s from %s", API_DEFINITION_NAME, API_PACKAGE_NAME), e); } } @@ -183,17 +185,7 @@ public void testFinish() { RestAssured.basePath = StringUtils.EMPTY; } - protected String getAppClientId(String applicationId) throws Exception { - - OpenIDConnectConfiguration oidcConfig = oAuth2RestClient.getOIDCInboundDetails(applicationId); - return oidcConfig.getClientId(); - } - - protected String getAppClientSecret(String applicationId) throws Exception { - - OpenIDConnectConfiguration oidcConfig = oAuth2RestClient.getOIDCInboundDetails(applicationId); - return oidcConfig.getClientSecret(); - } + // Request Sending Methods. protected HttpResponse sendGetRequest(String endpointURL, HttpClient client) throws IOException { @@ -202,8 +194,7 @@ protected HttpResponse sendGetRequest(String endpointURL, HttpClient client) thr return client.execute(request); } - protected HttpResponse sendPostRequest(String endpointURL, List urlParameters, HttpClient client) - throws IOException { + protected HttpResponse sendPostRequest(String endpointURL, List urlParameters, HttpClient client) throws IOException { HttpPost request = new HttpPost(endpointURL); request.setHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); @@ -211,53 +202,14 @@ protected HttpResponse sendPostRequest(String endpointURL, List u return client.execute(request); } - protected HttpResponse sendPutRequest(String endpointURL, String body, HttpClient client) throws IOException { - - HttpPut request = new HttpPut(endpointURL); - request.setHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); - request.setHeader("Content-Type", "application/json"); - request.setEntity(new StringEntity(body)); - return client.execute(request); - } - - protected HttpResponse sendDeleteRequest(String endpointURL, HttpClient client) throws IOException { - - HttpDelete request = new HttpDelete(endpointURL); - request.setHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); - return client.execute(request); - } - - /** - * Ged permissions based on the provided custom scopes. - * - * @return A list of permissions including predefined permissions - */ - protected List getPermissions() { - - List userPermissions = new ArrayList<>(); - - Collections.addAll(userPermissions, - new Permission(INTERNAL_USER_SHARE), - new Permission(INTERNAL_USER_UNSHARE), - new Permission(INTERNAL_USER_SHARED_ACCESS_VIEW)); - - return userPermissions; - } - - protected List getRoleV2Schema() { - - List schemas = new ArrayList<>(); - schemas.add("urn:ietf:params:scim:schemas:extension:2.0:Role"); - return schemas; - } + // Helper methods. protected ApplicationResponseModel addApplication(String appName) throws Exception { ApplicationModel application = new ApplicationModel(); List grantTypes = new ArrayList<>(); - Collections.addAll(grantTypes, "authorization_code", "implicit", "password", "client_credentials", - "refresh_token", "organization_switch"); + Collections.addAll(grantTypes, "authorization_code", "implicit", "password", "client_credentials", "refresh_token", "organization_switch"); List callBackUrls = new ArrayList<>(); Collections.addAll(callBackUrls, OAuth2Constant.CALLBACK_URL); @@ -279,33 +231,15 @@ protected ApplicationResponseModel addApplication(String appName) throws Excepti return oAuth2RestClient.getApplication(appId); } - private ClaimConfiguration setApplicationClaimConfig() { - - ClaimMappings emailClaim = new ClaimMappings().applicationClaim(EMAIL_CLAIM_URI); - emailClaim.setLocalClaim( - new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( - EMAIL_CLAIM_URI)); - ClaimMappings countryClaim = new ClaimMappings().applicationClaim(COUNTRY_CLAIM_URI); - countryClaim.setLocalClaim( - new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( - COUNTRY_CLAIM_URI)); + protected void switchApplicationAudience(String appId, AssociatedRolesConfig.AllowedAudienceEnum newAudience) throws Exception { - RequestedClaimConfiguration emailRequestedClaim = new RequestedClaimConfiguration(); - emailRequestedClaim.setClaim( - new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( - EMAIL_CLAIM_URI)); - RequestedClaimConfiguration countryRequestedClaim = new RequestedClaimConfiguration(); - countryRequestedClaim.setClaim( - new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( - COUNTRY_CLAIM_URI)); + AssociatedRolesConfig associatedRolesConfigApp2 = new AssociatedRolesConfig(); + associatedRolesConfigApp2.setAllowedAudience(newAudience); - ClaimConfiguration claimConfiguration = new ClaimConfiguration().dialect(ClaimConfiguration.DialectEnum.CUSTOM); - claimConfiguration.addClaimMappingsItem(emailClaim); - claimConfiguration.addClaimMappingsItem(countryClaim); - claimConfiguration.addRequestedClaimsItem(emailRequestedClaim); - claimConfiguration.addRequestedClaimsItem(countryRequestedClaim); + ApplicationPatchModel patchModelApp2 = new ApplicationPatchModel(); + patchModelApp2.setAssociatedRoles(associatedRolesConfigApp2); - return claimConfiguration; + oAuth2RestClient.updateApplication(appId, patchModelApp2); } protected void shareApplication(String applicationId) throws Exception { @@ -318,24 +252,25 @@ protected void shareApplication(String applicationId) throws Exception { Thread.sleep(5000); } - protected void switchApplicationAudience(String appId, AssociatedRolesConfig.AllowedAudienceEnum newAudience) - throws Exception { - - AssociatedRolesConfig associatedRolesConfigApp2 = new AssociatedRolesConfig(); - associatedRolesConfigApp2.setAllowedAudience(newAudience); + private ClaimConfiguration setApplicationClaimConfig() { - ApplicationPatchModel patchModelApp2 = new ApplicationPatchModel(); - patchModelApp2.setAssociatedRoles(associatedRolesConfigApp2); + ClaimMappings emailClaim = new ClaimMappings().applicationClaim(EMAIL_CLAIM_URI); + emailClaim.setLocalClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(EMAIL_CLAIM_URI)); + ClaimMappings countryClaim = new ClaimMappings().applicationClaim(COUNTRY_CLAIM_URI); + countryClaim.setLocalClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(COUNTRY_CLAIM_URI)); - oAuth2RestClient.updateApplication(appId, patchModelApp2); - } + RequestedClaimConfiguration emailRequestedClaim = new RequestedClaimConfiguration(); + emailRequestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(EMAIL_CLAIM_URI)); + RequestedClaimConfiguration countryRequestedClaim = new RequestedClaimConfiguration(); + countryRequestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(COUNTRY_CLAIM_URI)); - protected void updateRequestedClaimsOfApp(String applicationId, ClaimConfiguration claimConfigurationsForApp) - throws IOException { + ClaimConfiguration claimConfiguration = new ClaimConfiguration().dialect(ClaimConfiguration.DialectEnum.CUSTOM); + claimConfiguration.addClaimMappingsItem(emailClaim); + claimConfiguration.addClaimMappingsItem(countryClaim); + claimConfiguration.addRequestedClaimsItem(emailRequestedClaim); + claimConfiguration.addRequestedClaimsItem(countryRequestedClaim); - ApplicationPatchModel applicationPatch = new ApplicationPatchModel(); - applicationPatch.setClaimConfiguration(claimConfigurationsForApp); - oAuth2RestClient.updateApplication(applicationId, applicationPatch); + return claimConfiguration; } protected ClaimConfiguration getClaimConfigurationsWithRolesAndGroups() { @@ -349,12 +284,17 @@ protected ClaimConfiguration getClaimConfigurationsWithRolesAndGroups() { protected RequestedClaimConfiguration getRequestedClaim(String claimUri) { RequestedClaimConfiguration requestedClaim = new RequestedClaimConfiguration(); - requestedClaim.setClaim( - new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( - claimUri)); + requestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(claimUri)); return requestedClaim; } + protected void updateRequestedClaimsOfApp(String applicationId, ClaimConfiguration claimConfigurationsForApp) throws IOException { + + ApplicationPatchModel applicationPatch = new ApplicationPatchModel(); + applicationPatch.setClaimConfiguration(claimConfigurationsForApp); + oAuth2RestClient.updateApplication(applicationId, applicationPatch); + } + protected static UserObject createUserObject(String userName, String orgName) { String domainQualifiedUserName = USER_DOMAIN_PRIMARY + "/" + userName; @@ -376,6 +316,35 @@ protected static UserObject createUserObject(String userName, String orgName) { return user; } + protected static RoleWithAudience createRoleWithAudience(String roleName, String display, String type) { + + RoleWithAudienceAudience audience = new RoleWithAudienceAudience(); + audience.setDisplay(display); + audience.setType(type); + + RoleWithAudience roleWithAudience = new RoleWithAudience(); + roleWithAudience.setDisplayName(roleName); + roleWithAudience.setAudience(audience); + + return roleWithAudience; + } + + protected static String getSharedOrgsRolesRef(String userId, String orgId) { + + return "/api/server/v1" + USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH + "?orgId=" + orgId; + } + + protected String getOrgId(Map> orgDetails, String orgName) { + + return orgDetails.get(orgName).get("orgId").toString(); + } + + protected String getUserId(Map> userDetails, String userName, String userDomain) { + + String domainQualifiedUserName = userDomain + "/" + userName; + return userDetails.get(domainQualifiedUserName).get("userId").toString(); + } + public String toJSONString(java.lang.Object object) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 329672fbebd..e4665a45d99 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -73,10 +73,10 @@ */ public class UserSharingSuccessTest extends UserSharingBaseTest { - private Map> userDetails = new HashMap<>(); - private Map> orgDetails = new HashMap<>(); - private Map> appDetails = new HashMap<>(); - private Map> roleDetails = new HashMap<>(); + private final Map> userDetails = new HashMap<>(); + private final Map> orgDetails = new HashMap<>(); + private final Map> appDetails = new HashMap<>(); + private final Map> roleDetails = new HashMap<>(); @Factory(dataProvider = "restAPIUserConfigProvider") public UserSharingSuccessTest(TestUserMode userMode) throws Exception { @@ -765,33 +765,14 @@ private Map setExpectedUnsharedResultsForGeneralUserSharingTestC // Helper Methods. - private RoleWithAudience createRoleWithAudience(String roleName, String display, String type) { - - RoleWithAudienceAudience audience = new RoleWithAudienceAudience(); - audience.setDisplay(display); - audience.setType(type); - - RoleWithAudience roleWithAudience = new RoleWithAudience(); - roleWithAudience.setDisplayName(roleName); - roleWithAudience.setAudience(audience); - - return roleWithAudience; - } - - private String getSharedOrgsRolesRef(String userId, String orgId) { - - return "/api/server/v1" + USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH + "?orgId=" + orgId; - } - private String getOrgId(String orgName) { - return orgDetails.get(orgName).get("orgId").toString(); + return getOrgId(orgDetails, orgName); } private String getUserId(String userName, String userDomain) { - String domainQualifiedUserName = userDomain + "/" + userName; - return userDetails.get(domainQualifiedUserName).get("userId").toString(); + return getUserId(userDetails, userName, userDomain); } // Setup and cleanup methods. @@ -890,6 +871,7 @@ private Map createApplication(String appName, String audience, L updateRequestedClaimsOfApp(appId, getClaimConfigurationsWithRolesAndGroups()); shareApplication(appId); + // Get sub org details of Applications. Map appDetailsOfSubOrgs = new HashMap<>(); for (Map.Entry> entry : orgDetails.entrySet()) { String orgName = entry.getKey(); @@ -911,7 +893,6 @@ private Map createApplication(String appName, String audience, L return createdAppDetails; } - private Map getAppDetailsOfSubOrg(String appName, String audience, List roleNames, Map orgDetail) throws Exception { Map subOrgAppDetails = new HashMap<>(); @@ -932,6 +913,7 @@ private Map getAppDetailsOfSubOrg(String appName, String audienc subOrgAppDetails.put("appId", subOrgAppId); subOrgAppDetails.put("roleNames", roleNames); subOrgAppDetails.put("roleIdsByName", subOrgRoleIdsByName); + subOrgAppDetails.put("appAudience", audience); return subOrgAppDetails; } From 7f1581abaac8e1f47315ca4ba2b9ce654041c9a0 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 3 Mar 2025 10:54:28 +0530 Subject: [PATCH 16/39] move rest of the common methods to BaseTest. --- .../management/v1/UserSharingBaseTest.java | 463 +++++++++++++++--- .../management/v1/UserSharingSuccessTest.java | 372 +------------- 2 files changed, 424 insertions(+), 411 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 9dcdceb7dd1..4409f6dc82c 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -46,7 +46,9 @@ import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.RequestedClaimConfiguration; import org.wso2.identity.integration.test.rest.api.server.common.RESTAPIServerTestBase; +import org.wso2.identity.integration.test.rest.api.server.roles.v2.model.Audience; import org.wso2.identity.integration.test.rest.api.server.roles.v2.model.Permission; +import org.wso2.identity.integration.test.rest.api.server.roles.v2.model.RoleV2; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudienceAudience; import org.wso2.identity.integration.test.rest.api.user.common.model.Email; @@ -60,6 +62,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -70,11 +73,21 @@ */ public class UserSharingBaseTest extends RESTAPIServerTestBase { + protected static String swaggerDefinition; + + protected OAuth2RestClient oAuth2RestClient; + protected SCIM2RestClient scim2RestClient; + protected OrgMgtRestClient orgMgtRestClient; + + protected Map> userDetails; + protected Map> orgDetails; + protected Map> appDetails; + protected Map> roleDetails; + private static final String API_DEFINITION_NAME = "organization-user-share.yaml"; protected static final String AUTHORIZED_APIS_JSON = "user-sharing-apis.json"; static final String API_VERSION = "v1"; - private static final String API_PACKAGE_NAME = - "org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1"; + private static final String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1"; static final String USER_SHARING_API_BASE_PATH = "/users"; static final String SHARE_PATH = "/share"; @@ -129,12 +142,12 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String L1_ORG_1_USER_2_USERNAME = "l1Org1User2"; protected static final String L1_ORG_1_USER_3_USERNAME = "l1Org1User3"; - protected static final String INTERNAL_USER_SHARE = "internal_user_share"; - protected static final String INTERNAL_USER_UNSHARE = "internal_user_unshare"; - protected static final String INTERNAL_USER_SHARED_ACCESS_VIEW = "internal_user_shared_access_view"; - protected static final String INTERNAL_ORG_USER_SHARE = "internal_org_user_share"; - protected static final String INTERNAL_ORG_USER_UNSHARE = "internal_org_user_unshare"; - protected static final String INTERNAL_ORG_USER_SHARED_ACCESS_VIEW = "internal_org_user_shared_access_view"; + protected static final String API_SCOPE_INTERNAL_USER_SHARE = "internal_user_share"; + protected static final String API_SCOPE_INTERNAL_USER_UNSHARE = "internal_user_unshare"; + protected static final String API_SCOPE_INTERNAL_USER_SHARED_ACCESS_VIEW = "internal_user_shared_access_view"; + protected static final String API_SCOPE_INTERNAL_ORG_USER_SHARE = "internal_org_user_share"; + protected static final String API_SCOPE_INTERNAL_ORG_USER_UNSHARE = "internal_org_user_unshare"; + protected static final String API_SCOPE_INTERNAL_ORG_USER_SHARED_ACCESS_VIEW = "internal_org_user_shared_access_view"; protected static final String EMAIL_CLAIM_URI = "http://wso2.org/claims/emailaddress"; protected static final String COUNTRY_CLAIM_URI = "http://wso2.org/claims/country"; @@ -154,11 +167,6 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String MAP_KEY_EXPECTED_ORG_NAMES = "expectedOrgNames"; protected static final String MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG = "expectedRolesPerExpectedOrg"; - protected static String swaggerDefinition; - protected OAuth2RestClient oAuth2RestClient; - protected SCIM2RestClient scim2RestClient; - protected OrgMgtRestClient orgMgtRestClient; - static { try { swaggerDefinition = getAPISwaggerDefinition(API_PACKAGE_NAME, API_DEFINITION_NAME); @@ -202,9 +210,188 @@ protected HttpResponse sendPostRequest(String endpointURL, List u return client.execute(request); } - // Helper methods. + // Methods to add organizations and sub organizations for testing purposes. + + protected String addOrganization(String orgName) throws Exception { + + String orgId = orgMgtRestClient.addOrganization(orgName); + setOrgDetails(orgName, orgId, ROOT_ORG_ID, 1); + return orgId; + } + + protected String addSubOrganization(String orgName, String parentId, int orgLevel) throws Exception { + + String orgId = orgMgtRestClient.addSubOrganization(orgName, parentId); + setOrgDetails(orgName, orgId, parentId, orgLevel); + return orgId; + } + + protected String getOrgId(String orgName) { + + return orgDetails.get(orgName).get("orgId").toString(); + } + + protected void setOrgDetails(String orgName, String orgId, String parentId, int orgLevel) throws Exception { + + Map orgDetail = new HashMap<>(); + orgDetail.put("orgName", orgName); + orgDetail.put("orgId", orgId); + orgDetail.put("parentOrgId", parentId); + orgDetail.put("orgSwitchToken", orgMgtRestClient.switchM2MToken(orgId)); + orgDetail.put("orgLevel", orgLevel); + orgDetails.put(orgName, orgDetail); + } + + // Methods to add applications and roles for testing purposes. + + protected Map createApplication(String appName, String audience, List roleNames) throws Exception{ + + Map createdAppDetails = new HashMap<>(); + String rootOrgAppName = appName + "/" + ROOT_ORG_NAME; + + ApplicationResponseModel application = addApplication(appName); + String appId = application.getId(); + OpenIDConnectConfiguration oidcConfig = oAuth2RestClient.getOIDCInboundDetails(appId); + String clientId = oidcConfig.getClientId(); + String clientSecret = oidcConfig.getClientSecret(); + Map roleIdsByName = new HashMap<>(); + + if (StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience)){ + + Audience appRoleAudience = new Audience(APPLICATION_AUDIENCE, appId); + for (String roleName : roleNames) { + RoleV2 appRole = new RoleV2(appRoleAudience, roleName, Collections.emptyList(), Collections.emptyList()); + String roleId = scim2RestClient.addV2Role(appRole); + roleIdsByName.put(roleName, roleId); + } + storeRoleDetails(APPLICATION_AUDIENCE, rootOrgAppName, roleIdsByName); + createdAppDetails.put("appAudience", APPLICATION_AUDIENCE); + + } else { + + switchApplicationAudience(appId, AssociatedRolesConfig.AllowedAudienceEnum.ORGANIZATION); + + for (String roleName: roleNames){ + String roleId = scim2RestClient.getRoleIdByName(roleName); + roleIdsByName.put(roleName, roleId); + } + createdAppDetails.put("appAudience", ORGANIZATION_AUDIENCE); + } + + // Mark roles and groups as requested claims for the app 2. + updateRequestedClaimsOfApp(appId, getClaimConfigurationsWithRolesAndGroups()); + shareApplication(appId); + + // Get sub org details of Applications. + Map appDetailsOfSubOrgs = new HashMap<>(); + for (Map.Entry> entry : orgDetails.entrySet()) { + String orgName = entry.getKey(); + Map orgDetail = entry.getValue(); + + Map appDetailsOfSubOrg = getAppDetailsOfSubOrg(appName, audience, roleNames, orgDetail); + appDetailsOfSubOrgs.put(orgName, appDetailsOfSubOrg); + } + + createdAppDetails.put("appName", appName); + createdAppDetails.put("appId", appId); + createdAppDetails.put("clientId", clientId); + createdAppDetails.put("clientSecret", clientSecret); + createdAppDetails.put("roleNames", roleNames); + createdAppDetails.put("roleIdsByName", roleIdsByName); + createdAppDetails.put("appDetailsOfSubOrgs", appDetailsOfSubOrgs); + + appDetails.put(appName, createdAppDetails); + return createdAppDetails; + } + + protected Map getAppDetailsOfSubOrg(String appName, String audience, List roleNames, Map orgDetail) throws Exception { + + Map subOrgAppDetails = new HashMap<>(); + + String subOrgName = (String) orgDetail.get("orgName"); + String subOrgId = (String) orgDetail.get("orgId"); + String subOrgSwitchToken = (String) orgDetail.get("orgSwitchToken"); + String subOrgAppName = appName + "/" + subOrgName; - protected ApplicationResponseModel addApplication(String appName) throws Exception { + String subOrgAppId = oAuth2RestClient.getAppIdUsingAppNameInOrganization(appName, subOrgSwitchToken); + + Map subOrgRoleIdsByName = StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience) ? + getSubOrgRoleIdsByName(roleNames, APPLICATION_AUDIENCE, subOrgAppName, subOrgAppId, subOrgSwitchToken) : + getSubOrgRoleIdsByName(roleNames,ORGANIZATION_AUDIENCE, subOrgName, subOrgId, subOrgSwitchToken); + + subOrgAppDetails.put("subOrgName", subOrgName); + subOrgAppDetails.put("appName", appName); + subOrgAppDetails.put("appId", subOrgAppId); + subOrgAppDetails.put("roleNames", roleNames); + subOrgAppDetails.put("roleIdsByName", subOrgRoleIdsByName); + subOrgAppDetails.put("appAudience", audience); + + return subOrgAppDetails; + } + + protected Map getSubOrgRoleIdsByName(List roleNames, String audienceType, String audienceName, String audienceValue, String subOrgSwitchToken) throws Exception { + + Map roleIdsByName = new HashMap<>(); + for (String roleName : roleNames) { + String sharedAppRoleId = + scim2RestClient.getRoleIdByNameAndAudienceInSubOrg(roleName, audienceValue, subOrgSwitchToken); + roleIdsByName.put(roleName, sharedAppRoleId); + } + + if (StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audienceType)) { + storeRoleDetails(APPLICATION_AUDIENCE, audienceName, roleIdsByName); + } else { + storeRoleDetails(ORGANIZATION_AUDIENCE, audienceName, roleIdsByName); + } + + return roleIdsByName; + } + + protected Map createOrganizationRoles(String orgName, List orgRoleNames) throws IOException { + + Map orgRoleIdsByName = new HashMap<>(); + for (String orgRoleName : orgRoleNames) { + RoleV2 orgRole = new RoleV2(null, orgRoleName, Collections.emptyList(), Collections.emptyList()); + String orgRoleId = scim2RestClient.addV2Role(orgRole); + orgRoleIdsByName.put(orgRoleName, orgRoleId); + } + + storeRoleDetails(ORGANIZATION_AUDIENCE, orgName, orgRoleIdsByName); + + return orgRoleIdsByName; + } + + protected RoleWithAudience createRoleWithAudience(String roleName, String display, String type) { + + RoleWithAudienceAudience audience = new RoleWithAudienceAudience(); + audience.setDisplay(display); + audience.setType(type); + + RoleWithAudience roleWithAudience = new RoleWithAudience(); + roleWithAudience.setDisplayName(roleName); + roleWithAudience.setAudience(audience); + + return roleWithAudience; + } + + protected String getSharedOrgsRolesRef(String userId, String orgId) { + + return "/api/server/v1" + USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH + "?orgId=" + orgId; + } + + protected void storeRoleDetails(String audienceType, String audienceName, Map rolesOfAudience) { + + String key = StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audienceType) + ? APPLICATION_AUDIENCE + : ORGANIZATION_AUDIENCE; + + Map rolesMapOfAudienceType = new HashMap<>(); + rolesMapOfAudienceType.put(audienceName, rolesOfAudience); + + roleDetails.computeIfAbsent(key, k -> new HashMap<>()).putAll(rolesMapOfAudienceType); + } + + private ApplicationResponseModel addApplication(String appName) throws Exception { ApplicationModel application = new ApplicationModel(); @@ -231,27 +418,6 @@ protected ApplicationResponseModel addApplication(String appName) throws Excepti return oAuth2RestClient.getApplication(appId); } - protected void switchApplicationAudience(String appId, AssociatedRolesConfig.AllowedAudienceEnum newAudience) throws Exception { - - AssociatedRolesConfig associatedRolesConfigApp2 = new AssociatedRolesConfig(); - associatedRolesConfigApp2.setAllowedAudience(newAudience); - - ApplicationPatchModel patchModelApp2 = new ApplicationPatchModel(); - patchModelApp2.setAssociatedRoles(associatedRolesConfigApp2); - - oAuth2RestClient.updateApplication(appId, patchModelApp2); - } - - protected void shareApplication(String applicationId) throws Exception { - - ApplicationSharePOSTRequest applicationSharePOSTRequest = new ApplicationSharePOSTRequest(); - applicationSharePOSTRequest.setShareWithAllChildren(true); - oAuth2RestClient.shareApplication(applicationId, applicationSharePOSTRequest); - - // Since application sharing is an async operation, wait for some time for it to finish. - Thread.sleep(5000); - } - private ClaimConfiguration setApplicationClaimConfig() { ClaimMappings emailClaim = new ClaimMappings().applicationClaim(EMAIL_CLAIM_URI); @@ -273,7 +439,7 @@ private ClaimConfiguration setApplicationClaimConfig() { return claimConfiguration; } - protected ClaimConfiguration getClaimConfigurationsWithRolesAndGroups() { + private ClaimConfiguration getClaimConfigurationsWithRolesAndGroups() { ClaimConfiguration claimConfiguration = new ClaimConfiguration(); claimConfiguration.addRequestedClaimsItem(getRequestedClaim(ROLES_CLAIM_URI)); @@ -281,23 +447,46 @@ protected ClaimConfiguration getClaimConfigurationsWithRolesAndGroups() { return claimConfiguration; } - protected RequestedClaimConfiguration getRequestedClaim(String claimUri) { + private RequestedClaimConfiguration getRequestedClaim(String claimUri) { RequestedClaimConfiguration requestedClaim = new RequestedClaimConfiguration(); requestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(claimUri)); return requestedClaim; } - protected void updateRequestedClaimsOfApp(String applicationId, ClaimConfiguration claimConfigurationsForApp) throws IOException { + private void updateRequestedClaimsOfApp(String applicationId, ClaimConfiguration claimConfigurationsForApp) throws IOException { ApplicationPatchModel applicationPatch = new ApplicationPatchModel(); applicationPatch.setClaimConfiguration(claimConfigurationsForApp); oAuth2RestClient.updateApplication(applicationId, applicationPatch); } - protected static UserObject createUserObject(String userName, String orgName) { + private void switchApplicationAudience(String appId, AssociatedRolesConfig.AllowedAudienceEnum newAudience) throws Exception { + + AssociatedRolesConfig associatedRolesConfigApp2 = new AssociatedRolesConfig(); + associatedRolesConfigApp2.setAllowedAudience(newAudience); + + ApplicationPatchModel patchModelApp2 = new ApplicationPatchModel(); + patchModelApp2.setAssociatedRoles(associatedRolesConfigApp2); + + oAuth2RestClient.updateApplication(appId, patchModelApp2); + } + + private void shareApplication(String applicationId) throws Exception { - String domainQualifiedUserName = USER_DOMAIN_PRIMARY + "/" + userName; + ApplicationSharePOSTRequest applicationSharePOSTRequest = new ApplicationSharePOSTRequest(); + applicationSharePOSTRequest.setShareWithAllChildren(true); + oAuth2RestClient.shareApplication(applicationId, applicationSharePOSTRequest); + + // Since application sharing is an async operation, wait for some time for it to finish. + Thread.sleep(5000); + } + + // Methods to add users in organizations and sub organizations for testing purposes. + + protected UserObject createUserObject(String userDomain, String userName, String orgName) { + + String domainQualifiedUserName = userDomain + "/" + userName; UserObject user = new UserObject() .userName(domainQualifiedUserName) .password("Admin123") @@ -316,36 +505,198 @@ protected static UserObject createUserObject(String userName, String orgName) { return user; } - protected static RoleWithAudience createRoleWithAudience(String roleName, String display, String type) { + protected String createUser(UserObject user) throws Exception{ - RoleWithAudienceAudience audience = new RoleWithAudienceAudience(); - audience.setDisplay(display); - audience.setType(type); + String userId = scim2RestClient.createUser(user); - RoleWithAudience roleWithAudience = new RoleWithAudience(); - roleWithAudience.setDisplayName(roleName); - roleWithAudience.setAudience(audience); + Map userDetail = new HashMap<>(); + userDetail.put("username", user.getUserName()); + userDetail.put("userId", userId); + userDetail.put("isRootOrgUser", true); + userDetail.put("orgName", ROOT_ORG_NAME); + userDetail.put("orgId", ROOT_ORG_ID); + userDetail.put("orgLevel", 0); - return roleWithAudience; + userDetails.put(user.getUserName(), userDetail); + return userId; } - protected static String getSharedOrgsRolesRef(String userId, String orgId) { + protected String createSuborgUser(UserObject user, String suborg) throws Exception{ - return "/api/server/v1" + USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH + "?orgId=" + orgId; - } + String userId = scim2RestClient.createSubOrgUser(user, (String) orgDetails.get(suborg).get("orgSwitchToken")); - protected String getOrgId(Map> orgDetails, String orgName) { + Map userDetail = new HashMap<>(); + userDetail.put("username", user.getUserName()); + userDetail.put("userId", userId); + userDetail.put("isRootOrgUser", false); + userDetail.put("orgName", suborg); + userDetail.put("orgId", orgDetails.get(suborg).get("orgId")); + userDetail.put("orgLevel", orgDetails.get(suborg).get("orgLevel")); - return orgDetails.get(orgName).get("orgId").toString(); + userDetails.put(user.getUserName(), userDetail); + return userId; } - protected String getUserId(Map> userDetails, String userName, String userDomain) { + protected String getUserId(String userName, String userDomain) { String domainQualifiedUserName = userDomain + "/" + userName; return userDetails.get(domainQualifiedUserName).get("userId").toString(); } - public String toJSONString(java.lang.Object object) { + // Methods to clean up the resources created for testing purposes. + + /** + * Clean up users by deleting them if they exist. + * + * @throws Exception If an error occurs while deleting the users. + */ + protected void cleanUpUsers() throws Exception { + + for (Map.Entry> entry : userDetails.entrySet()) { + String userId = (String) entry.getValue().get("userId"); + String orgName = (String) entry.getValue().get("orgName"); + int orgLevel = (int) entry.getValue().get("orgLevel"); + + if(orgLevel==0) { + deleteUserIfExists(userId); + } else { + deleteSubOrgUserIfExists(userId, (String) orgDetails.get(orgName).get("orgSwitchToken")); + } + } + } + + /** + * Cleans up roles for the specified audiences if exists. + * Audiences will always be either ORGANIZATION_AUDIENCE or APPLICATION_AUDIENCE or both. + * + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. + *

+ * @param audiences The audiences for which roles need to be cleaned up. + * @throws Exception If an error occurs during the cleanup process. + */ + @SuppressWarnings("unchecked") + protected void cleanUpRoles(String... audiences) throws Exception { + + for(String audience : audiences) { + Map orgWiseRolesOfAudience = roleDetails.get(audience); + for (Map.Entry entry : orgWiseRolesOfAudience.entrySet()) { + String audienceName = entry.getKey(); + Map roles = (Map) entry.getValue(); + for (Map.Entry role : roles.entrySet()) { + String roleId = role.getValue(); + if(audienceName.contains(ROOT_ORG_NAME)) { + deleteRoleIfExists(roleId); + } + } + } + } + } + + /** + * Cleans up applications by deleting them if they exist. + * + * @throws Exception If an error occurs while deleting the applications. + */ + protected void cleanUpApplications() throws Exception { + + for (Map.Entry> entry : appDetails.entrySet()) { + Map details = entry.getValue(); + deleteApplicationIfExists(details.get("appId").toString()); + } + } + + /** + * Cleans up organizations by deleting them from the deepest level to the root level. + * + * @throws Exception If an error occurs while deleting the organizations. + */ + protected void cleanUpOrganizations() throws Exception { + // Determine the deepest organization level in the hierarchy + int maxDepth = orgDetails.values().stream() + .mapToInt(details -> (int) details.get("orgLevel")) + .max() + .orElse(1); + + // Delete organizations starting from the deepest level down to the root level + for (int level = maxDepth; level >= 1; level--) { + for (Map.Entry> entry : orgDetails.entrySet()) { + if ((int) entry.getValue().get("orgLevel") == level) { + deleteOrganization(entry.getKey(), entry.getValue()); + } + } + } + } + + /** + * Close the HTTP clients for OAuth2, SCIM2, and Organization Management. + * + * @throws IOException If an error occurred while closing the HTTP clients. + */ + protected void closeRestClients() throws IOException { + + oAuth2RestClient.closeHttpClient(); + scim2RestClient.closeHttpClient(); + orgMgtRestClient.closeHttpClient(); + } + + private void deleteOrganization(String orgName, Map details) throws Exception { + String orgId = getOrgId(orgName); + String parentOrgId = (String) details.get("parentOrgId"); + + if ((int) details.get("orgLevel") > 1) { + deleteSubOrganizationIfExists(orgId, parentOrgId); + } else { + deleteOrganizationIfExists(orgId); + } + } + + private void deleteUserIfExists(String userId) throws Exception { + + if (userId != null) { + scim2RestClient.deleteUser(userId); + } + } + + private void deleteSubOrgUserIfExists(String userId, String organizationSwitchToken) throws Exception { + + if (userId != null) { + scim2RestClient.deleteSubOrgUser(userId, organizationSwitchToken); + } + } + + private void deleteRoleIfExists(String roleId) throws Exception { + + if (roleId != null) { + scim2RestClient.deleteV2Role(roleId); + } + } + + private void deleteApplicationIfExists(String appId) throws Exception { + + if (appId != null) { + oAuth2RestClient.deleteApplication(appId); + } + } + + private void deleteSubOrganizationIfExists(String orgId, String parentId) throws Exception { + + if (orgId != null) { + orgMgtRestClient.deleteSubOrganization(orgId, parentId); + } + } + + private void deleteOrganizationIfExists(String orgId) throws Exception { + + if (orgId != null) { + orgMgtRestClient.deleteOrganization(orgId); + } + } + + // Helper methods. + + protected String toJSONString(java.lang.Object object) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); return gson.toJson(object); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index e4665a45d99..3c2fd6c85e3 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -73,10 +73,10 @@ */ public class UserSharingSuccessTest extends UserSharingBaseTest { - private final Map> userDetails = new HashMap<>(); - private final Map> orgDetails = new HashMap<>(); - private final Map> appDetails = new HashMap<>(); - private final Map> roleDetails = new HashMap<>(); +// private final Map> userDetails = new HashMap<>(); +// private final Map> orgDetails = new HashMap<>(); +// private final Map> appDetails = new HashMap<>(); +// private final Map> roleDetails = new HashMap<>(); @Factory(dataProvider = "restAPIUserConfigProvider") public UserSharingSuccessTest(TestUserMode userMode) throws Exception { @@ -93,6 +93,7 @@ public UserSharingSuccessTest(TestUserMode userMode) throws Exception { public void init() throws Exception { super.testInit(API_VERSION, swaggerDefinition, tenant); + setupDetailMaps(); setupRestClients(); setupOrganizations(); setupApplicationsAndRoles(); @@ -763,20 +764,16 @@ private Map setExpectedUnsharedResultsForGeneralUserSharingTestC return expectedResults; } - // Helper Methods. + // Setup methods. - private String getOrgId(String orgName) { + private void setupDetailMaps() { - return getOrgId(orgDetails, orgName); + userDetails = new HashMap<>(); + orgDetails = new HashMap<>(); + appDetails = new HashMap<>(); + roleDetails = new HashMap<>(); } - private String getUserId(String userName, String userDomain) { - - return getUserId(userDetails, userName, userDomain); - } - - // Setup and cleanup methods. - private void setupRestClients() throws Exception { oAuth2RestClient = new OAuth2RestClient(serverURL, tenantInfo); @@ -800,31 +797,6 @@ private void setupOrganizations() throws Exception { addSubOrganization(L3_ORG_1_NAME, getOrgId(L2_ORG_1_NAME), 3); } - private String addOrganization(String orgName) throws Exception { - - String orgId = orgMgtRestClient.addOrganization(orgName); - setOrgDetails(orgName, orgId, ROOT_ORG_ID, 1); - return orgId; - } - - private String addSubOrganization(String orgName, String parentId, int orgLevel) throws Exception { - - String orgId = orgMgtRestClient.addSubOrganization(orgName, parentId); - setOrgDetails(orgName, orgId, parentId, orgLevel); - return orgId; - } - - private void setOrgDetails(String orgName, String orgId, String parentId, int orgLevel) throws Exception { - - Map orgDetail = new HashMap<>(); - orgDetail.put("orgName", orgName); - orgDetail.put("orgId", orgId); - orgDetail.put("parentOrgId", parentId); - orgDetail.put("orgSwitchToken", orgMgtRestClient.switchM2MToken(orgId)); - orgDetail.put("orgLevel", orgLevel); - orgDetails.put(orgName, orgDetail); - } - protected void setupApplicationsAndRoles() throws Exception { Map rootOrgOrganizationRoles = createOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); @@ -833,324 +805,14 @@ protected void setupApplicationsAndRoles() throws Exception { createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(rootOrgOrganizationRoles.keySet())); } - private Map createApplication(String appName, String audience, List roleNames) throws Exception{ - - Map createdAppDetails = new HashMap<>(); - String rootOrgAppName = appName + "/" + ROOT_ORG_NAME; - - ApplicationResponseModel application = addApplication(appName); - String appId = application.getId(); - OpenIDConnectConfiguration oidcConfig = oAuth2RestClient.getOIDCInboundDetails(appId); - String clientId = oidcConfig.getClientId(); - String clientSecret = oidcConfig.getClientSecret(); - Map roleIdsByName = new HashMap<>(); - - if (StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience)){ - - Audience appRoleAudience = new Audience(APPLICATION_AUDIENCE, appId); - for (String roleName : roleNames) { - RoleV2 appRole = new RoleV2(appRoleAudience, roleName, Collections.emptyList(), Collections.emptyList()); - String roleId = scim2RestClient.addV2Role(appRole); - roleIdsByName.put(roleName, roleId); - } - storeRoleDetails(APPLICATION_AUDIENCE, rootOrgAppName, roleIdsByName); - createdAppDetails.put("appAudience", APPLICATION_AUDIENCE); - - } else { - - switchApplicationAudience(appId, AssociatedRolesConfig.AllowedAudienceEnum.ORGANIZATION); - - for (String roleName: roleNames){ - String roleId = scim2RestClient.getRoleIdByName(roleName); - roleIdsByName.put(roleName, roleId); - } - createdAppDetails.put("appAudience", ORGANIZATION_AUDIENCE); - } - - // Mark roles and groups as requested claims for the app 2. - updateRequestedClaimsOfApp(appId, getClaimConfigurationsWithRolesAndGroups()); - shareApplication(appId); - - // Get sub org details of Applications. - Map appDetailsOfSubOrgs = new HashMap<>(); - for (Map.Entry> entry : orgDetails.entrySet()) { - String orgName = entry.getKey(); - Map orgDetail = entry.getValue(); - - Map appDetailsOfSubOrg = getAppDetailsOfSubOrg(appName, audience, roleNames, orgDetail); - appDetailsOfSubOrgs.put(orgName, appDetailsOfSubOrg); - } - - createdAppDetails.put("appName", appName); - createdAppDetails.put("appId", appId); - createdAppDetails.put("clientId", clientId); - createdAppDetails.put("clientSecret", clientSecret); - createdAppDetails.put("roleNames", roleNames); - createdAppDetails.put("roleIdsByName", roleIdsByName); - createdAppDetails.put("appDetailsOfSubOrgs", appDetailsOfSubOrgs); - - appDetails.put(appName, createdAppDetails); - return createdAppDetails; - } - - private Map getAppDetailsOfSubOrg(String appName, String audience, List roleNames, Map orgDetail) throws Exception { - - Map subOrgAppDetails = new HashMap<>(); - - String subOrgName = (String) orgDetail.get("orgName"); - String subOrgId = (String) orgDetail.get("orgId"); - String subOrgSwitchToken = (String) orgDetail.get("orgSwitchToken"); - String subOrgAppName = appName + "/" + subOrgName; - - String subOrgAppId = oAuth2RestClient.getAppIdUsingAppNameInOrganization(appName, subOrgSwitchToken); - - Map subOrgRoleIdsByName = StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience) ? - getSubOrgRoleIdsByName(roleNames, APPLICATION_AUDIENCE, subOrgAppName, subOrgAppId, subOrgSwitchToken) : - getSubOrgRoleIdsByName(roleNames,ORGANIZATION_AUDIENCE, subOrgName, subOrgId, subOrgSwitchToken); - - subOrgAppDetails.put("subOrgName", subOrgName); - subOrgAppDetails.put("appName", appName); - subOrgAppDetails.put("appId", subOrgAppId); - subOrgAppDetails.put("roleNames", roleNames); - subOrgAppDetails.put("roleIdsByName", subOrgRoleIdsByName); - subOrgAppDetails.put("appAudience", audience); - - return subOrgAppDetails; - } - - private Map getSubOrgRoleIdsByName(List roleNames, String audienceType, String audienceName, String audienceValue, String subOrgSwitchToken) throws Exception { - - Map roleIdsByName = new HashMap<>(); - for (String roleName : roleNames) { - String sharedAppRoleId = - scim2RestClient.getRoleIdByNameAndAudienceInSubOrg(roleName, audienceValue, subOrgSwitchToken); - roleIdsByName.put(roleName, sharedAppRoleId); - } - - if (StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audienceType)) { - storeRoleDetails(APPLICATION_AUDIENCE, audienceName, roleIdsByName); - } else { - storeRoleDetails(ORGANIZATION_AUDIENCE, audienceName, roleIdsByName); - } - - return roleIdsByName; - } - - private Map createOrganizationRoles(String orgName, List orgRoleNames) throws IOException { - - Map orgRoleIdsByName = new HashMap<>(); - for (String orgRoleName : orgRoleNames) { - RoleV2 orgRole = new RoleV2(null, orgRoleName, Collections.emptyList(), Collections.emptyList()); - String orgRoleId = scim2RestClient.addV2Role(orgRole); - orgRoleIdsByName.put(orgRoleName, orgRoleId); - } - - storeRoleDetails(ORGANIZATION_AUDIENCE, orgName, orgRoleIdsByName); - - return orgRoleIdsByName; - } - - private void storeRoleDetails(String audienceType, String audienceName, Map rolesOfAudience) { - - String key = StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audienceType) - ? APPLICATION_AUDIENCE - : ORGANIZATION_AUDIENCE; - - Map rolesMapOfAudienceType = new HashMap<>(); - rolesMapOfAudienceType.put(audienceName, rolesOfAudience); - - roleDetails.computeIfAbsent(key, k -> new HashMap<>()).putAll(rolesMapOfAudienceType); - } - private void setupUsers() throws Exception { - createUser(createUserObject(ROOT_ORG_USER_1_USERNAME, ROOT_ORG_NAME)); - createUser(createUserObject(ROOT_ORG_USER_2_USERNAME, ROOT_ORG_NAME)); - createUser(createUserObject(ROOT_ORG_USER_3_USERNAME, ROOT_ORG_NAME)); - - createSuborgUser(createUserObject(L1_ORG_1_USER_1_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); - createSuborgUser(createUserObject(L1_ORG_1_USER_2_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); - createSuborgUser(createUserObject(L1_ORG_1_USER_3_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); - } - - private String createUser(UserObject user) throws Exception{ - - String userId = scim2RestClient.createUser(user); - - Map userDetail = new HashMap<>(); - userDetail.put("username", user.getUserName()); - userDetail.put("userId", userId); - userDetail.put("isRootOrgUser", true); - userDetail.put("orgName", ROOT_ORG_NAME); - userDetail.put("orgId", ROOT_ORG_ID); - userDetail.put("orgLevel", 0); - - userDetails.put(user.getUserName(), userDetail); - return userId; - } - - private String createSuborgUser(UserObject user, String suborg) throws Exception{ - - String userId = scim2RestClient.createSubOrgUser(user, (String) orgDetails.get(suborg).get("orgSwitchToken")); - - Map userDetail = new HashMap<>(); - userDetail.put("username", user.getUserName()); - userDetail.put("userId", userId); - userDetail.put("isRootOrgUser", false); - userDetail.put("orgName", suborg); - userDetail.put("orgId", orgDetails.get(suborg).get("orgId")); - userDetail.put("orgLevel", orgDetails.get(suborg).get("orgLevel")); - - userDetails.put(user.getUserName(), userDetail); - return userId; - } - - private void deleteUserIfExists(String userId) throws Exception { - - if (userId != null) { - scim2RestClient.deleteUser(userId); - } - } - - private void deleteSubOrgUserIfExists(String userId, String organizationSwitchToken) throws Exception { - - if (userId != null) { - scim2RestClient.deleteSubOrgUser(userId, organizationSwitchToken); - } - } - - private void deleteRoleIfExists(String roleId) throws Exception { - - if (roleId != null) { - scim2RestClient.deleteV2Role(roleId); - } - } - - private void deleteApplicationIfExists(String appId) throws Exception { - - if (appId != null) { - oAuth2RestClient.deleteApplication(appId); - } - } - - private void deleteSubOrganizationIfExists(String orgId, String parentId) throws Exception { - - if (orgId != null) { - orgMgtRestClient.deleteSubOrganization(orgId, parentId); - } - } - - private void deleteOrganizationIfExists(String orgId) throws Exception { - - if (orgId != null) { - orgMgtRestClient.deleteOrganization(orgId); - } - } - - /** - * Clean up users by deleting them if they exist. - * - * @throws Exception If an error occurs while deleting the users. - */ - private void cleanUpUsers() throws Exception { - - for (Map.Entry> entry : userDetails.entrySet()) { - String userId = (String) entry.getValue().get("userId"); - String orgName = (String) entry.getValue().get("orgName"); - int orgLevel = (int) entry.getValue().get("orgLevel"); - - if(orgLevel==0) { - deleteUserIfExists(userId); - } else { - deleteSubOrgUserIfExists(userId, (String) orgDetails.get(orgName).get("orgSwitchToken")); - } - } - } - - /** - * Cleans up roles for the specified audiences if exists. - * Audiences will always be either ORGANIZATION_AUDIENCE or APPLICATION_AUDIENCE or both. - * - *

- * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are - * predefined in the test data providers. - *

- * @param audiences The audiences for which roles need to be cleaned up. - * @throws Exception If an error occurs during the cleanup process. - */ - @SuppressWarnings("unchecked") - private void cleanUpRoles(String... audiences) throws Exception { - - for(String audience : audiences) { - Map orgWiseRolesOfAudience = roleDetails.get(audience); - for (Map.Entry entry : orgWiseRolesOfAudience.entrySet()) { - String audienceName = entry.getKey(); - Map roles = (Map) entry.getValue(); - for (Map.Entry role : roles.entrySet()) { - String roleId = role.getValue(); - if(audienceName.contains(ROOT_ORG_NAME)) { - deleteRoleIfExists(roleId); - } - } - } - } - } - - /** - * Cleans up applications by deleting them if they exist. - * - * @throws Exception If an error occurs while deleting the applications. - */ - private void cleanUpApplications() throws Exception { - - for (Map.Entry> entry : appDetails.entrySet()) { - Map details = entry.getValue(); - deleteApplicationIfExists(details.get("appId").toString()); - } - } - - /** - * Cleans up organizations by deleting them from the deepest level to the root level. - * - * @throws Exception If an error occurs while deleting the organizations. - */ - private void cleanUpOrganizations() throws Exception { - // Determine the deepest organization level in the hierarchy - int maxDepth = orgDetails.values().stream() - .mapToInt(details -> (int) details.get("orgLevel")) - .max() - .orElse(1); - - // Delete organizations starting from the deepest level down to the root level - for (int level = maxDepth; level >= 1; level--) { - for (Map.Entry> entry : orgDetails.entrySet()) { - if ((int) entry.getValue().get("orgLevel") == level) { - deleteOrganization(entry.getKey(), entry.getValue()); - } - } - } - } - - private void deleteOrganization(String orgName, Map details) throws Exception { - String orgId = getOrgId(orgName); - String parentOrgId = (String) details.get("parentOrgId"); - - if ((int) details.get("orgLevel") > 1) { - deleteSubOrganizationIfExists(orgId, parentOrgId); - } else { - deleteOrganizationIfExists(orgId); - } - } - - /** - * Close the HTTP clients for OAuth2, SCIM2, and Organization Management. - * - * @throws IOException If an error occurred while closing the HTTP clients. - */ - private void closeRestClients() throws IOException { + createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_1_USERNAME, ROOT_ORG_NAME)); + createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_2_USERNAME, ROOT_ORG_NAME)); + createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_3_USERNAME, ROOT_ORG_NAME)); - oAuth2RestClient.closeHttpClient(); - scim2RestClient.closeHttpClient(); - orgMgtRestClient.closeHttpClient(); + createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_1_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); + createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_2_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); + createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_3_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); } } From 0d11b8a8cba4c2f917a0d723105ff8a7745bd40c Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 3 Mar 2025 11:04:58 +0530 Subject: [PATCH 17/39] cleanup detail maps after the completion of success tests. --- .../sharing/management/v1/UserSharingBaseTest.java | 11 +++++++++++ .../sharing/management/v1/UserSharingSuccessTest.java | 6 +----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 4409f6dc82c..00ff0d29ae7 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -629,6 +629,17 @@ protected void cleanUpOrganizations() throws Exception { } } + /** + * Cleans up the detail maps by clearing all entries. + */ + protected void cleanUpDetailMaps() { + + userDetails.clear(); + orgDetails.clear(); + appDetails.clear(); + roleDetails.clear(); + } + /** * Close the HTTP clients for OAuth2, SCIM2, and Organization Management. * diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 3c2fd6c85e3..31b009c018e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -73,11 +73,6 @@ */ public class UserSharingSuccessTest extends UserSharingBaseTest { -// private final Map> userDetails = new HashMap<>(); -// private final Map> orgDetails = new HashMap<>(); -// private final Map> appDetails = new HashMap<>(); -// private final Map> roleDetails = new HashMap<>(); - @Factory(dataProvider = "restAPIUserConfigProvider") public UserSharingSuccessTest(TestUserMode userMode) throws Exception { @@ -108,6 +103,7 @@ public void testConclude() throws Exception { cleanUpRoles(APPLICATION_AUDIENCE, ORGANIZATION_AUDIENCE); cleanUpApplications(); cleanUpOrganizations(); + cleanUpDetailMaps(); closeRestClients(); } From 5fd2d652dd78ef0f693c738f41b018fda2b60adc Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 3 Mar 2025 11:20:53 +0530 Subject: [PATCH 18/39] move request body building methods to BaseTest. --- .../management/v1/UserSharingBaseTest.java | 103 +++++++++++++++++- .../management/v1/UserSharingSuccessTest.java | 96 +--------------- 2 files changed, 100 insertions(+), 99 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 00ff0d29ae7..9fb55265bf5 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -27,10 +27,7 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpPut; import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.entity.StringEntity; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; @@ -47,10 +44,13 @@ import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.RequestedClaimConfiguration; import org.wso2.identity.integration.test.rest.api.server.common.RESTAPIServerTestBase; import org.wso2.identity.integration.test.rest.api.server.roles.v2.model.Audience; -import org.wso2.identity.integration.test.rest.api.server.roles.v2.model.Permission; import org.wso2.identity.integration.test.rest.api.server.roles.v2.model.RoleV2; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudienceAudience; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyUserCriteria; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareRequestBodyUserCriteria; import org.wso2.identity.integration.test.rest.api.user.common.model.Email; import org.wso2.identity.integration.test.rest.api.user.common.model.Name; import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; @@ -705,6 +705,101 @@ private void deleteOrganizationIfExists(String orgId) throws Exception { } } + // Methods to create request bodies for user sharing and unsharing. + + /** + * Creates a `UserShareRequestBodyUserCriteria` object with the given user IDs. + * + * @param userIds The list of user IDs to be included in the criteria. + * @return A `UserShareRequestBodyUserCriteria` object containing the specified user IDs. + */ + protected UserShareRequestBodyUserCriteria getUserCriteriaForBaseUserSharing(List userIds) { + + UserShareRequestBodyUserCriteria criteria = new UserShareRequestBodyUserCriteria(); + criteria.setUserIds(userIds); + return criteria; + } + + /** + * Creates a `UserUnshareRequestBodyUserCriteria` object with the given user IDs. + * + * @param userIds The list of user IDs to be included in the criteria. + * @return A `UserUnshareRequestBodyUserCriteria` object containing the specified user IDs. + */ + protected UserUnshareRequestBodyUserCriteria getUserCriteriaForBaseUserUnsharing(List userIds) { + + UserUnshareRequestBodyUserCriteria criteria = new UserUnshareRequestBodyUserCriteria(); + criteria.setUserIds(userIds); + return criteria; + } + + /** + * Converts a map of organization details into a list of `UserShareRequestBodyOrganizations` objects. + * + * @param organizations A map where the key is the organization name and the value is a map of organization details. + * @return A list of `UserShareRequestBodyOrganizations` objects. + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. + *

+ */ + @SuppressWarnings("unchecked") + protected List getOrganizationsForSelectiveUserSharing(Map> organizations) { + + List orgs = new ArrayList<>(); + + for (Map.Entry> entry : organizations.entrySet()) { + + Map orgDetails = entry.getValue(); + + UserShareRequestBodyOrganizations org = new UserShareRequestBodyOrganizations(); + org.setOrgId((String) orgDetails.get(MAP_KEY_SELECTIVE_ORG_ID)); + org.setPolicy((UserShareRequestBodyOrganizations.PolicyEnum) orgDetails.get(MAP_KEY_SELECTIVE_POLICY)); + org.setRoles((List) orgDetails.get(MAP_KEY_SELECTIVE_ROLES)); + + orgs.add(org); + } + return orgs; + } + + /** + * Retrieves the policy enum for general user sharing from the provided map. + * + * @param policyWithRoles A map containing the policy and roles for general user sharing. + * @return The policy enum for general user sharing. + */ + protected UserShareWithAllRequestBody.PolicyEnum getPolicyEnumForGeneralUserSharing(Map policyWithRoles) { + + return (UserShareWithAllRequestBody.PolicyEnum)policyWithRoles.get(MAP_KEY_GENERAL_POLICY) ; + } + + /** + * Retrieves the roles for general user sharing from the provided map. + * + * @param policyWithRoles A map containing the policy and roles for general user sharing. + * @return A list of `RoleWithAudience` objects representing the roles for general user sharing. + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. + *

+ */ + @SuppressWarnings("unchecked") + protected List getRolesForGeneralUserSharing(Map policyWithRoles) { + + return (List) policyWithRoles.get(MAP_KEY_GENERAL_ROLES); + } + + /** + * Retrieves the list of organization IDs from which the users are being selectively unshared. + * + * @param removingOrgIds The list of organization IDs to be removed. + * @return A list of organization IDs as strings. + */ + protected List getOrganizationsForSelectiveUserUnsharing(List removingOrgIds) { + + return removingOrgIds; + } + // Helper methods. protected String toJSONString(java.lang.Object object) { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 31b009c018e..9c564b03fa4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -19,7 +19,6 @@ package org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1; import io.restassured.response.Response; -import org.apache.commons.lang.StringUtils; import org.apache.http.HttpStatus; import org.json.JSONObject; import org.testng.annotations.AfterClass; @@ -28,26 +27,15 @@ import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationResponseModel; -import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.AssociatedRolesConfig; -import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration; -import org.wso2.identity.integration.test.rest.api.server.roles.v2.model.Audience; -import org.wso2.identity.integration.test.rest.api.server.roles.v2.model.RoleV2; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; -import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudienceAudience; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; -import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations; -import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyUserCriteria; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareRequestBody; -import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareRequestBodyUserCriteria; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareWithAllRequestBody; -import org.wso2.identity.integration.test.rest.api.user.common.model.UserObject; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; import org.wso2.identity.integration.test.restclients.SCIM2RestClient; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -292,7 +280,7 @@ public void testSelectiveUserUnsharing(List userIds, UserUnshareRequestBody requestBody = new UserUnshareRequestBody() .userCriteria(getUserCriteriaForBaseUserUnsharing(userIds)) - .organizations(removingOrgIds); + .organizations(getOrganizationsForSelectiveUserUnsharing(removingOrgIds)); Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + UNSHARE_PATH, toJSONString(requestBody)); @@ -406,88 +394,6 @@ public void testGetSharedRolesForOrg(String userId, String orgId, List userIds) { - - UserShareRequestBodyUserCriteria criteria = new UserShareRequestBodyUserCriteria(); - criteria.setUserIds(userIds); - return criteria; - } - - /** - * Creates a `UserUnshareRequestBodyUserCriteria` object with the given user IDs. - * - * @param userIds The list of user IDs to be included in the criteria. - * @return A `UserUnshareRequestBodyUserCriteria` object containing the specified user IDs. - */ - private UserUnshareRequestBodyUserCriteria getUserCriteriaForBaseUserUnsharing(List userIds) { - - UserUnshareRequestBodyUserCriteria criteria = new UserUnshareRequestBodyUserCriteria(); - criteria.setUserIds(userIds); - return criteria; - } - - /** - * Converts a map of organization details into a list of `UserShareRequestBodyOrganizations` objects. - * - * @param organizations A map where the key is the organization name and the value is a map of organization details. - * @return A list of `UserShareRequestBodyOrganizations` objects. - *

- * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are - * predefined in the test data providers. - *

- */ - @SuppressWarnings("unchecked") - private List getOrganizationsForSelectiveUserSharing(Map> organizations) { - - List orgs = new ArrayList<>(); - - for (Map.Entry> entry : organizations.entrySet()) { - - Map orgDetails = entry.getValue(); - - UserShareRequestBodyOrganizations org = new UserShareRequestBodyOrganizations(); - org.setOrgId((String) orgDetails.get(MAP_KEY_SELECTIVE_ORG_ID)); - org.setPolicy((UserShareRequestBodyOrganizations.PolicyEnum) orgDetails.get(MAP_KEY_SELECTIVE_POLICY)); - org.setRoles((List) orgDetails.get(MAP_KEY_SELECTIVE_ROLES)); - - orgs.add(org); - } - return orgs; - } - - /** - * Retrieves the policy enum for general user sharing from the provided map. - * - * @param policyWithRoles A map containing the policy and roles for general user sharing. - * @return The policy enum for general user sharing. - */ - private UserShareWithAllRequestBody.PolicyEnum getPolicyEnumForGeneralUserSharing(Map policyWithRoles) { - - return (UserShareWithAllRequestBody.PolicyEnum)policyWithRoles.get(MAP_KEY_GENERAL_POLICY) ; - } - - /** - * Retrieves the roles for general user sharing from the provided map. - * - * @param policyWithRoles A map containing the policy and roles for general user sharing. - * @return A list of `RoleWithAudience` objects representing the roles for general user sharing. - *

- * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are - * predefined in the test data providers. - *

- */ - @SuppressWarnings("unchecked") - private List getRolesForGeneralUserSharing(Map policyWithRoles) { - - return (List) policyWithRoles.get(MAP_KEY_GENERAL_ROLES); - } - // Test cases builders for selective user sharing. private Map> setOrganizationsForSelectiveUserSharingTestCase1() { From 6a91afbb51c07c95e9ca08266866e49c45721e97 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 3 Mar 2025 11:29:34 +0530 Subject: [PATCH 19/39] introduce failure class. --- .../management/v1/UserSharingFaliureTest.java | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFaliureTest.java diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFaliureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFaliureTest.java new file mode 100644 index 00000000000..8dd7471257b --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFaliureTest.java @@ -0,0 +1,118 @@ +package org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1; + +import org.json.JSONObject; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Factory; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.identity.integration.test.restclients.OAuth2RestClient; +import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; +import org.wso2.identity.integration.test.restclients.SCIM2RestClient; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +/** + * Tests for failure cases of the User Sharing REST APIs. + */ +public class UserSharingFaliureTest extends UserSharingBaseTest { + + @Factory(dataProvider = "restAPIUserConfigProvider") + public UserSharingFaliureTest(TestUserMode userMode) throws Exception { + + super.init(userMode); + this.context = isServer; + this.authenticatingUserName = context.getContextTenant().getTenantAdmin().getUserName(); + this.authenticatingCredential = context.getContextTenant().getTenantAdmin().getPassword(); + this.tenant = context.getContextTenant().getDomain(); + } + + @Override + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + + super.testInit(API_VERSION, swaggerDefinition, tenant); + setupDetailMaps(); + setupRestClients(); + setupOrganizations(); + setupApplicationsAndRoles(); + setupUsers(); + } + + @Override + @AfterClass(alwaysRun = true) + public void testConclude() throws Exception { + + cleanUpUsers(); + cleanUpRoles(APPLICATION_AUDIENCE, ORGANIZATION_AUDIENCE); + cleanUpApplications(); + cleanUpOrganizations(); + cleanUpDetailMaps(); + closeRestClients(); + } + + @DataProvider(name = "restAPIUserConfigProvider") + public static Object[][] restAPIUserConfigProvider() { + + return new Object[][]{ + {TestUserMode.SUPER_TENANT_ADMIN}, + {TestUserMode.TENANT_ADMIN} + }; + } + + + // Setup methods. + + private void setupDetailMaps() { + + userDetails = new HashMap<>(); + orgDetails = new HashMap<>(); + appDetails = new HashMap<>(); + roleDetails = new HashMap<>(); + } + + private void setupRestClients() throws Exception { + + oAuth2RestClient = new OAuth2RestClient(serverURL, tenantInfo); + scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); + orgMgtRestClient = new OrgMgtRestClient(context, tenantInfo, serverURL, new JSONObject(readResource(AUTHORIZED_APIS_JSON))); + } + + private void setupOrganizations() throws Exception { + + // Create Level 1 Organizations + addOrganization(L1_ORG_1_NAME); + addOrganization(L1_ORG_2_NAME); + addOrganization(L1_ORG_3_NAME); + + // Create Level 2 Organizations + addSubOrganization(L2_ORG_1_NAME, getOrgId(L1_ORG_1_NAME), 2); + addSubOrganization(L2_ORG_2_NAME, getOrgId(L1_ORG_1_NAME), 2); + addSubOrganization(L2_ORG_3_NAME, getOrgId(L1_ORG_2_NAME), 2); + + // Create Level 3 Organization + addSubOrganization(L3_ORG_1_NAME, getOrgId(L2_ORG_1_NAME), 3); + } + + protected void setupApplicationsAndRoles() throws Exception { + + Map rootOrgOrganizationRoles = createOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); + + createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); + createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(rootOrgOrganizationRoles.keySet())); + } + + private void setupUsers() throws Exception { + + createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_1_USERNAME, ROOT_ORG_NAME)); + createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_2_USERNAME, ROOT_ORG_NAME)); + createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_3_USERNAME, ROOT_ORG_NAME)); + + createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_1_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); + createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_2_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); + createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_3_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); + } +} From 1e7824351f0f726f99cbe44ba97297430b8e7c35 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Mon, 3 Mar 2025 11:32:23 +0530 Subject: [PATCH 20/39] introduce failure class - rename typo. --- ...serSharingFaliureTest.java => UserSharingFailureTest.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/{UserSharingFaliureTest.java => UserSharingFailureTest.java} (97%) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFaliureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java similarity index 97% rename from modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFaliureTest.java rename to modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 8dd7471257b..2fc26a576e1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFaliureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -18,10 +18,10 @@ /** * Tests for failure cases of the User Sharing REST APIs. */ -public class UserSharingFaliureTest extends UserSharingBaseTest { +public class UserSharingFailureTest extends UserSharingBaseTest { @Factory(dataProvider = "restAPIUserConfigProvider") - public UserSharingFaliureTest(TestUserMode userMode) throws Exception { + public UserSharingFailureTest(TestUserMode userMode) throws Exception { super.init(userMode); this.context = isServer; From fecbbef809f1d8de0f7f26874551d734ee05f7d3 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Tue, 4 Mar 2025 11:47:56 +0530 Subject: [PATCH 21/39] intrduce constants to validation strings. --- .../management/v1/UserSharingBaseTest.java | 260 ++++++++++++------ .../management/v1/UserSharingFailureTest.java | 18 ++ .../management/v1/UserSharingSuccessTest.java | 56 ++-- 3 files changed, 219 insertions(+), 115 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 9fb55265bf5..96e91b28ae7 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -89,6 +89,7 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { static final String API_VERSION = "v1"; private static final String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1"; + static final String SERVER_URL_VERSION = "/api/server/v1"; static final String USER_SHARING_API_BASE_PATH = "/users"; static final String SHARE_PATH = "/share"; static final String SHARE_WITH_ALL_PATH = "/share-with-all"; @@ -97,6 +98,14 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { static final String SHARED_ORGANIZATIONS_PATH = "/shared-organizations"; static final String SHARED_ROLES_PATH = "/shared-roles"; + static final String PATH_SEPARATOR = "/"; + static final String QUERY_PARAM_SEPARATOR = "?"; + static final String QUERY_PARAM_VALUE_SEPARATOR = "="; + + protected static final String SHARED_TYPE_SHARED = "SHARED"; + protected static final String SHARED_TYPE_OWNER = "OWNER"; + protected static final String SHARED_TYPE_INVITED = "INVITED"; + protected static final String PATH_PARAM_USER_ID = "userId"; protected static final String QUERY_PARAM_ORG_ID = "orgId"; protected static final String QUERY_PARAM_LIMIT = "limit"; @@ -141,19 +150,7 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String L1_ORG_1_USER_1_USERNAME = "l1Org1User1"; protected static final String L1_ORG_1_USER_2_USERNAME = "l1Org1User2"; protected static final String L1_ORG_1_USER_3_USERNAME = "l1Org1User3"; - - protected static final String API_SCOPE_INTERNAL_USER_SHARE = "internal_user_share"; - protected static final String API_SCOPE_INTERNAL_USER_UNSHARE = "internal_user_unshare"; - protected static final String API_SCOPE_INTERNAL_USER_SHARED_ACCESS_VIEW = "internal_user_shared_access_view"; - protected static final String API_SCOPE_INTERNAL_ORG_USER_SHARE = "internal_org_user_share"; - protected static final String API_SCOPE_INTERNAL_ORG_USER_UNSHARE = "internal_org_user_unshare"; - protected static final String API_SCOPE_INTERNAL_ORG_USER_SHARED_ACCESS_VIEW = "internal_org_user_shared_access_view"; - - protected static final String EMAIL_CLAIM_URI = "http://wso2.org/claims/emailaddress"; - protected static final String COUNTRY_CLAIM_URI = "http://wso2.org/claims/country"; - protected static final String ROLES_CLAIM_URI = "http://wso2.org/claims/roles"; - protected static final String GROUPS_CLAIM_URI = "http://wso2.org/claims/groups"; - + protected static final String MAP_KEY_SELECTIVE_ORG_ID = "orgId"; protected static final String MAP_KEY_SELECTIVE_ORG_NAME = "orgName"; protected static final String MAP_KEY_SELECTIVE_POLICY = "selectivePolicy"; @@ -166,12 +163,86 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String MAP_KEY_EXPECTED_ORG_IDS = "expectedOrgIds"; protected static final String MAP_KEY_EXPECTED_ORG_NAMES = "expectedOrgNames"; protected static final String MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG = "expectedRolesPerExpectedOrg"; + + protected static final String MAP_ORG_DETAILS_KEY_ORG_NAME = "orgName"; + protected static final String MAP_ORG_DETAILS_KEY_ORG_ID = "orgId"; + protected static final String MAP_ORG_DETAILS_KEY_PARENT_ORG_ID = "parentOrgId"; + protected static final String MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN = "orgSwitchToken"; + protected static final String MAP_ORG_DETAILS_KEY_ORG_LEVEL = "orgLevel"; + + protected static final String MAP_APP_DETAILS_KEY_APP_NAME = "appName"; + protected static final String MAP_APP_DETAILS_KEY_APP_ID = "appId"; + protected static final String MAP_APP_DETAILS_KEY_APP_AUDIENCE = "appAudience"; + protected static final String MAP_APP_DETAILS_KEY_CLIENT_ID = "clientId"; + protected static final String MAP_APP_DETAILS_KEY_CLIENT_SECRET = "clientSecret"; + protected static final String MAP_APP_DETAILS_KEY_ROLE_NAMES = "roleNames"; + protected static final String MAP_APP_DETAILS_KEY_ROLE_IDS_BY_NAME = "roleIdsByName"; + protected static final String MAP_APP_DETAILS_KEY_APP_DETAILS_OF_SUB_ORGS = "appDetailsOfSubOrgs"; + protected static final String MAP_APP_DETAILS_KEY_APP_SUB_ORG_NAME = "subOrgName"; + + protected static final String MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME = "domainQualifiedUserName"; + protected static final String MAP_USER_DETAILS_KEY_USER_NAME = "userName"; + protected static final String MAP_USER_DETAILS_KEY_USER_ID = "userId"; + protected static final String MAP_USER_DETAILS_KEY_USER_DOMAIN = "userDomain"; + protected static final String MAP_USER_DETAILS_KEY_USER_ORG_NAME = "userOrgName"; + protected static final String MAP_USER_DETAILS_KEY_USER_ORG_ID = "userOrgId"; + protected static final String MAP_USER_DETAILS_KEY_USER_ORG_LEVEL = "userOrgLevel"; + protected static final String MAP_USER_DETAILS_KEY_IS_ROOT_ORG_USER = "isRootOrgUser"; + + protected static final String MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME = "userName"; + protected static final String MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN = "userDomain"; + + protected static final String SCOPE_INTERNAL_USER_SHARE = "internal_user_share"; + protected static final String SCOPE_INTERNAL_USER_UNSHARE = "internal_user_unshare"; + protected static final String SCOPE_INTERNAL_USER_SHARED_ACCESS_VIEW = "internal_user_shared_access_view"; + protected static final String SCOPE_INTERNAL_ORG_USER_SHARE = "internal_org_user_share"; + protected static final String SCOPE_INTERNAL_ORG_USER_UNSHARE = "internal_org_user_unshare"; + protected static final String SCOPE_INTERNAL_ORG_USER_SHARED_ACCESS_VIEW = "internal_org_user_shared_access_view"; + + protected static final String GRANT_AUTHORIZATION_CODE = "authorization_code"; + protected static final String GRANT_IMPLICIT = "implicit"; + protected static final String GRANT_PASSWORD = "password"; + protected static final String GRANT_CLIENT_CREDENTIALS = "client_credentials"; + protected static final String GRANT_REFRESH_TOKEN = "refresh_token"; + protected static final String GRANT_ORGANIZATION_SWITCH = "organization_switch"; + + protected static final String CLAIM_EMAIL_URI = "http://wso2.org/claims/emailaddress"; + protected static final String CLAIM_COUNTRY_URI = "http://wso2.org/claims/country"; + protected static final String CLAIM_ROLES_URI = "http://wso2.org/claims/roles"; + protected static final String CLAIM_GROUPS_URI = "http://wso2.org/claims/groups"; + + protected static final String ATTRIBUTE_USER_PASSWORD = "Admin123"; + protected static final String ATTRIBUTE_USER_EMAIL_DOMAIN = "@gmail.com"; + protected static final String ATTRIBUTE_USER_SCHEMA_SCIM2_USER = "urn:ietf:params:scim:schemas:core:2.0:User"; + + protected static final String RESPONSE_STATUS = "status"; + protected static final String RESPONSE_DETAILS = "details"; + protected static final String RESPONSE_STATUS_VALUE = "Processing"; + protected static final String RESPONSE_DETAIL_VALUE_SHARING = "User sharing process triggered successfully."; + protected static final String RESPONSE_DETAIL_VALUE_UNSHARING = "User unsharing process triggered successfully."; + + protected static final String RESPONSE_LINKS_SIZE = "links.size()"; + protected static final String RESPONSE_LINKS_EMPTY = "links[0].isEmpty()"; + protected static final String RESPONSE_LINKS_SHARED_ORGS = "sharedOrganizations"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_SIZE = "sharedOrganizations.size()"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_ID = "sharedOrganizations.orgId"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_NAME = "sharedOrganizations.orgName"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_SHARED_USER_ID = "sharedOrganizations.sharedUserId"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_SHARED_TYPE = "sharedOrganizations.sharedType"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_REF = "sharedOrganizations.rolesRef"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES = "roles"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_SIZE = "roles.size()"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_NAME = "roles.displayName"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_NAME = "roles.audience.display"; + protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_TYPE = "roles.audience.type"; + + protected static final String ERROR_SETUP_SWAGGER_DEFINITION = "Unable to read the swagger definition %s from %s"; static { try { swaggerDefinition = getAPISwaggerDefinition(API_PACKAGE_NAME, API_DEFINITION_NAME); } catch (IOException e) { - Assert.fail(String.format("Unable to read the swagger definition %s from %s", API_DEFINITION_NAME, API_PACKAGE_NAME), e); + Assert.fail(String.format(ERROR_SETUP_SWAGGER_DEFINITION, API_DEFINITION_NAME, API_PACKAGE_NAME), e); } } @@ -228,17 +299,17 @@ protected String addSubOrganization(String orgName, String parentId, int orgLeve protected String getOrgId(String orgName) { - return orgDetails.get(orgName).get("orgId").toString(); + return orgDetails.get(orgName).get(MAP_ORG_DETAILS_KEY_ORG_ID).toString(); } protected void setOrgDetails(String orgName, String orgId, String parentId, int orgLevel) throws Exception { Map orgDetail = new HashMap<>(); - orgDetail.put("orgName", orgName); - orgDetail.put("orgId", orgId); - orgDetail.put("parentOrgId", parentId); - orgDetail.put("orgSwitchToken", orgMgtRestClient.switchM2MToken(orgId)); - orgDetail.put("orgLevel", orgLevel); + orgDetail.put(MAP_ORG_DETAILS_KEY_ORG_NAME, orgName); + orgDetail.put(MAP_ORG_DETAILS_KEY_ORG_ID, orgId); + orgDetail.put(MAP_ORG_DETAILS_KEY_PARENT_ORG_ID, parentId); + orgDetail.put(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN, orgMgtRestClient.switchM2MToken(orgId)); + orgDetail.put(MAP_ORG_DETAILS_KEY_ORG_LEVEL, orgLevel); orgDetails.put(orgName, orgDetail); } @@ -247,7 +318,7 @@ protected void setOrgDetails(String orgName, String orgId, String parentId, int protected Map createApplication(String appName, String audience, List roleNames) throws Exception{ Map createdAppDetails = new HashMap<>(); - String rootOrgAppName = appName + "/" + ROOT_ORG_NAME; + String rootOrgAppName = appName + PATH_SEPARATOR + ROOT_ORG_NAME; ApplicationResponseModel application = addApplication(appName); String appId = application.getId(); @@ -265,7 +336,7 @@ protected Map createApplication(String appName, String audience, roleIdsByName.put(roleName, roleId); } storeRoleDetails(APPLICATION_AUDIENCE, rootOrgAppName, roleIdsByName); - createdAppDetails.put("appAudience", APPLICATION_AUDIENCE); + createdAppDetails.put(MAP_APP_DETAILS_KEY_APP_AUDIENCE, APPLICATION_AUDIENCE); } else { @@ -275,7 +346,7 @@ protected Map createApplication(String appName, String audience, String roleId = scim2RestClient.getRoleIdByName(roleName); roleIdsByName.put(roleName, roleId); } - createdAppDetails.put("appAudience", ORGANIZATION_AUDIENCE); + createdAppDetails.put(MAP_APP_DETAILS_KEY_APP_AUDIENCE, ORGANIZATION_AUDIENCE); } // Mark roles and groups as requested claims for the app 2. @@ -292,13 +363,13 @@ protected Map createApplication(String appName, String audience, appDetailsOfSubOrgs.put(orgName, appDetailsOfSubOrg); } - createdAppDetails.put("appName", appName); - createdAppDetails.put("appId", appId); - createdAppDetails.put("clientId", clientId); - createdAppDetails.put("clientSecret", clientSecret); - createdAppDetails.put("roleNames", roleNames); - createdAppDetails.put("roleIdsByName", roleIdsByName); - createdAppDetails.put("appDetailsOfSubOrgs", appDetailsOfSubOrgs); + createdAppDetails.put(MAP_APP_DETAILS_KEY_APP_NAME, appName); + createdAppDetails.put(MAP_APP_DETAILS_KEY_APP_ID, appId); + createdAppDetails.put(MAP_APP_DETAILS_KEY_CLIENT_ID, clientId); + createdAppDetails.put(MAP_APP_DETAILS_KEY_CLIENT_SECRET, clientSecret); + createdAppDetails.put(MAP_APP_DETAILS_KEY_ROLE_NAMES, roleNames); + createdAppDetails.put(MAP_APP_DETAILS_KEY_ROLE_IDS_BY_NAME, roleIdsByName); + createdAppDetails.put(MAP_APP_DETAILS_KEY_APP_DETAILS_OF_SUB_ORGS, appDetailsOfSubOrgs); appDetails.put(appName, createdAppDetails); return createdAppDetails; @@ -308,10 +379,10 @@ protected Map getAppDetailsOfSubOrg(String appName, String audie Map subOrgAppDetails = new HashMap<>(); - String subOrgName = (String) orgDetail.get("orgName"); - String subOrgId = (String) orgDetail.get("orgId"); - String subOrgSwitchToken = (String) orgDetail.get("orgSwitchToken"); - String subOrgAppName = appName + "/" + subOrgName; + String subOrgName = (String) orgDetail.get(MAP_ORG_DETAILS_KEY_ORG_NAME); + String subOrgId = (String) orgDetail.get(MAP_ORG_DETAILS_KEY_ORG_ID); + String subOrgSwitchToken = (String) orgDetail.get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN); + String subOrgAppName = appName + PATH_SEPARATOR + subOrgName; String subOrgAppId = oAuth2RestClient.getAppIdUsingAppNameInOrganization(appName, subOrgSwitchToken); @@ -319,12 +390,12 @@ protected Map getAppDetailsOfSubOrg(String appName, String audie getSubOrgRoleIdsByName(roleNames, APPLICATION_AUDIENCE, subOrgAppName, subOrgAppId, subOrgSwitchToken) : getSubOrgRoleIdsByName(roleNames,ORGANIZATION_AUDIENCE, subOrgName, subOrgId, subOrgSwitchToken); - subOrgAppDetails.put("subOrgName", subOrgName); - subOrgAppDetails.put("appName", appName); - subOrgAppDetails.put("appId", subOrgAppId); - subOrgAppDetails.put("roleNames", roleNames); - subOrgAppDetails.put("roleIdsByName", subOrgRoleIdsByName); - subOrgAppDetails.put("appAudience", audience); + subOrgAppDetails.put(MAP_APP_DETAILS_KEY_APP_SUB_ORG_NAME, subOrgName); + subOrgAppDetails.put(MAP_APP_DETAILS_KEY_APP_NAME, appName); + subOrgAppDetails.put(MAP_APP_DETAILS_KEY_APP_ID, subOrgAppId); + subOrgAppDetails.put(MAP_APP_DETAILS_KEY_ROLE_NAMES, roleNames); + subOrgAppDetails.put(MAP_APP_DETAILS_KEY_ROLE_IDS_BY_NAME, subOrgRoleIdsByName); + subOrgAppDetails.put(MAP_APP_DETAILS_KEY_APP_AUDIENCE, audience); return subOrgAppDetails; } @@ -376,7 +447,7 @@ protected RoleWithAudience createRoleWithAudience(String roleName, String displa protected String getSharedOrgsRolesRef(String userId, String orgId) { - return "/api/server/v1" + USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH + "?orgId=" + orgId; + return SERVER_URL_VERSION + USER_SHARING_API_BASE_PATH + PATH_SEPARATOR + userId + SHARED_ROLES_PATH + QUERY_PARAM_SEPARATOR + QUERY_PARAM_ORG_ID + QUERY_PARAM_VALUE_SEPARATOR + orgId; } protected void storeRoleDetails(String audienceType, String audienceName, Map rolesOfAudience) { @@ -396,7 +467,7 @@ private ApplicationResponseModel addApplication(String appName) throws Exception ApplicationModel application = new ApplicationModel(); List grantTypes = new ArrayList<>(); - Collections.addAll(grantTypes, "authorization_code", "implicit", "password", "client_credentials", "refresh_token", "organization_switch"); + Collections.addAll(grantTypes, GRANT_AUTHORIZATION_CODE, GRANT_IMPLICIT, GRANT_PASSWORD, GRANT_CLIENT_CREDENTIALS, GRANT_REFRESH_TOKEN, GRANT_ORGANIZATION_SWITCH); List callBackUrls = new ArrayList<>(); Collections.addAll(callBackUrls, OAuth2Constant.CALLBACK_URL); @@ -420,15 +491,15 @@ private ApplicationResponseModel addApplication(String appName) throws Exception private ClaimConfiguration setApplicationClaimConfig() { - ClaimMappings emailClaim = new ClaimMappings().applicationClaim(EMAIL_CLAIM_URI); - emailClaim.setLocalClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(EMAIL_CLAIM_URI)); - ClaimMappings countryClaim = new ClaimMappings().applicationClaim(COUNTRY_CLAIM_URI); - countryClaim.setLocalClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(COUNTRY_CLAIM_URI)); + ClaimMappings emailClaim = new ClaimMappings().applicationClaim(CLAIM_EMAIL_URI); + emailClaim.setLocalClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(CLAIM_EMAIL_URI)); + ClaimMappings countryClaim = new ClaimMappings().applicationClaim(CLAIM_COUNTRY_URI); + countryClaim.setLocalClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(CLAIM_COUNTRY_URI)); RequestedClaimConfiguration emailRequestedClaim = new RequestedClaimConfiguration(); - emailRequestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(EMAIL_CLAIM_URI)); + emailRequestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(CLAIM_EMAIL_URI)); RequestedClaimConfiguration countryRequestedClaim = new RequestedClaimConfiguration(); - countryRequestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(COUNTRY_CLAIM_URI)); + countryRequestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(CLAIM_COUNTRY_URI)); ClaimConfiguration claimConfiguration = new ClaimConfiguration().dialect(ClaimConfiguration.DialectEnum.CUSTOM); claimConfiguration.addClaimMappingsItem(emailClaim); @@ -442,8 +513,8 @@ private ClaimConfiguration setApplicationClaimConfig() { private ClaimConfiguration getClaimConfigurationsWithRolesAndGroups() { ClaimConfiguration claimConfiguration = new ClaimConfiguration(); - claimConfiguration.addRequestedClaimsItem(getRequestedClaim(ROLES_CLAIM_URI)); - claimConfiguration.addRequestedClaimsItem(getRequestedClaim(GROUPS_CLAIM_URI)); + claimConfiguration.addRequestedClaimsItem(getRequestedClaim(CLAIM_ROLES_URI)); + claimConfiguration.addRequestedClaimsItem(getRequestedClaim(CLAIM_GROUPS_URI)); return claimConfiguration; } @@ -486,20 +557,20 @@ private void shareApplication(String applicationId) throws Exception { protected UserObject createUserObject(String userDomain, String userName, String orgName) { - String domainQualifiedUserName = userDomain + "/" + userName; + String domainQualifiedUserName = userDomain + PATH_SEPARATOR + userName; UserObject user = new UserObject() .userName(domainQualifiedUserName) - .password("Admin123") + .password(ATTRIBUTE_USER_PASSWORD) .name(new Name().givenName(userName).familyName(orgName)) .emails(new ArrayList<>()); Email email = new Email(); - email.setValue(userName + "@gmail.com"); + email.setValue(userName + ATTRIBUTE_USER_EMAIL_DOMAIN); email.setPrimary(true); user.getEmails().add(email); List schemas = new ArrayList<>(); - schemas.add("urn:ietf:params:scim:schemas:core:2.0:User"); + schemas.add(ATTRIBUTE_USER_SCHEMA_SCIM2_USER); user.setSchemas(schemas); return user; @@ -508,39 +579,54 @@ protected UserObject createUserObject(String userDomain, String userName, String protected String createUser(UserObject user) throws Exception{ String userId = scim2RestClient.createUser(user); + String domainQualifiedUserName = user.getUserName(); Map userDetail = new HashMap<>(); - userDetail.put("username", user.getUserName()); - userDetail.put("userId", userId); - userDetail.put("isRootOrgUser", true); - userDetail.put("orgName", ROOT_ORG_NAME); - userDetail.put("orgId", ROOT_ORG_ID); - userDetail.put("orgLevel", 0); - - userDetails.put(user.getUserName(), userDetail); + userDetail.put(MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME, domainQualifiedUserName); + userDetail.put(MAP_USER_DETAILS_KEY_USER_NAME, getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME)); + userDetail.put(MAP_USER_DETAILS_KEY_USER_DOMAIN, getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN)); + userDetail.put(MAP_USER_DETAILS_KEY_USER_ID, userId); + userDetail.put(MAP_USER_DETAILS_KEY_IS_ROOT_ORG_USER, true); + userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_NAME, ROOT_ORG_NAME); + userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_ID, ROOT_ORG_ID); + userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_LEVEL, 0); + + userDetails.put(domainQualifiedUserName, userDetail); return userId; } protected String createSuborgUser(UserObject user, String suborg) throws Exception{ - String userId = scim2RestClient.createSubOrgUser(user, (String) orgDetails.get(suborg).get("orgSwitchToken")); + String userId = scim2RestClient.createSubOrgUser(user, (String) orgDetails.get(suborg).get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN)); + String domainQualifiedUserName = user.getUserName(); Map userDetail = new HashMap<>(); - userDetail.put("username", user.getUserName()); - userDetail.put("userId", userId); - userDetail.put("isRootOrgUser", false); - userDetail.put("orgName", suborg); - userDetail.put("orgId", orgDetails.get(suborg).get("orgId")); - userDetail.put("orgLevel", orgDetails.get(suborg).get("orgLevel")); - - userDetails.put(user.getUserName(), userDetail); + userDetail.put(MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME, domainQualifiedUserName); + userDetail.put(MAP_USER_DETAILS_KEY_USER_NAME, getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME)); + userDetail.put(MAP_USER_DETAILS_KEY_USER_DOMAIN, getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN)); + userDetail.put(MAP_USER_DETAILS_KEY_USER_ID, userId); + userDetail.put(MAP_USER_DETAILS_KEY_IS_ROOT_ORG_USER, false); + userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_NAME, suborg); + userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_ID, orgDetails.get(suborg).get(MAP_ORG_DETAILS_KEY_ORG_ID)); + userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_LEVEL, orgDetails.get(suborg).get(MAP_ORG_DETAILS_KEY_ORG_LEVEL)); + + userDetails.put(domainQualifiedUserName, userDetail); return userId; } protected String getUserId(String userName, String userDomain) { - String domainQualifiedUserName = userDomain + "/" + userName; - return userDetails.get(domainQualifiedUserName).get("userId").toString(); + String domainQualifiedUserName = userDomain + PATH_SEPARATOR + userName; + return userDetails.get(domainQualifiedUserName).get(MAP_USER_DETAILS_KEY_USER_ID).toString(); + } + + private Map getUserNameAndUserDomain(String domainQualifiedUserName) { + + String[] parts = domainQualifiedUserName.split(PATH_SEPARATOR); + Map userNameAndUserDomain = new HashMap<>(); + userNameAndUserDomain.put(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME, parts[1]); + userNameAndUserDomain.put(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN, parts[0]); + return userNameAndUserDomain; } // Methods to clean up the resources created for testing purposes. @@ -553,14 +639,14 @@ protected String getUserId(String userName, String userDomain) { protected void cleanUpUsers() throws Exception { for (Map.Entry> entry : userDetails.entrySet()) { - String userId = (String) entry.getValue().get("userId"); - String orgName = (String) entry.getValue().get("orgName"); - int orgLevel = (int) entry.getValue().get("orgLevel"); + String userId = (String) entry.getValue().get(MAP_USER_DETAILS_KEY_USER_ID); + String orgName = (String) entry.getValue().get(MAP_USER_DETAILS_KEY_USER_ORG_NAME); + int orgLevel = (int) entry.getValue().get(MAP_USER_DETAILS_KEY_USER_ORG_LEVEL); if(orgLevel==0) { deleteUserIfExists(userId); } else { - deleteSubOrgUserIfExists(userId, (String) orgDetails.get(orgName).get("orgSwitchToken")); + deleteSubOrgUserIfExists(userId, (String) orgDetails.get(orgName).get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN)); } } } @@ -603,7 +689,7 @@ protected void cleanUpApplications() throws Exception { for (Map.Entry> entry : appDetails.entrySet()) { Map details = entry.getValue(); - deleteApplicationIfExists(details.get("appId").toString()); + deleteApplicationIfExists(details.get(MAP_APP_DETAILS_KEY_APP_ID).toString()); } } @@ -615,14 +701,14 @@ protected void cleanUpApplications() throws Exception { protected void cleanUpOrganizations() throws Exception { // Determine the deepest organization level in the hierarchy int maxDepth = orgDetails.values().stream() - .mapToInt(details -> (int) details.get("orgLevel")) + .mapToInt(details -> (int) details.get(MAP_ORG_DETAILS_KEY_ORG_LEVEL)) .max() .orElse(1); // Delete organizations starting from the deepest level down to the root level for (int level = maxDepth; level >= 1; level--) { for (Map.Entry> entry : orgDetails.entrySet()) { - if ((int) entry.getValue().get("orgLevel") == level) { + if ((int) entry.getValue().get(MAP_ORG_DETAILS_KEY_ORG_LEVEL) == level) { deleteOrganization(entry.getKey(), entry.getValue()); } } @@ -652,11 +738,11 @@ protected void closeRestClients() throws IOException { orgMgtRestClient.closeHttpClient(); } - private void deleteOrganization(String orgName, Map details) throws Exception { + private void deleteOrganization(String orgName, Map orgDetail) throws Exception { String orgId = getOrgId(orgName); - String parentOrgId = (String) details.get("parentOrgId"); + String parentOrgId = (String) orgDetail.get(MAP_ORG_DETAILS_KEY_PARENT_ORG_ID); - if ((int) details.get("orgLevel") > 1) { + if ((int) orgDetail.get(MAP_ORG_DETAILS_KEY_ORG_LEVEL) > 1) { deleteSubOrganizationIfExists(orgId, parentOrgId); } else { deleteOrganizationIfExists(orgId); @@ -750,12 +836,12 @@ protected List getOrganizationsForSelectiveUs for (Map.Entry> entry : organizations.entrySet()) { - Map orgDetails = entry.getValue(); + Map orgDetail = entry.getValue(); UserShareRequestBodyOrganizations org = new UserShareRequestBodyOrganizations(); - org.setOrgId((String) orgDetails.get(MAP_KEY_SELECTIVE_ORG_ID)); - org.setPolicy((UserShareRequestBodyOrganizations.PolicyEnum) orgDetails.get(MAP_KEY_SELECTIVE_POLICY)); - org.setRoles((List) orgDetails.get(MAP_KEY_SELECTIVE_ROLES)); + org.setOrgId((String) orgDetail.get(MAP_KEY_SELECTIVE_ORG_ID)); + org.setPolicy((UserShareRequestBodyOrganizations.PolicyEnum) orgDetail.get(MAP_KEY_SELECTIVE_POLICY)); + org.setRoles((List) orgDetail.get(MAP_KEY_SELECTIVE_ROLES)); orgs.add(org); } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 2fc26a576e1..6327890482d 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1; import org.json.JSONObject; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 9c564b03fa4..3b96e1d053e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -138,10 +138,10 @@ public void testSelectiveUserSharing(List userIds, .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_ACCEPTED) - .body("status", equalTo("Processing")) - .body("details", equalTo("User sharing process triggered successfully.")); + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); - Thread.sleep(5000); + Thread.sleep(5000); // Waiting until user sharing is completed. for (String userId : userIds) { validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); } @@ -158,7 +158,7 @@ public Object[][] generalUserSharingDataProvider() { Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); // IMMEDIATE EXISTING AND FUTURE - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); @@ -196,10 +196,10 @@ public void testGeneralUserSharing(List userIds, .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_ACCEPTED) - .body("status", equalTo("Processing")) - .body("details", equalTo("User sharing process triggered successfully.")); + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); - Thread.sleep(5000); + Thread.sleep(5000); // Waiting until user sharing is completed. for (String userId : userIds) { validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); } @@ -235,10 +235,10 @@ public void testGeneralUserUnsharing(List userIds, .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_ACCEPTED) - .body("status", equalTo("Processing")) - .body("details", equalTo("User unsharing process triggered successfully.")); + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_UNSHARING)); - Thread.sleep(5000); + Thread.sleep(5000); // Waiting until user sharing is completed. for (String userId : userIds) { validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); } @@ -288,10 +288,10 @@ public void testSelectiveUserUnsharing(List userIds, .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_ACCEPTED) - .body("status", equalTo("Processing")) - .body("details", equalTo("User unsharing process triggered successfully.")); + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_UNSHARING)); - Thread.sleep(5000); + Thread.sleep(5000); // Waiting until user sharing is completed. for (String userId : userIds) { validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedUnsharedResults); } @@ -343,14 +343,14 @@ public void testGetSharedOrganizations(String userId, int expectedOrgCount, List .log().ifValidationFails() .assertThat() .statusCode(HttpStatus.SC_OK) - .body("links.size()", equalTo(1)) - .body("links[0].isEmpty()", equalTo(true)) - .body("sharedOrganizations", notNullValue()) - .body("sharedOrganizations.size()", equalTo(expectedOrgCount)) - .body("sharedOrganizations.orgId", hasItems(expectedOrgIds.toArray(new String[0]))) - .body("sharedOrganizations.orgName", hasItems(expectedOrgNames.toArray(new String[0]))) - .body("sharedOrganizations.sharedType", everyItem(equalTo("SHARED"))) - .body("sharedOrganizations.rolesRef", hasItems( + .body(RESPONSE_LINKS_SIZE, equalTo(1)) + .body(RESPONSE_LINKS_EMPTY, equalTo(true)) + .body(RESPONSE_LINKS_SHARED_ORGS, notNullValue()) + .body(RESPONSE_LINKS_SHARED_ORGS_SIZE, equalTo(expectedOrgCount)) + .body(RESPONSE_LINKS_SHARED_ORGS_ID, hasItems(expectedOrgIds.toArray(new String[0]))) + .body(RESPONSE_LINKS_SHARED_ORGS_NAME, hasItems(expectedOrgNames.toArray(new String[0]))) + .body(RESPONSE_LINKS_SHARED_ORGS_SHARED_TYPE, everyItem(equalTo(SHARED_TYPE_SHARED))) + .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_REF, hasItems( expectedOrgIds.stream() .map(orgId -> getSharedOrgsRolesRef(userId, orgId)) .toArray(String[]::new))); @@ -372,22 +372,22 @@ public void testGetSharedRolesForOrg(String userId, String orgId, List role.getAudience().getDisplay()) .toArray(String[]::new))) - .body("roles.audience.type", hasItems( + .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_TYPE, hasItems( expectedRoles.stream() .map(role -> role.getAudience().getType()) .toArray(String[]::new))); From a29febdee8bb3693dca2236764c2a420bed1f95b Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Tue, 4 Mar 2025 14:43:10 +0530 Subject: [PATCH 22/39] add failure tests to user selective sharing with invalid roles, orgs and users. --- .../management/v1/UserSharingBaseTest.java | 295 ++++++++++++------ .../management/v1/UserSharingFailureTest.java | 242 ++++++++++++++ .../management/v1/UserSharingSuccessTest.java | 97 ------ 3 files changed, 442 insertions(+), 192 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 96e91b28ae7..1ef5edebccb 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -21,8 +21,10 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import io.restassured.RestAssured; +import io.restassured.response.Response; import org.apache.commons.lang.StringUtils; import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; @@ -66,6 +68,10 @@ import java.util.List; import java.util.Map; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.everyItem; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.wso2.identity.integration.test.restclients.RestBaseClient.USER_AGENT_ATTRIBUTE; /** @@ -629,6 +635,200 @@ private Map getUserNameAndUserDomain(String domainQualifiedUserN return userNameAndUserDomain; } + // Method to validate user shared organizations and assigned roles. + + /** + * Validate that the user has been shared to the expected organizations with the expected roles. + * + * @param userId The ID of the user to validate. + * @param expectedResults A map containing the expected results, including the expected organization count, + * expected organization IDs, expected organization names, and expected roles per + * organization. + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. + *

+ */ + @SuppressWarnings("unchecked") + protected void validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(String userId, + Map expectedResults) { + + testGetSharedOrganizations( + userId, + (int) expectedResults.get(MAP_KEY_EXPECTED_ORG_COUNT), + (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_IDS), + (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_NAMES) + ); + + Map> expectedRolesPerExpectedOrg = (Map>) expectedResults.get(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG); + for (Map.Entry> entry : expectedRolesPerExpectedOrg.entrySet()) { + testGetSharedRolesForOrg(userId, entry.getKey(), entry.getValue()); + } + } + + /** + * Test method for GET /user-sharing/{userId}/shared-organizations. + * + * @param userId The ID of the user to get shared organizations for. + * @param expectedOrgCount The expected number of shared organizations. + * @param expectedOrgIds The expected IDs of the shared organizations. + * @param expectedOrgNames The expected names of the shared organizations. + */ + protected void testGetSharedOrganizations(String userId, int expectedOrgCount, List expectedOrgIds, List expectedOrgNames) { + + Response response = + getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ORGANIZATIONS_PATH); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body(RESPONSE_LINKS_SIZE, equalTo(1)) + .body(RESPONSE_LINKS_EMPTY, equalTo(true)) + .body(RESPONSE_LINKS_SHARED_ORGS, notNullValue()) + .body(RESPONSE_LINKS_SHARED_ORGS_SIZE, equalTo(expectedOrgCount)) + .body(RESPONSE_LINKS_SHARED_ORGS_ID, hasItems(expectedOrgIds.toArray(new String[0]))) + .body(RESPONSE_LINKS_SHARED_ORGS_NAME, hasItems(expectedOrgNames.toArray(new String[0]))) + .body(RESPONSE_LINKS_SHARED_ORGS_SHARED_TYPE, everyItem(equalTo(SHARED_TYPE_SHARED))) + .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_REF, hasItems( + expectedOrgIds.stream() + .map(orgId -> getSharedOrgsRolesRef(userId, orgId)) + .toArray(String[]::new))); + } + + /** + * Test method for GET /user-sharing/{userId}/shared-roles?orgId={orgId}. + * + * @param userId The ID of the user to get shared roles for. + * @param orgId The ID of the organization to get shared roles for. + * @param expectedRoles The expected roles for the user in the specified organization. + */ + protected void testGetSharedRolesForOrg(String userId, String orgId, List expectedRoles) { + + Response response = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH, + Collections.singletonMap(QUERY_PARAM_ORG_ID, orgId)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body(RESPONSE_LINKS_SIZE, equalTo(1)) + .body(RESPONSE_LINKS_EMPTY, equalTo(true)) + .body(RESPONSE_LINKS_SHARED_ORGS_ROLES, notNullValue()) + .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_SIZE, equalTo(expectedRoles.size())); + + if (!expectedRoles.isEmpty()) { + response.then() + .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_NAME, hasItems( + expectedRoles.stream() + .map(RoleWithAudience::getDisplayName) + .toArray(String[]::new))) + .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_NAME, hasItems( + expectedRoles.stream() + .map(role -> role.getAudience().getDisplay()) + .toArray(String[]::new))) + .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_TYPE, hasItems( + expectedRoles.stream() + .map(role -> role.getAudience().getType()) + .toArray(String[]::new))); + } + } + + // Methods to create request bodies for user sharing and unsharing. + + /** + * Creates a `UserShareRequestBodyUserCriteria` object with the given user IDs. + * + * @param userIds The list of user IDs to be included in the criteria. + * @return A `UserShareRequestBodyUserCriteria` object containing the specified user IDs. + */ + protected UserShareRequestBodyUserCriteria getUserCriteriaForBaseUserSharing(List userIds) { + + UserShareRequestBodyUserCriteria criteria = new UserShareRequestBodyUserCriteria(); + criteria.setUserIds(userIds); + return criteria; + } + + /** + * Creates a `UserUnshareRequestBodyUserCriteria` object with the given user IDs. + * + * @param userIds The list of user IDs to be included in the criteria. + * @return A `UserUnshareRequestBodyUserCriteria` object containing the specified user IDs. + */ + protected UserUnshareRequestBodyUserCriteria getUserCriteriaForBaseUserUnsharing(List userIds) { + + UserUnshareRequestBodyUserCriteria criteria = new UserUnshareRequestBodyUserCriteria(); + criteria.setUserIds(userIds); + return criteria; + } + + /** + * Converts a map of organization details into a list of `UserShareRequestBodyOrganizations` objects. + * + * @param organizations A map where the key is the organization name and the value is a map of organization details. + * @return A list of `UserShareRequestBodyOrganizations` objects. + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. + *

+ */ + @SuppressWarnings("unchecked") + protected List getOrganizationsForSelectiveUserSharing(Map> organizations) { + + List orgs = new ArrayList<>(); + + for (Map.Entry> entry : organizations.entrySet()) { + + Map orgDetail = entry.getValue(); + + UserShareRequestBodyOrganizations org = new UserShareRequestBodyOrganizations(); + org.setOrgId((String) orgDetail.get(MAP_KEY_SELECTIVE_ORG_ID)); + org.setPolicy((UserShareRequestBodyOrganizations.PolicyEnum) orgDetail.get(MAP_KEY_SELECTIVE_POLICY)); + org.setRoles((List) orgDetail.get(MAP_KEY_SELECTIVE_ROLES)); + + orgs.add(org); + } + return orgs; + } + + /** + * Retrieves the policy enum for general user sharing from the provided map. + * + * @param policyWithRoles A map containing the policy and roles for general user sharing. + * @return The policy enum for general user sharing. + */ + protected UserShareWithAllRequestBody.PolicyEnum getPolicyEnumForGeneralUserSharing(Map policyWithRoles) { + + return (UserShareWithAllRequestBody.PolicyEnum)policyWithRoles.get(MAP_KEY_GENERAL_POLICY) ; + } + + /** + * Retrieves the roles for general user sharing from the provided map. + * + * @param policyWithRoles A map containing the policy and roles for general user sharing. + * @return A list of `RoleWithAudience` objects representing the roles for general user sharing. + *

+ * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are + * predefined in the test data providers. + *

+ */ + @SuppressWarnings("unchecked") + protected List getRolesForGeneralUserSharing(Map policyWithRoles) { + + return (List) policyWithRoles.get(MAP_KEY_GENERAL_ROLES); + } + + /** + * Retrieves the list of organization IDs from which the users are being selectively unshared. + * + * @param removingOrgIds The list of organization IDs to be removed. + * @return A list of organization IDs as strings. + */ + protected List getOrganizationsForSelectiveUserUnsharing(List removingOrgIds) { + + return removingOrgIds; + } + // Methods to clean up the resources created for testing purposes. /** @@ -791,101 +991,6 @@ private void deleteOrganizationIfExists(String orgId) throws Exception { } } - // Methods to create request bodies for user sharing and unsharing. - - /** - * Creates a `UserShareRequestBodyUserCriteria` object with the given user IDs. - * - * @param userIds The list of user IDs to be included in the criteria. - * @return A `UserShareRequestBodyUserCriteria` object containing the specified user IDs. - */ - protected UserShareRequestBodyUserCriteria getUserCriteriaForBaseUserSharing(List userIds) { - - UserShareRequestBodyUserCriteria criteria = new UserShareRequestBodyUserCriteria(); - criteria.setUserIds(userIds); - return criteria; - } - - /** - * Creates a `UserUnshareRequestBodyUserCriteria` object with the given user IDs. - * - * @param userIds The list of user IDs to be included in the criteria. - * @return A `UserUnshareRequestBodyUserCriteria` object containing the specified user IDs. - */ - protected UserUnshareRequestBodyUserCriteria getUserCriteriaForBaseUserUnsharing(List userIds) { - - UserUnshareRequestBodyUserCriteria criteria = new UserUnshareRequestBodyUserCriteria(); - criteria.setUserIds(userIds); - return criteria; - } - - /** - * Converts a map of organization details into a list of `UserShareRequestBodyOrganizations` objects. - * - * @param organizations A map where the key is the organization name and the value is a map of organization details. - * @return A list of `UserShareRequestBodyOrganizations` objects. - *

- * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are - * predefined in the test data providers. - *

- */ - @SuppressWarnings("unchecked") - protected List getOrganizationsForSelectiveUserSharing(Map> organizations) { - - List orgs = new ArrayList<>(); - - for (Map.Entry> entry : organizations.entrySet()) { - - Map orgDetail = entry.getValue(); - - UserShareRequestBodyOrganizations org = new UserShareRequestBodyOrganizations(); - org.setOrgId((String) orgDetail.get(MAP_KEY_SELECTIVE_ORG_ID)); - org.setPolicy((UserShareRequestBodyOrganizations.PolicyEnum) orgDetail.get(MAP_KEY_SELECTIVE_POLICY)); - org.setRoles((List) orgDetail.get(MAP_KEY_SELECTIVE_ROLES)); - - orgs.add(org); - } - return orgs; - } - - /** - * Retrieves the policy enum for general user sharing from the provided map. - * - * @param policyWithRoles A map containing the policy and roles for general user sharing. - * @return The policy enum for general user sharing. - */ - protected UserShareWithAllRequestBody.PolicyEnum getPolicyEnumForGeneralUserSharing(Map policyWithRoles) { - - return (UserShareWithAllRequestBody.PolicyEnum)policyWithRoles.get(MAP_KEY_GENERAL_POLICY) ; - } - - /** - * Retrieves the roles for general user sharing from the provided map. - * - * @param policyWithRoles A map containing the policy and roles for general user sharing. - * @return A list of `RoleWithAudience` objects representing the roles for general user sharing. - *

- * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are - * predefined in the test data providers. - *

- */ - @SuppressWarnings("unchecked") - protected List getRolesForGeneralUserSharing(Map policyWithRoles) { - - return (List) policyWithRoles.get(MAP_KEY_GENERAL_ROLES); - } - - /** - * Retrieves the list of organization IDs from which the users are being selectively unshared. - * - * @param removingOrgIds The list of organization IDs to be removed. - * @return A list of organization IDs as strings. - */ - protected List getOrganizationsForSelectiveUserUnsharing(List removingOrgIds) { - - return removingOrgIds; - } - // Helper methods. protected String toJSONString(java.lang.Object object) { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 6327890482d..02682a07b2a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -18,26 +18,52 @@ package org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1; +import io.restassured.response.Response; +import org.apache.http.HttpStatus; import org.json.JSONObject; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; +import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; import org.wso2.identity.integration.test.restclients.SCIM2RestClient; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; + /** * Tests for failure cases of the User Sharing REST APIs. */ public class UserSharingFailureTest extends UserSharingBaseTest { + private static final String INVALID_ORG_1_NAME = "invalid-org-1-name"; + private static final String INVALID_ORG_1_ID = "invalid-org-1-id"; + + private static final String INVALID_APP_1_NAME = "invalid-app-1"; + private static final String INVALID_APP_2_NAME = "invalid-app-2"; + + private static final String INVALID_APP_ROLE_1 = "invalid-app-role-1"; + private static final String INVALID_APP_ROLE_2 = "invalid-app-role-2"; + private static final String INVALID_ORG_ROLE_1 = "invalid-org-role-1"; + private static final String INVALID_ORG_ROLE_2 = "invalid-org-role-2"; + + private static final String INVALID_USER_1_ID = "invalid-user-id-1"; + private static final String INVALID_USER_2_ID = "invalid-user-id-2"; + @Factory(dataProvider = "restAPIUserConfigProvider") public UserSharingFailureTest(TestUserMode userMode) throws Exception { @@ -81,6 +107,222 @@ public static Object[][] restAPIUserConfigProvider() { }; } + // Selective User Sharing. + + @DataProvider(name = "selectiveUserSharingWithInvalidRolesDataProvider") + public Object[][] selectiveUserSharingWithInvalidRolesDataProvider() { + + // Test case 1: User sharing with invalid roles. + List userIdsForTestCase1 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingTestCase1(); + Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingTestCase1(); + + // Test case 2: User sharing with invalid organizations. + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + Map> organizationsForTestCase2 = setOrganizationsForSelectiveUserSharingTestCase2(); + Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserSharingTestCase2(); + + // Test case 3: User sharing with invalid users. + List userIdsForTestCase3 = Arrays.asList(INVALID_USER_1_ID, INVALID_USER_2_ID); + Map> organizationsForTestCase3 = setOrganizationsForSelectiveUserSharingTestCase3(); + Map expectedResultsForTestCase3 = setExpectedResultsForSelectiveUserSharingTestCase3(); + + + + return new Object[][] { + { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1 }, + { userIdsForTestCase2, organizationsForTestCase2, expectedResultsForTestCase2 }, + { userIdsForTestCase3, organizationsForTestCase3, expectedResultsForTestCase3 } + }; + } + + @Test(dataProvider = "selectiveUserSharingWithInvalidRolesDataProvider") + public void testSelectiveUserSharingWithInvalidRoles(List userIds, + Map> organizations, + Map expectedResults) throws InterruptedException { + + UserShareRequestBody requestBody = new UserShareRequestBody() + .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) + .organizations(getOrganizationsForSelectiveUserSharing(organizations)); + + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); + + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + } + } + + // Test cases builders for selective user sharing. + + private Map> setOrganizationsForSelectiveUserSharingTestCase1() { + + Map> organizations = new HashMap<>(); + + // Organization 1 + Map org1 = new HashMap<>(); + org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); + org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( + createRoleWithAudience(INVALID_APP_ROLE_1, INVALID_APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + organizations.put(L1_ORG_1_NAME, org1); + + // Organization 2 + Map org2 = new HashMap<>(); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); + org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); + org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( + createRoleWithAudience(APP_ROLE_1, INVALID_APP_2_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, INVALID_ORG_1_NAME, ORGANIZATION_AUDIENCE), + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + organizations.put(L1_ORG_2_NAME, org2); + + // Organization 3 + Map org3 = new HashMap<>(); + org3.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_3_NAME)); + org3.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_3_NAME); + org3.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_ONLY); + org3.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( + createRoleWithAudience(INVALID_APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(INVALID_ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE), + createRoleWithAudience(INVALID_ORG_ROLE_2, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + organizations.put(L1_ORG_3_NAME, org3); + + return organizations; + } + + private Map setExpectedResultsForSelectiveUserSharingTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.emptyList()); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map> setOrganizationsForSelectiveUserSharingTestCase2() { + + Map> organizations = new HashMap<>(); + + // Organization 1 + Map org1 = new HashMap<>(); + org1.put(MAP_KEY_SELECTIVE_ORG_ID, INVALID_ORG_1_ID); + org1.put(MAP_KEY_SELECTIVE_ORG_NAME, INVALID_ORG_1_NAME); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + organizations.put(INVALID_ORG_1_NAME, org1); + + // Organization 2 + Map org2 = new HashMap<>(); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); + org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); + org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + organizations.put(L1_ORG_2_NAME, org2); + + return organizations; + } + + private Map setExpectedResultsForSelectiveUserSharingTestCase2() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 2); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map> setOrganizationsForSelectiveUserSharingTestCase3() { + + Map> organizations = new HashMap<>(); + + // Organization 1 + Map org1 = new HashMap<>(); + org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); + org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + organizations.put(L1_ORG_1_NAME, org1); + + // Organization 2 + Map org2 = new HashMap<>(); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); + org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); + org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + organizations.put(L1_ORG_2_NAME, org2); + + // Organization 3 + Map org3 = new HashMap<>(); + org3.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_3_NAME)); + org3.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_3_NAME); + org3.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_ONLY); + org3.put(MAP_KEY_SELECTIVE_ROLES, Collections.emptyList()); + + organizations.put(L1_ORG_3_NAME, org3); + + return organizations; + } + + private Map setExpectedResultsForSelectiveUserSharingTestCase3() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } // Setup methods. diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 3b96e1d053e..543f55108fa 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -297,103 +297,6 @@ public void testSelectiveUserUnsharing(List userIds, } } - - /** - * Validate that the user has been shared to the expected organizations with the expected roles. - * - * @param userId The ID of the user to validate. - * @param expectedResults A map containing the expected results, including the expected organization count, - * expected organization IDs, expected organization names, and expected roles per - * organization. - *

- * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are - * predefined in the test data providers. - *

- */ - @SuppressWarnings("unchecked") - private void validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(String userId, Map expectedResults) { - - testGetSharedOrganizations( - userId, - (int) expectedResults.get(MAP_KEY_EXPECTED_ORG_COUNT), - (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_IDS), - (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_NAMES) - ); - - Map> expectedRolesPerExpectedOrg = (Map>) expectedResults.get(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG); - for (Map.Entry> entry : expectedRolesPerExpectedOrg.entrySet()) { - testGetSharedRolesForOrg(userId, entry.getKey(), entry.getValue()); - } - } - - /** - * Test method for GET /user-sharing/{userId}/shared-organizations. - * - * @param userId The ID of the user to get shared organizations for. - * @param expectedOrgCount The expected number of shared organizations. - * @param expectedOrgIds The expected IDs of the shared organizations. - * @param expectedOrgNames The expected names of the shared organizations. - */ - public void testGetSharedOrganizations(String userId, int expectedOrgCount, List expectedOrgIds, List expectedOrgNames) { - - Response response = - getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ORGANIZATIONS_PATH); - - response.then() - .log().ifValidationFails() - .assertThat() - .statusCode(HttpStatus.SC_OK) - .body(RESPONSE_LINKS_SIZE, equalTo(1)) - .body(RESPONSE_LINKS_EMPTY, equalTo(true)) - .body(RESPONSE_LINKS_SHARED_ORGS, notNullValue()) - .body(RESPONSE_LINKS_SHARED_ORGS_SIZE, equalTo(expectedOrgCount)) - .body(RESPONSE_LINKS_SHARED_ORGS_ID, hasItems(expectedOrgIds.toArray(new String[0]))) - .body(RESPONSE_LINKS_SHARED_ORGS_NAME, hasItems(expectedOrgNames.toArray(new String[0]))) - .body(RESPONSE_LINKS_SHARED_ORGS_SHARED_TYPE, everyItem(equalTo(SHARED_TYPE_SHARED))) - .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_REF, hasItems( - expectedOrgIds.stream() - .map(orgId -> getSharedOrgsRolesRef(userId, orgId)) - .toArray(String[]::new))); - } - - /** - * Test method for GET /user-sharing/{userId}/shared-roles?orgId={orgId}. - * - * @param userId The ID of the user to get shared roles for. - * @param orgId The ID of the organization to get shared roles for. - * @param expectedRoles The expected roles for the user in the specified organization. - */ - public void testGetSharedRolesForOrg(String userId, String orgId, List expectedRoles) { - - Response response = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ROLES_PATH, - Collections.singletonMap(QUERY_PARAM_ORG_ID, orgId)); - - response.then() - .log().ifValidationFails() - .assertThat() - .statusCode(HttpStatus.SC_OK) - .body(RESPONSE_LINKS_SIZE, equalTo(1)) - .body(RESPONSE_LINKS_EMPTY, equalTo(true)) - .body(RESPONSE_LINKS_SHARED_ORGS_ROLES, notNullValue()) - .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_SIZE, equalTo(expectedRoles.size())); - - if (!expectedRoles.isEmpty()) { - response.then() - .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_NAME, hasItems( - expectedRoles.stream() - .map(RoleWithAudience::getDisplayName) - .toArray(String[]::new))) - .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_NAME, hasItems( - expectedRoles.stream() - .map(role -> role.getAudience().getDisplay()) - .toArray(String[]::new))) - .body(RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_TYPE, hasItems( - expectedRoles.stream() - .map(role -> role.getAudience().getType()) - .toArray(String[]::new))); - } - } - // Test cases builders for selective user sharing. private Map> setOrganizationsForSelectiveUserSharingTestCase1() { From c18714278ed91a254b782b0f6f9df19b9efb028a Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Tue, 4 Mar 2025 14:44:38 +0530 Subject: [PATCH 23/39] add failure tests to user selective sharing with invalid roles, orgs and users - refine method names. --- .../management/v1/UserSharingFailureTest.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 02682a07b2a..82ec7f27dad 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -109,23 +109,23 @@ public static Object[][] restAPIUserConfigProvider() { // Selective User Sharing. - @DataProvider(name = "selectiveUserSharingWithInvalidRolesDataProvider") - public Object[][] selectiveUserSharingWithInvalidRolesDataProvider() { + @DataProvider(name = "selectiveUserSharingWithInvalidDetailsDataProvider") + public Object[][] selectiveUserSharingWithInvalidDetailsDataProvider() { // Test case 1: User sharing with invalid roles. List userIdsForTestCase1 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); - Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingTestCase1(); - Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingTestCase1(); + Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1(); + Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase1(); // Test case 2: User sharing with invalid organizations. List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); - Map> organizationsForTestCase2 = setOrganizationsForSelectiveUserSharingTestCase2(); - Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserSharingTestCase2(); + Map> organizationsForTestCase2 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase2(); + Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase2(); // Test case 3: User sharing with invalid users. List userIdsForTestCase3 = Arrays.asList(INVALID_USER_1_ID, INVALID_USER_2_ID); - Map> organizationsForTestCase3 = setOrganizationsForSelectiveUserSharingTestCase3(); - Map expectedResultsForTestCase3 = setExpectedResultsForSelectiveUserSharingTestCase3(); + Map> organizationsForTestCase3 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase3(); + Map expectedResultsForTestCase3 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase3(); @@ -136,8 +136,8 @@ public Object[][] selectiveUserSharingWithInvalidRolesDataProvider() { }; } - @Test(dataProvider = "selectiveUserSharingWithInvalidRolesDataProvider") - public void testSelectiveUserSharingWithInvalidRoles(List userIds, + @Test(dataProvider = "selectiveUserSharingWithInvalidDetailsDataProvider") + public void testSelectiveUserSharingWithInvalidDetails(List userIds, Map> organizations, Map expectedResults) throws InterruptedException { @@ -162,7 +162,7 @@ public void testSelectiveUserSharingWithInvalidRoles(List userIds, // Test cases builders for selective user sharing. - private Map> setOrganizationsForSelectiveUserSharingTestCase1() { + private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1() { Map> organizations = new HashMap<>(); @@ -205,7 +205,7 @@ private Map> setOrganizationsForSelectiveUserSharing return organizations; } - private Map setExpectedResultsForSelectiveUserSharingTestCase1() { + private Map setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase1() { Map expectedResults = new HashMap<>(); @@ -227,7 +227,7 @@ private Map setExpectedResultsForSelectiveUserSharingTestCase1() return expectedResults; } - private Map> setOrganizationsForSelectiveUserSharingTestCase2() { + private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase2() { Map> organizations = new HashMap<>(); @@ -255,7 +255,7 @@ private Map> setOrganizationsForSelectiveUserSharing return organizations; } - private Map setExpectedResultsForSelectiveUserSharingTestCase2() { + private Map setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase2() { Map expectedResults = new HashMap<>(); @@ -272,7 +272,7 @@ private Map setExpectedResultsForSelectiveUserSharingTestCase2() return expectedResults; } - private Map> setOrganizationsForSelectiveUserSharingTestCase3() { + private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase3() { Map> organizations = new HashMap<>(); @@ -309,7 +309,7 @@ private Map> setOrganizationsForSelectiveUserSharing return organizations; } - private Map setExpectedResultsForSelectiveUserSharingTestCase3() { + private Map setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase3() { Map expectedResults = new HashMap<>(); From f19d22437ae664afdd419a1bbf4f343eea78ff91 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Tue, 4 Mar 2025 16:55:29 +0530 Subject: [PATCH 24/39] add failure tests to user general sharing with invalid roles and users. --- .../management/v1/UserSharingFailureTest.java | 115 +++++++++++++++++- .../management/v1/UserSharingSuccessTest.java | 2 +- 2 files changed, 113 insertions(+), 4 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 82ec7f27dad..fd9dafdfbc2 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -29,6 +29,7 @@ import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; import org.wso2.identity.integration.test.restclients.SCIM2RestClient; @@ -44,6 +45,8 @@ import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_AND_FUTURE_ORGS; /** * Tests for failure cases of the User Sharing REST APIs. @@ -107,7 +110,7 @@ public static Object[][] restAPIUserConfigProvider() { }; } - // Selective User Sharing. + // Invalid Selective User Sharing. @DataProvider(name = "selectiveUserSharingWithInvalidDetailsDataProvider") public Object[][] selectiveUserSharingWithInvalidDetailsDataProvider() { @@ -160,7 +163,53 @@ public void testSelectiveUserSharingWithInvalidDetails(List userIds, } } - // Test cases builders for selective user sharing. + // Invalid General User Sharing. + + @DataProvider(name = "generalUserSharingWithInvalidDetailsDataProvider") + public Object[][] generalUserSharingWithInvalidDetailsDataProvider() { + + // Test case 1: User sharing with invalid roles. + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); + Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase1(); + Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase1(); + + // Test case 2: User sharing with invalid users. + List userIdsForTestCase2 = Arrays.asList(INVALID_USER_1_ID, INVALID_USER_2_ID); + Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase2(); + Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase2(); + + return new Object[][] { + { userIdsForTestCase1, policyWithRolesForTestCase1, expectedResultsForTestCase1 }, + { userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2 } + }; + } + + @Test(dataProvider = "generalUserSharingWithInvalidDetailsDataProvider") + public void testGeneralWithInvalidDetailsUserSharing(List userIds, + Map policyWithRoles, + Map expectedResults) throws InterruptedException { + + UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() + .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) + .policy(getPolicyEnumForGeneralUserSharing(policyWithRoles)) + .roles(getRolesForGeneralUserSharing(policyWithRoles)); + + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); + + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + } + } + + // Test cases builders. private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1() { @@ -184,7 +233,6 @@ private Map> setOrganizationsForSelectiveUserSharing org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( createRoleWithAudience(APP_ROLE_1, INVALID_APP_2_NAME, APPLICATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_1, INVALID_ORG_1_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); @@ -318,7 +366,68 @@ private Map setExpectedResultsForSelectiveUserSharingWithInvalid expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + return expectedResults; + } + + private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase1() { + + Map policyWithRoles = new HashMap<>(); + + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, ALL_EXISTING_ORGS_ONLY); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList( + createRoleWithAudience(INVALID_APP_ROLE_1, INVALID_APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(APP_ROLE_1, INVALID_APP_2_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(INVALID_APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(INVALID_ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE), + createRoleWithAudience(INVALID_ORG_ROLE_2, INVALID_ORG_1_NAME, ORGANIZATION_AUDIENCE), + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + return policyWithRoles; + } + + private Map setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase2() { + + Map policyWithRoles = new HashMap<>(); + + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_AND_FUTURE_ORGS); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + return policyWithRoles; + } + + private Map setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase2() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); return expectedResults; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 543f55108fa..e98ae102b81 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -297,7 +297,7 @@ public void testSelectiveUserUnsharing(List userIds, } } - // Test cases builders for selective user sharing. + // Test cases builders. private Map> setOrganizationsForSelectiveUserSharingTestCase1() { From e2eaf396afd41c29a5d713173a89ec8c63583ce7 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Wed, 5 Mar 2025 18:31:26 +0530 Subject: [PATCH 25/39] format method names. --- .../management/v1/UserSharingFailureTest.java | 5 +++-- .../management/v1/UserSharingSuccessTest.java | 15 ++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index fd9dafdfbc2..103ebe0b228 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -30,6 +30,7 @@ import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareWithAllRequestBody; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; import org.wso2.identity.integration.test.restclients.SCIM2RestClient; @@ -427,8 +428,8 @@ private Map setExpectedResultsForGeneralUserSharingWithInvalidDe expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); - Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + Map> expectedRolesPerExpectedOrganization = new HashMap<>(); + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrganization); return expectedResults; } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index e98ae102b81..e7625633b8e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -44,9 +44,6 @@ import java.util.Map; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.everyItem; -import static org.hamcrest.CoreMatchers.hasItems; -import static org.hamcrest.CoreMatchers.notNullValue; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; @@ -254,18 +251,18 @@ public Object[][] selectiveUserUnsharingDataProvider() { Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); List removingOrgIdsForTestCase1 = Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME)); - Map expectedUnsharedResultsForTestCase1 = setExpectedUnsharedResultsForGeneralUserSharingTestCase1(); + Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserUnsharingTestCase1(); // IMMEDIATE EXISTING AND FUTURE List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); List removingOrgIdsForTestCase2 = Collections.singletonList(getOrgId(L1_ORG_1_NAME)); - Map expectedUnsharedResultsForTestCase2 = setExpectedUnsharedResultsForGeneralUserSharingTestCase2(); + Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserUnsharingTestCase2(); return new Object[][] { - { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, removingOrgIdsForTestCase1, expectedUnsharedResultsForTestCase1}, - { userIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, removingOrgIdsForTestCase2, expectedUnsharedResultsForTestCase2} + { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, removingOrgIdsForTestCase1, expectedResultsForTestCase1}, + { userIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, removingOrgIdsForTestCase2, expectedResultsForTestCase2} }; } @@ -532,7 +529,7 @@ private Map setExpectedResultsForGeneralUserUnsharingTestCase1() return expectedResults; } - private Map setExpectedUnsharedResultsForGeneralUserSharingTestCase1() { + private Map setExpectedResultsForSelectiveUserUnsharingTestCase1() { Map expectedResults = new HashMap<>(); @@ -552,7 +549,7 @@ private Map setExpectedUnsharedResultsForGeneralUserSharingTestC return expectedResults; } - private Map setExpectedUnsharedResultsForGeneralUserSharingTestCase2() { + private Map setExpectedResultsForSelectiveUserUnsharingTestCase2() { Map expectedResults = new HashMap<>(); From b789b3d2e1609ef21cf8cabcc3bd7f34d420772d Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Wed, 5 Mar 2025 22:25:19 +0530 Subject: [PATCH 26/39] general unsharing for invalid user ids (with no pre sharing) --- .../management/v1/UserSharingFailureTest.java | 136 +++++++++++++++++- 1 file changed, 132 insertions(+), 4 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 103ebe0b228..7ae89f34a0a 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -48,6 +48,7 @@ import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_AND_FUTURE_ORGS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_ORGS_ONLY; /** * Tests for failure cases of the User Sharing REST APIs. @@ -141,7 +142,7 @@ public Object[][] selectiveUserSharingWithInvalidDetailsDataProvider() { } @Test(dataProvider = "selectiveUserSharingWithInvalidDetailsDataProvider") - public void testSelectiveUserSharingWithInvalidDetails(List userIds, + public void testSelectiveUserSharing(List userIds, Map> organizations, Map expectedResults) throws InterruptedException { @@ -186,7 +187,7 @@ public Object[][] generalUserSharingWithInvalidDetailsDataProvider() { } @Test(dataProvider = "generalUserSharingWithInvalidDetailsDataProvider") - public void testGeneralWithInvalidDetailsUserSharing(List userIds, + public void testGeneralUserSharing(List userIds, Map policyWithRoles, Map expectedResults) throws InterruptedException { @@ -210,6 +211,56 @@ public void testGeneralWithInvalidDetailsUserSharing(List userIds, } } + // General User Unsharing. + + @DataProvider(name = "generalUserUnsharingWithInvalidDetailsDataProvider") + public Object[][] generalUserUnsharingWithInvalidDetailsDataProvider() { + + List sharingUserIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); +// Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); +// Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + List userIdsForTestCase1 = Collections.singletonList(INVALID_USER_1_ID); +// Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + + List sharingUserIdsForTestCase2 = Collections.singletonList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); +// Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); +// Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); + List userIdsForTestCase2 = Arrays.asList(INVALID_USER_1_ID, INVALID_USER_2_ID); +// Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); + + Map expectedResultsForTestCase = + setExpectedResultsForGeneralUserUnsharingWithInvalidDetailsTestCase1(); + + return new Object[][] { + { userIdsForTestCase1, expectedResultsForTestCase}, + { userIdsForTestCase2, expectedResultsForTestCase}, + }; + } + + @Test(dataProvider = "generalUserUnsharingWithInvalidDetailsDataProvider") + public void testGeneralUserUnsharing(List removingUserIds, + Map expectedResults) throws InterruptedException { + + //testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); + + UserUnshareWithAllRequestBody requestBody = new UserUnshareWithAllRequestBody() + .userCriteria(getUserCriteriaForBaseUserUnsharing(removingUserIds)); + + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + UNSHARE_WITH_ALL_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_UNSHARING)); + + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : removingUserIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + } + } + // Test cases builders. private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1() { @@ -428,8 +479,85 @@ private Map setExpectedResultsForGeneralUserSharingWithInvalidDe expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); - Map> expectedRolesPerExpectedOrganization = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrganization); + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1() { + + Map policyWithRoles = new HashMap<>(); + + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, ALL_EXISTING_ORGS_ONLY); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + return policyWithRoles; + } + + private Map setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2() { + + Map policyWithRoles = new HashMap<>(); + + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_ORGS_ONLY); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + return policyWithRoles; + } + + private Map setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + + + + private Map setExpectedResultsForGeneralUserUnsharingWithInvalidDetailsTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); return expectedResults; } From e887af248b4d1cfd3a6b93d6840750e96d0b8c8f Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Wed, 5 Mar 2025 23:10:14 +0530 Subject: [PATCH 27/39] general unsharing for invalid user ids. --- .../management/v1/UserSharingFailureTest.java | 47 +++++++------------ 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 7ae89f34a0a..fc8aaf953d6 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -217,32 +217,34 @@ public void testGeneralUserSharing(List userIds, public Object[][] generalUserUnsharingWithInvalidDetailsDataProvider() { List sharingUserIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); -// Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); -// Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); + Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); List userIdsForTestCase1 = Collections.singletonList(INVALID_USER_1_ID); -// Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); List sharingUserIdsForTestCase2 = Collections.singletonList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); -// Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); -// Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); + Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); + Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); List userIdsForTestCase2 = Arrays.asList(INVALID_USER_1_ID, INVALID_USER_2_ID); -// Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); - - Map expectedResultsForTestCase = - setExpectedResultsForGeneralUserUnsharingWithInvalidDetailsTestCase1(); + Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); return new Object[][] { - { userIdsForTestCase1, expectedResultsForTestCase}, - { userIdsForTestCase2, expectedResultsForTestCase}, + { sharingUserIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, userIdsForTestCase1, expectedResultsForTestCase1}, + { sharingUserIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, userIdsForTestCase2, expectedResultsForTestCase2}, }; } @Test(dataProvider = "generalUserUnsharingWithInvalidDetailsDataProvider") - public void testGeneralUserUnsharing(List removingUserIds, + public void testGeneralUserUnsharing(List userIds, + Map policyWithRoles, + Map expectedSharedResults, + List removingUserIds, Map expectedResults) throws InterruptedException { - //testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); + // Sharing valid users. + testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); + // Unsharing invalid users. UserUnshareWithAllRequestBody requestBody = new UserUnshareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserUnsharing(removingUserIds)); @@ -256,7 +258,7 @@ public void testGeneralUserUnsharing(List removingUserIds, .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_UNSHARING)); Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : removingUserIds) { + for (String userId : userIds) { validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); } } @@ -545,23 +547,6 @@ private Map setExpectedResultsForGeneralUserSharingWithValidDeta return expectedResults; } - - - - private Map setExpectedResultsForGeneralUserUnsharingWithInvalidDetailsTestCase1() { - - Map expectedResults = new HashMap<>(); - - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); - - Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); - - return expectedResults; - } - // Setup methods. private void setupDetailMaps() { From b7f9568baeb6e0650150abce342f6af299cdbb11 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Wed, 5 Mar 2025 23:58:43 +0530 Subject: [PATCH 28/39] selective unsharing for invalid user ids and invalid org ids. --- .../management/v1/UserSharingFailureTest.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index fc8aaf953d6..2fc94804b4f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -30,6 +30,7 @@ import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareWithAllRequestBody; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; import org.wso2.identity.integration.test.restclients.OrgMgtRestClient; @@ -57,6 +58,8 @@ public class UserSharingFailureTest extends UserSharingBaseTest { private static final String INVALID_ORG_1_NAME = "invalid-org-1-name"; private static final String INVALID_ORG_1_ID = "invalid-org-1-id"; + private static final String INVALID_ORG_2_NAME = "invalid-org-2-name"; + private static final String INVALID_ORG_2_ID = "invalid-org-2-id"; private static final String INVALID_APP_1_NAME = "invalid-app-1"; private static final String INVALID_APP_2_NAME = "invalid-app-2"; @@ -263,6 +266,62 @@ public void testGeneralUserUnsharing(List userIds, } } + // Selective User Unsharing. + + @DataProvider(name = "selectiveUserUnsharingDataProvider") + public Object[][] selectiveUserUnsharingDataProvider() { + + // ALL EXISTING + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); + Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); + Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + List removingUserIdsForTestCase1 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), INVALID_USER_1_ID, INVALID_USER_2_ID); + List removingOrgIdsForTestCase1 =Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME)); + Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase1(); + + // IMMEDIATE EXISTING AND FUTURE + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); + Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); + Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); + List removingUserIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), INVALID_USER_1_ID); + List removingOrgIdsForTestCase2 = Arrays.asList(getOrgId(L1_ORG_1_NAME), INVALID_ORG_1_ID); + Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase2(); + + return new Object[][] { + { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, removingUserIdsForTestCase1, removingOrgIdsForTestCase1, expectedResultsForTestCase1}, + { userIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, removingUserIdsForTestCase2, removingOrgIdsForTestCase2, expectedResultsForTestCase2} + }; + } + + @Test(dataProvider = "selectiveUserUnsharingDataProvider") + public void testSelectiveUserUnsharing(List userIds, + Map policyWithRoles, + Map expectedSharedResults, + List removingUserIds, + List removingOrgIds, + Map expectedUnsharedResults) throws InterruptedException { + + testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); + + UserUnshareRequestBody requestBody = new UserUnshareRequestBody() + .userCriteria(getUserCriteriaForBaseUserUnsharing(removingUserIds)) + .organizations(getOrganizationsForSelectiveUserUnsharing(removingOrgIds)); + + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + UNSHARE_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_UNSHARING)); + + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedUnsharedResults); + } + } + // Test cases builders. private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1() { @@ -547,6 +606,43 @@ private Map setExpectedResultsForGeneralUserSharingWithValidDeta return expectedResults; } + private Map setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 5); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase2() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 2); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + // Setup methods. private void setupDetailMaps() { From 64ad3ed8a5b30d67e3a1ec9c3afe21082182d48e Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Thu, 6 Mar 2025 15:46:08 +0530 Subject: [PATCH 29/39] selective user sharing of conflicting user. --- .../management/v1/UserSharingBaseTest.java | 1 + .../management/v1/UserSharingFailureTest.java | 64 ++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 1ef5edebccb..29eab6680ce 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -156,6 +156,7 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String L1_ORG_1_USER_1_USERNAME = "l1Org1User1"; protected static final String L1_ORG_1_USER_2_USERNAME = "l1Org1User2"; protected static final String L1_ORG_1_USER_3_USERNAME = "l1Org1User3"; + protected static final String ROOT_ORG_USER_DUPLICATED_USERNAME = "rootUserDuplicated"; protected static final String MAP_KEY_SELECTIVE_ORG_ID = "orgId"; protected static final String MAP_KEY_SELECTIVE_ORG_NAME = "orgName"; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 2fc94804b4f..6fc9ccc0710 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -45,6 +45,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY; @@ -135,12 +136,17 @@ public Object[][] selectiveUserSharingWithInvalidDetailsDataProvider() { Map> organizationsForTestCase3 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase3(); Map expectedResultsForTestCase3 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase3(); + // Test case 3: User sharing with invalid users. + List userIdsForTestCase4 = Collections.singletonList(getUserId(ROOT_ORG_USER_DUPLICATED_USERNAME, USER_DOMAIN_PRIMARY)); + Map> organizationsForTestCase4 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase4(); + Map expectedResultsForTestCase4 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase4(); return new Object[][] { { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1 }, { userIdsForTestCase2, organizationsForTestCase2, expectedResultsForTestCase2 }, - { userIdsForTestCase3, organizationsForTestCase3, expectedResultsForTestCase3 } + { userIdsForTestCase3, organizationsForTestCase3, expectedResultsForTestCase3 }, + { userIdsForTestCase4, organizationsForTestCase4, expectedResultsForTestCase4 } }; } @@ -322,6 +328,8 @@ public void testSelectiveUserUnsharing(List userIds, } } + //todo next remove thread sleep. + // Test cases builders. private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1() { @@ -484,6 +492,58 @@ private Map setExpectedResultsForSelectiveUserSharingWithInvalid return expectedResults; } + private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase4() { + + Map> organizations = new HashMap<>(); + + // Organization 1 + Map org1 = new HashMap<>(); + org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); + org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + organizations.put(L1_ORG_1_NAME, org1); + + // Organization 2 + Map org2 = new HashMap<>(); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); + org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); + org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_ONLY); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + organizations.put(L1_ORG_2_NAME, org2); + + return organizations; + } + + private Map setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase4() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + +// expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 1); +// expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.singletonList(getOrgId(L1_ORG_2_NAME))); +// expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.singletonList(L1_ORG_2_NAME)); +// +// Map> expectedRolesPerExpectedOrg = new HashMap<>(); +// expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); +// +// expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase1() { Map policyWithRoles = new HashMap<>(); @@ -689,9 +749,11 @@ private void setupUsers() throws Exception { createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_1_USERNAME, ROOT_ORG_NAME)); createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_2_USERNAME, ROOT_ORG_NAME)); createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_3_USERNAME, ROOT_ORG_NAME)); + createUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_DUPLICATED_USERNAME, ROOT_ORG_NAME)); createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_1_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_2_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_3_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); + createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_DUPLICATED_USERNAME, ROOT_ORG_NAME), L1_ORG_1_NAME); } } From 936897fd19ce1e86e17e3795f05c502c7ae4ce46 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Thu, 6 Mar 2025 23:28:25 +0530 Subject: [PATCH 30/39] conflicting user sharing result. --- .../management/v1/UserSharingBaseTest.java | 12 +-- .../management/v1/UserSharingFailureTest.java | 78 +++++++++++++------ .../management/v1/UserSharingSuccessTest.java | 20 ++--- 3 files changed, 70 insertions(+), 40 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 29eab6680ce..e26a59bfdc1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -587,6 +587,7 @@ protected String createUser(UserObject user) throws Exception{ String userId = scim2RestClient.createUser(user); String domainQualifiedUserName = user.getUserName(); + String domainQualifiedUserNameWithOrg = domainQualifiedUserName + PATH_SEPARATOR + ROOT_ORG_NAME; Map userDetail = new HashMap<>(); userDetail.put(MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME, domainQualifiedUserName); @@ -598,7 +599,7 @@ protected String createUser(UserObject user) throws Exception{ userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_ID, ROOT_ORG_ID); userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_LEVEL, 0); - userDetails.put(domainQualifiedUserName, userDetail); + userDetails.put(domainQualifiedUserNameWithOrg, userDetail); return userId; } @@ -606,6 +607,7 @@ protected String createSuborgUser(UserObject user, String suborg) throws Excepti String userId = scim2RestClient.createSubOrgUser(user, (String) orgDetails.get(suborg).get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN)); String domainQualifiedUserName = user.getUserName(); + String domainQualifiedUserNameWithOrg = domainQualifiedUserName + PATH_SEPARATOR + suborg; Map userDetail = new HashMap<>(); userDetail.put(MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME, domainQualifiedUserName); @@ -617,14 +619,14 @@ protected String createSuborgUser(UserObject user, String suborg) throws Excepti userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_ID, orgDetails.get(suborg).get(MAP_ORG_DETAILS_KEY_ORG_ID)); userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_LEVEL, orgDetails.get(suborg).get(MAP_ORG_DETAILS_KEY_ORG_LEVEL)); - userDetails.put(domainQualifiedUserName, userDetail); + userDetails.put(domainQualifiedUserNameWithOrg, userDetail); return userId; } - protected String getUserId(String userName, String userDomain) { + protected String getUserId(String userName, String userDomain, String orgName) { - String domainQualifiedUserName = userDomain + PATH_SEPARATOR + userName; - return userDetails.get(domainQualifiedUserName).get(MAP_USER_DETAILS_KEY_USER_ID).toString(); + String domainQualifiedUserNameWithOrg = userDomain + PATH_SEPARATOR + userName + PATH_SEPARATOR + orgName; + return userDetails.get(domainQualifiedUserNameWithOrg).get(MAP_USER_DETAILS_KEY_USER_ID).toString(); } private Map getUserNameAndUserDomain(String domainQualifiedUserName) { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 6fc9ccc0710..59667333f4f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -48,6 +48,7 @@ import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_AND_FUTURE_ORGS; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_ORGS_ONLY; @@ -122,12 +123,12 @@ public static Object[][] restAPIUserConfigProvider() { public Object[][] selectiveUserSharingWithInvalidDetailsDataProvider() { // Test case 1: User sharing with invalid roles. - List userIdsForTestCase1 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase1 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase1(); // Test case 2: User sharing with invalid organizations. - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map> organizationsForTestCase2 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase2(); @@ -136,8 +137,8 @@ public Object[][] selectiveUserSharingWithInvalidDetailsDataProvider() { Map> organizationsForTestCase3 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase3(); Map expectedResultsForTestCase3 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase3(); - // Test case 3: User sharing with invalid users. - List userIdsForTestCase4 = Collections.singletonList(getUserId(ROOT_ORG_USER_DUPLICATED_USERNAME, USER_DOMAIN_PRIMARY)); + // Test case 4: User sharing with conflicting users. + List userIdsForTestCase4 = Collections.singletonList(getUserId(ROOT_ORG_USER_DUPLICATED_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map> organizationsForTestCase4 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase4(); Map expectedResultsForTestCase4 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase4(); @@ -180,7 +181,7 @@ public void testSelectiveUserSharing(List userIds, public Object[][] generalUserSharingWithInvalidDetailsDataProvider() { // Test case 1: User sharing with invalid roles. - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase1(); @@ -189,9 +190,15 @@ public Object[][] generalUserSharingWithInvalidDetailsDataProvider() { Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase2(); + // Test case 3: User sharing with conflicting users. + List userIdsForTestCase3 = Collections.singletonList(getUserId(ROOT_ORG_USER_DUPLICATED_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase3(); + Map expectedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase3(); + return new Object[][] { { userIdsForTestCase1, policyWithRolesForTestCase1, expectedResultsForTestCase1 }, - { userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2 } + { userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2 }, + { userIdsForTestCase3, policyWithRolesForTestCase3, expectedResultsForTestCase3 } }; } @@ -225,13 +232,13 @@ public void testGeneralUserSharing(List userIds, @DataProvider(name = "generalUserUnsharingWithInvalidDetailsDataProvider") public Object[][] generalUserUnsharingWithInvalidDetailsDataProvider() { - List sharingUserIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); + List sharingUserIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); List userIdsForTestCase1 = Collections.singletonList(INVALID_USER_1_ID); Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); - List sharingUserIdsForTestCase2 = Collections.singletonList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + List sharingUserIdsForTestCase2 = Collections.singletonList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); List userIdsForTestCase2 = Arrays.asList(INVALID_USER_1_ID, INVALID_USER_2_ID); @@ -278,18 +285,18 @@ public void testGeneralUserUnsharing(List userIds, public Object[][] selectiveUserUnsharingDataProvider() { // ALL EXISTING - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); - List removingUserIdsForTestCase1 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), INVALID_USER_1_ID, INVALID_USER_2_ID); + List removingUserIdsForTestCase1 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), INVALID_USER_1_ID, INVALID_USER_2_ID); List removingOrgIdsForTestCase1 =Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME)); Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase1(); // IMMEDIATE EXISTING AND FUTURE - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); - List removingUserIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), INVALID_USER_1_ID); + List removingUserIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), INVALID_USER_1_ID); List removingOrgIdsForTestCase2 = Arrays.asList(getOrgId(L1_ORG_1_NAME), INVALID_ORG_1_ID); Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase2(); @@ -500,7 +507,7 @@ private Map> setOrganizationsForSelectiveUserSharing Map org1 = new HashMap<>(); org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); - org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_CHILDREN_ONLY); org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList( createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); @@ -524,23 +531,17 @@ private Map setExpectedResultsForSelectiveUserSharingWithInvalid Map expectedResults = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); -// expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 1); -// expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.singletonList(getOrgId(L1_ORG_2_NAME))); -// expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.singletonList(L1_ORG_2_NAME)); -// -// Map> expectedRolesPerExpectedOrg = new HashMap<>(); -// expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); -// -// expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); - return expectedResults; } @@ -606,6 +607,33 @@ private Map setExpectedResultsForGeneralUserSharingWithInvalidDe return expectedResults; } + private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase3() { + + Map policyWithRoles = new HashMap<>(); + + policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_ORGS_ONLY); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + return policyWithRoles; + } + + private Map setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase3() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 2); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + private Map setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1() { Map policyWithRoles = new HashMap<>(); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index e7625633b8e..5896b886806 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -106,11 +106,11 @@ public static Object[][] restAPIUserConfigProvider() { @DataProvider(name = "selectiveUserSharingDataProvider") public Object[][] selectiveUserSharingDataProvider() { - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingTestCase1(); - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map> organizationsForTestCase2 = setOrganizationsForSelectiveUserSharingTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserSharingTestCase2(); @@ -150,22 +150,22 @@ public void testSelectiveUserSharing(List userIds, public Object[][] generalUserSharingDataProvider() { // ALL EXISTING - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); // IMMEDIATE EXISTING AND FUTURE - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); // IMMEDIATE EXISTING - List userIdsForTestCase3 = Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase3 = Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingTestCase3(); Map expectedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingTestCase3(); // ALL EXISTING AND FUTURE - List userIdsForTestCase4 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase4 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase4 = setPolicyWithRolesForGeneralUserSharingTestCase4(); Map expectedResultsForTestCase4 = setExpectedResultsForGeneralUserSharingTestCase4(); @@ -207,8 +207,8 @@ public void testGeneralUserSharing(List userIds, @DataProvider(name = "generalUserUnsharingDataProvider") public Object[][] generalUserUnsharingDataProvider() { - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); List userIdsForTestCase3 = Collections.emptyList(); Map expectedResultsForTestCase = setExpectedResultsForGeneralUserUnsharingTestCase1(); @@ -247,14 +247,14 @@ public void testGeneralUserUnsharing(List userIds, public Object[][] selectiveUserUnsharingDataProvider() { // ALL EXISTING - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); List removingOrgIdsForTestCase1 = Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME)); Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserUnsharingTestCase1(); // IMMEDIATE EXISTING AND FUTURE - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY)); + List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); List removingOrgIdsForTestCase2 = Collections.singletonList(getOrgId(L1_ORG_1_NAME)); From 930335b01cffe81c93de6b6432fb0b46a1d6634c Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Thu, 6 Mar 2025 23:37:51 +0530 Subject: [PATCH 31/39] Skip sharing. --- .../management/v1/UserSharingFailureTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 59667333f4f..a5ec8c0f307 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -142,6 +142,10 @@ public Object[][] selectiveUserSharingWithInvalidDetailsDataProvider() { Map> organizationsForTestCase4 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase4(); Map expectedResultsForTestCase4 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase4(); + // Test case 5: User sharing with non-immediate child organizations. + List userIdsForTestCase5 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map> organizationsForTestCase5 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase5(); + Map expectedResultsForTestCase5 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase5(); return new Object[][] { { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1 }, @@ -545,6 +549,51 @@ private Map setExpectedResultsForSelectiveUserSharingWithInvalid return expectedResults; } + private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase5() { + + Map> organizations = new HashMap<>(); + + // Organization 1 + Map org1 = new HashMap<>(); + org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L3_ORG_1_NAME)); + org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L3_ORG_1_NAME); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_ONLY); + org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + organizations.put(INVALID_ORG_1_NAME, org1); + + // Organization 2 + Map org2 = new HashMap<>(); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); + org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); + org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + organizations.put(L1_ORG_2_NAME, org2); + + return organizations; + } + + private Map setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase5() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 2); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase1() { Map policyWithRoles = new HashMap<>(); From eeacd37c5d410db232d665dfcfd9a9b4d72d0832 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Fri, 7 Mar 2025 09:44:50 +0530 Subject: [PATCH 32/39] add sharing and unsharing methods to UserSharingRestClient. --- .../restclients/UserSharingRestClient.java | 86 +++++++++++++++++-- 1 file changed, 77 insertions(+), 9 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserSharingRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserSharingRestClient.java index fbc55fdcfc3..b1a71e83f00 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserSharingRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserSharingRestClient.java @@ -24,10 +24,12 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.message.BasicHeader; import org.testng.Assert; -import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.automation.engine.context.beans.Tenant; import org.wso2.identity.integration.common.utils.ISIntegrationTest; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareRequestBody; +import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserUnshareWithAllRequestBody; import java.io.IOException; @@ -39,13 +41,25 @@ public class UserSharingRestClient extends RestBaseClient { private static final String API_SERVER_BASE_PATH = "/api/server/v1"; - public static final String USER_SHARE_WITH_ALL_ENDPOINT_URI = "/users/share-with-all"; + static final String USER_SHARING_API_BASE_PATH = "/users"; + static final String SHARE_PATH = "/share"; + static final String SHARE_WITH_ALL_PATH = "/share-with-all"; + static final String UNSHARE_PATH = "/unshare"; + static final String UNSHARE_WITH_ALL_PATH = "/unshare-with-all"; + static final String SHARED_ORGANIZATIONS_PATH = "/shared-organizations"; + static final String SHARED_ROLES_PATH = "/shared-roles"; + public static final String PATH_SEPARATOR = "/"; + private final String serverUrl; private final String tenantDomain; private final String username; private final String password; - private final String userShareWithAllBasePath; + + private final String selectiveUserShareEndpoint; + private final String generalUserShareEndpoint; + private final String selectiveUserUnshareEndpoint; + private final String generalUserUnshareEndpoint; public UserSharingRestClient(String serverUrl, Tenant tenantInfo) { @@ -54,24 +68,78 @@ public UserSharingRestClient(String serverUrl, Tenant tenantInfo) { this.username = tenantInfo.getContextUser().getUserName(); this.password = tenantInfo.getContextUser().getPassword(); - userShareWithAllBasePath = serverUrl + - ISIntegrationTest.getTenantedRelativePath(API_SERVER_BASE_PATH + USER_SHARE_WITH_ALL_ENDPOINT_URI, - tenantDomain); + selectiveUserShareEndpoint = serverUrl + ISIntegrationTest.getTenantedRelativePath( + API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + SHARE_PATH, tenantDomain); + generalUserShareEndpoint = serverUrl + ISIntegrationTest.getTenantedRelativePath( + API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, tenantDomain); + selectiveUserUnshareEndpoint = serverUrl + ISIntegrationTest.getTenantedRelativePath( + API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + UNSHARE_PATH, tenantDomain); + generalUserUnshareEndpoint = serverUrl + ISIntegrationTest.getTenantedRelativePath( + API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + UNSHARE_WITH_ALL_PATH, tenantDomain); + } /** * Share users with all. * - * @param userShareWithAllRequestBody User share with all request body. + * @param userShareRequestBody Selective User Share request body. + * @throws Exception If an error occurs while sharing users with all. + */ + public void shareUsers(UserShareRequestBody userShareRequestBody) throws Exception { + + String jsonRequest = toJSONString(userShareRequestBody); + try (CloseableHttpResponse response = getResponseOfHttpPost(selectiveUserShareEndpoint, jsonRequest, + getHeaders())) { + Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_ACCEPTED, + "Selective User Sharing request accepted."); + } + } + + /** + * Share users with all. + * + * @param userShareWithAllRequestBody General User Share request body. * @throws Exception If an error occurs while sharing users with all. */ public void shareUsersWithAll(UserShareWithAllRequestBody userShareWithAllRequestBody) throws Exception { String jsonRequest = toJSONString(userShareWithAllRequestBody); - try (CloseableHttpResponse response = getResponseOfHttpPost(userShareWithAllBasePath, jsonRequest, + try (CloseableHttpResponse response = getResponseOfHttpPost(generalUserShareEndpoint, jsonRequest, + getHeaders())) { + Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_ACCEPTED, + "General User Sharing request accepted."); + } + } + + /** + * Unshare users with all. + * + * @param userUnshareRequestBody Selective User Unshare request body. + * @throws Exception If an error occurs while unsharing users with all. + */ + public void unshareUsers(UserUnshareRequestBody userUnshareRequestBody) throws Exception { + + String jsonRequest = toJSONString(userUnshareRequestBody); + try (CloseableHttpResponse response = getResponseOfHttpPost(selectiveUserUnshareEndpoint, jsonRequest, + getHeaders())) { + Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_ACCEPTED, + "Selective User Unsharing request accepted."); + } + } + + /** + * Unshare users with all. + * + * @param userUnshareWithAllRequestBody General User Unshare request body. + * @throws Exception If an error occurs while unsharing users with all. + */ + public void unshareUsersWithAll(UserUnshareWithAllRequestBody userUnshareWithAllRequestBody) throws Exception { + + String jsonRequest = toJSONString(userUnshareWithAllRequestBody); + try (CloseableHttpResponse response = getResponseOfHttpPost(generalUserUnshareEndpoint, jsonRequest, getHeaders())) { Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpServletResponse.SC_ACCEPTED, - "User sharing request accepted."); + "General User Unsharing request accepted."); } } From 1236d3ea61b6bd01a2cf4d6d7076f8733ea0d27f Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Fri, 7 Mar 2025 15:56:47 +0530 Subject: [PATCH 33/39] test to confirm a shared user cannot be re-shared from a sub organization. --- .../management/v1/UserSharingBaseTest.java | 64 ++++- .../management/v1/UserSharingFailureTest.java | 271 +++++++++++++++++- .../management/v1/UserSharingSuccessTest.java | 2 + 3 files changed, 320 insertions(+), 17 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index e26a59bfdc1..3283d5a3746 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -21,8 +21,12 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import io.restassured.path.json.JsonPath; import io.restassured.response.Response; import org.apache.commons.lang.StringUtils; +import org.apache.http.Header; +import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; @@ -30,6 +34,8 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.message.BasicHeader; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; @@ -72,6 +78,8 @@ import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.wso2.identity.integration.test.restclients.RestBaseClient.CONTENT_TYPE_ATTRIBUTE; +import static org.wso2.identity.integration.test.restclients.RestBaseClient.TENANT_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.USER_AGENT_ATTRIBUTE; /** @@ -84,29 +92,35 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected OAuth2RestClient oAuth2RestClient; protected SCIM2RestClient scim2RestClient; protected OrgMgtRestClient orgMgtRestClient; + protected HttpClient httpClient; protected Map> userDetails; protected Map> orgDetails; protected Map> appDetails; protected Map> roleDetails; - private static final String API_DEFINITION_NAME = "organization-user-share.yaml"; + protected static final String API_DEFINITION_NAME = "organization-user-share.yaml"; protected static final String AUTHORIZED_APIS_JSON = "user-sharing-apis.json"; - static final String API_VERSION = "v1"; + protected static final String API_VERSION = "v1"; private static final String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1"; - static final String SERVER_URL_VERSION = "/api/server/v1"; - static final String USER_SHARING_API_BASE_PATH = "/users"; - static final String SHARE_PATH = "/share"; - static final String SHARE_WITH_ALL_PATH = "/share-with-all"; - static final String UNSHARE_PATH = "/unshare"; - static final String UNSHARE_WITH_ALL_PATH = "/unshare-with-all"; - static final String SHARED_ORGANIZATIONS_PATH = "/shared-organizations"; - static final String SHARED_ROLES_PATH = "/shared-roles"; + protected static final String API_SERVER_BASE_PATH = "/api/server/v1"; + protected static final String ORGANIZATION_API_PATH = "/o"; + protected static final String USER_SHARING_API_BASE_PATH = "/users"; + protected static final String SHARE_PATH = "/share"; + protected static final String SHARE_WITH_ALL_PATH = "/share-with-all"; + protected static final String UNSHARE_PATH = "/unshare"; + protected static final String UNSHARE_WITH_ALL_PATH = "/unshare-with-all"; + protected static final String SHARED_ORGANIZATIONS_PATH = "/shared-organizations"; + protected static final String SHARED_ROLES_PATH = "/shared-roles"; - static final String PATH_SEPARATOR = "/"; - static final String QUERY_PARAM_SEPARATOR = "?"; - static final String QUERY_PARAM_VALUE_SEPARATOR = "="; + protected static final String PATH_SEPARATOR = "/"; + protected static final String QUERY_PARAM_SEPARATOR = "?"; + protected static final String QUERY_PARAM_VALUE_SEPARATOR = "="; + + protected static final String HEADER_AUTHORIZATION = "Authorization"; + protected static final String HEADER_AUTHORIZATION_VALUE_BEARER = "Bearer "; + protected static final String HEADER_CONTENT_TYPE = "Content-Type"; protected static final String SHARED_TYPE_SHARED = "SHARED"; protected static final String SHARED_TYPE_OWNER = "OWNER"; @@ -244,6 +258,7 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_TYPE = "roles.audience.type"; protected static final String ERROR_SETUP_SWAGGER_DEFINITION = "Unable to read the swagger definition %s from %s"; + protected static final String SHARED_USER_ID_JSON_PATH = "sharedOrganizations.find { it.orgName == '%s' }.sharedUserId"; static { try { @@ -273,6 +288,14 @@ public void testFinish() { // Request Sending Methods. + protected HttpResponse getResponseOfPostToSubOrg(String path, String body, String token) throws Exception { + + HttpPost request = new HttpPost(serverURL + TENANT_PATH + tenant + ORGANIZATION_API_PATH + API_SERVER_BASE_PATH + path); + request.setHeaders(getHeaders(token)); + request.setEntity(new StringEntity(body)); + return httpClient.execute(request); + } + protected HttpResponse sendGetRequest(String endpointURL, HttpClient client) throws IOException { HttpGet request = new HttpGet(endpointURL); @@ -454,7 +477,7 @@ protected RoleWithAudience createRoleWithAudience(String roleName, String displa protected String getSharedOrgsRolesRef(String userId, String orgId) { - return SERVER_URL_VERSION + USER_SHARING_API_BASE_PATH + PATH_SEPARATOR + userId + SHARED_ROLES_PATH + QUERY_PARAM_SEPARATOR + QUERY_PARAM_ORG_ID + QUERY_PARAM_VALUE_SEPARATOR + orgId; + return API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + PATH_SEPARATOR + userId + SHARED_ROLES_PATH + QUERY_PARAM_SEPARATOR + QUERY_PARAM_ORG_ID + QUERY_PARAM_VALUE_SEPARATOR + orgId; } protected void storeRoleDetails(String audienceType, String audienceName, Map rolesOfAudience) { @@ -996,9 +1019,22 @@ private void deleteOrganizationIfExists(String orgId) throws Exception { // Helper methods. + protected String extractSharedUserId(Response response, String orgName) { + JsonPath jsonPath = response.jsonPath(); + return jsonPath.getString(String.format(SHARED_USER_ID_JSON_PATH, orgName)); + } + protected String toJSONString(java.lang.Object object) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); return gson.toJson(object); } + + private Header[] getHeaders(String token) { + return new Header[]{ + new BasicHeader(HEADER_AUTHORIZATION, HEADER_AUTHORIZATION_VALUE_BEARER + token), + new BasicHeader(HEADER_CONTENT_TYPE, String.valueOf(ContentType.JSON)) + }; + } + } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index a5ec8c0f307..02801c09f65 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -18,15 +18,28 @@ package org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1; +import io.restassured.http.ContentType; +import io.restassured.path.json.JsonPath; import io.restassured.response.Response; +import io.restassured.response.ResponseBody; +import org.apache.commons.codec.binary.Base64; +import org.apache.http.Header; +import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicHeader; import org.json.JSONObject; +import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.identity.integration.common.utils.ISIntegrationTest; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; @@ -43,7 +56,12 @@ import java.util.List; import java.util.Map; +import javax.servlet.http.HttpServletResponse; + import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.everyItem; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; @@ -52,6 +70,10 @@ import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_AND_FUTURE_ORGS; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_ORGS_ONLY; +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; +import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.SCIM2_USERS_ENDPOINT; /** * Tests for failure cases of the User Sharing REST APIs. @@ -231,7 +253,7 @@ public void testGeneralUserSharing(List userIds, } } - // General User Unsharing. + // Invalid General User Unsharing. @DataProvider(name = "generalUserUnsharingWithInvalidDetailsDataProvider") public Object[][] generalUserUnsharingWithInvalidDetailsDataProvider() { @@ -283,7 +305,7 @@ public void testGeneralUserUnsharing(List userIds, } } - // Selective User Unsharing. + // Invalid Selective User Unsharing. @DataProvider(name = "selectiveUserUnsharingDataProvider") public Object[][] selectiveUserUnsharingDataProvider() { @@ -339,6 +361,133 @@ public void testSelectiveUserUnsharing(List userIds, } } + // Invalid Selective User Sharing for re-sharing. + + @DataProvider(name = "selectiveUserSharingWithReSharingDataProvider") + public Object[][] selectiveUserSharingWithReSharingDataProvider() { + + // Test case 1: User re-sharing. + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingWithValidDetailsTestCase1(); + Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingWithValidDetailsTestCase1(); + Map> organizationsForReSharingTestCase1 = setOrganizationsForSelectiveUserSharingWithReSharingTestCase1(); + Map expectedResultsForReSharingTestCase1 = setExpectedResultsForSelectiveUserSharingWithReSharingTestCase1(); + Map reSharingSubOrgDetailsForTestCase1 = orgDetails.get(L1_ORG_1_NAME); + + return new Object[][] { + { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1, organizationsForReSharingTestCase1, expectedResultsForReSharingTestCase1, reSharingSubOrgDetailsForTestCase1 } + }; + } + + @Test(dataProvider = "selectiveUserSharingWithReSharingDataProvider") + public void testSelectiveUserSharingWithReSharing(List userIds, + Map> organizations, + Map expectedResults, + Map> organizationsForReSharing, + Map expectedResultsForReSharing, + Map reSharingSubOrgDetails) throws Exception { + + List sharedUserIds = new ArrayList<>(); + UserShareRequestBody requestBody = new UserShareRequestBody() + .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) + .organizations(getOrganizationsForSelectiveUserSharing(organizations)); + + Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); + + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + + Response sharedOrgsResponseOfUserId = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ORGANIZATIONS_PATH); + String sharedUserId = extractSharedUserId(sharedOrgsResponseOfUserId, reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_NAME).toString()); + sharedUserIds.add(sharedUserId); + } + + UserShareRequestBody requestBodyForReSharing = new UserShareRequestBody() + .userCriteria(getUserCriteriaForBaseUserSharing(sharedUserIds)) + .organizations(getOrganizationsForSelectiveUserSharing(organizationsForReSharing)); + + HttpResponse responseOfReSharing = getResponseOfPostToSubOrg(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBodyForReSharing), reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN).toString()); + + Assert.assertEquals(responseOfReSharing.getStatusLine().getStatusCode(), HttpStatus.SC_ACCEPTED); + + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : sharedUserIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResultsForReSharing); + } + } + + // Invalid General User Sharing for re-sharing. + + @DataProvider(name = "generalUserSharingWithReSharingDataProvider") + public Object[][] generalUserSharingWithReSharingDataProvider() { + + // Test case 1: User re-sharing. + List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); + Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + Map expectedResultsForReSharingTestCase1 = setExpectedResultsForGenealUserSharingWithReSharingTestCase1(); + Map reSharingSubOrgDetailsForTestCase1 = orgDetails.get(L1_ORG_1_NAME); + + return new Object[][] { + { userIdsForTestCase1, policyWithRolesForTestCase1, expectedResultsForTestCase1, expectedResultsForReSharingTestCase1, reSharingSubOrgDetailsForTestCase1 } + }; + } + + @Test(dataProvider = "generalUserSharingWithReSharingDataProvider") + public void testGeneralUserSharingWithReSharing(List userIds, Map policyWithRoles, + Map expectedResults, + Map expectedResultsForReSharing, + Map reSharingSubOrgDetails) throws Exception { + + List sharedUserIds = new ArrayList<>(); + UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() + .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) + .policy(getPolicyEnumForGeneralUserSharing(policyWithRoles)) + .roles(getRolesForGeneralUserSharing(policyWithRoles)); + + Response response = + getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, toJSONString(requestBody)); + + response.then() + .log().ifValidationFails() + .assertThat() + .statusCode(HttpStatus.SC_ACCEPTED) + .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) + .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); + + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + + Response sharedOrgsResponseOfUserId = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ORGANIZATIONS_PATH); + String sharedUserId = extractSharedUserId(sharedOrgsResponseOfUserId, reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_NAME).toString()); + sharedUserIds.add(sharedUserId); + } + + UserShareWithAllRequestBody requestBodyForReSharing = new UserShareWithAllRequestBody() + .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) + .policy(getPolicyEnumForGeneralUserSharing(policyWithRoles)) + .roles(getRolesForGeneralUserSharing(policyWithRoles)); + + HttpResponse responseOfReSharing = getResponseOfPostToSubOrg(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, + toJSONString(requestBodyForReSharing), reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN).toString()); + + Assert.assertEquals(responseOfReSharing.getStatusLine().getStatusCode(), HttpStatus.SC_ACCEPTED); + + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : sharedUserIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResultsForReSharing); + } + } + //todo next remove thread sleep. // Test cases builders. @@ -683,12 +832,69 @@ private Map setExpectedResultsForGeneralUserSharingWithInvalidDe return expectedResults; } + private Map> setOrganizationsForSelectiveUserSharingWithValidDetailsTestCase1() { + + Map> organizations = new HashMap<>(); + + // Organization 1 + Map org1 = new HashMap<>(); + org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); + org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + organizations.put(L1_ORG_1_NAME, org1); + + // Organization 2 + Map org2 = new HashMap<>(); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); + org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); + org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + organizations.put(L1_ORG_2_NAME, org2); + + // Organization 3 + Map org3 = new HashMap<>(); + org3.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_3_NAME)); + org3.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_3_NAME); + org3.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_ONLY); + org3.put(MAP_KEY_SELECTIVE_ROLES, Collections.emptyList()); + + organizations.put(L1_ORG_3_NAME, org3); + + return organizations; + } + + private Map setExpectedResultsForSelectiveUserSharingWithValidDetailsTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.emptyList()); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + private Map setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1() { Map policyWithRoles = new HashMap<>(); policyWithRoles.put(MAP_KEY_GENERAL_POLICY, ALL_EXISTING_ORGS_ONLY); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); return policyWithRoles; } @@ -780,6 +986,64 @@ private Map setExpectedResultsForSelectiveUserUnsharingWithInval return expectedResults; } + private Map> setOrganizationsForSelectiveUserSharingWithReSharingTestCase1() { + + Map> organizations = new HashMap<>(); + + // Organization 1 + Map org1 = new HashMap<>(); + org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L2_ORG_1_NAME)); + org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L2_ORG_1_NAME); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + + organizations.put(L2_ORG_1_NAME, org1); + + // Organization 2 + Map org2 = new HashMap<>(); + org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L2_ORG_2_NAME)); + org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L2_ORG_2_NAME); + org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); + org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( + createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + + organizations.put(L2_ORG_2_NAME, org2); + + return organizations; + } + + private Map setExpectedResultsForSelectiveUserSharingWithReSharingTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + + private Map setExpectedResultsForGenealUserSharingWithReSharingTestCase1() { + + Map expectedResults = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); + + Map> expectedRolesPerExpectedOrg = new HashMap<>(); + + expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); + + return expectedResults; + } + // Setup methods. private void setupDetailMaps() { @@ -795,6 +1059,7 @@ private void setupRestClients() throws Exception { oAuth2RestClient = new OAuth2RestClient(serverURL, tenantInfo); scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); orgMgtRestClient = new OrgMgtRestClient(context, tenantInfo, serverURL, new JSONObject(readResource(AUTHORIZED_APIS_JSON))); + httpClient = HttpClientBuilder.create().build(); } private void setupOrganizations() throws Exception { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 5896b886806..0c84e275a56 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -20,6 +20,7 @@ import io.restassured.response.Response; import org.apache.http.HttpStatus; +import org.apache.http.impl.client.HttpClientBuilder; import org.json.JSONObject; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -581,6 +582,7 @@ private void setupRestClients() throws Exception { oAuth2RestClient = new OAuth2RestClient(serverURL, tenantInfo); scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); orgMgtRestClient = new OrgMgtRestClient(context, tenantInfo, serverURL, new JSONObject(readResource(AUTHORIZED_APIS_JSON))); + httpClient = HttpClientBuilder.create().build(); } private void setupOrganizations() throws Exception { From 851ba3c7a8c2428650a1043971ebedb2b5457a03 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Fri, 7 Mar 2025 17:12:25 +0530 Subject: [PATCH 34/39] get common validation method with waiting to base class. --- .../management/v1/UserSharingBaseTest.java | 25 ++++++ .../management/v1/UserSharingFailureTest.java | 86 ++++++------------- .../management/v1/UserSharingSuccessTest.java | 28 ++---- 3 files changed, 57 insertions(+), 82 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 3283d5a3746..4adbdef42ca 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -663,6 +663,31 @@ private Map getUserNameAndUserDomain(String domainQualifiedUserN // Method to validate user shared organizations and assigned roles. + protected void validateUserSharingResults(List userIds, Map expectedResults) + throws Exception { + + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + } + } + + protected List validateUserSharingResultsAndGetSharedUsersList(List userIds, + Map reSharingSubOrgDetails, + Map expectedSharedResults) throws Exception{ + + List sharedUserIds = new ArrayList<>(); + Thread.sleep(5000); // Waiting until user sharing is completed. + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedSharedResults); + + Response sharedOrgsResponseOfUserId = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ORGANIZATIONS_PATH); + String sharedUserId = extractSharedUserId(sharedOrgsResponseOfUserId, reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_NAME).toString()); + sharedUserIds.add(sharedUserId); + } + return sharedUserIds; + } + /** * Validate that the user has been shared to the expected organizations with the expected roles. * diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 02801c09f65..ffddfa703b6 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -82,8 +82,6 @@ public class UserSharingFailureTest extends UserSharingBaseTest { private static final String INVALID_ORG_1_NAME = "invalid-org-1-name"; private static final String INVALID_ORG_1_ID = "invalid-org-1-id"; - private static final String INVALID_ORG_2_NAME = "invalid-org-2-name"; - private static final String INVALID_ORG_2_ID = "invalid-org-2-id"; private static final String INVALID_APP_1_NAME = "invalid-app-1"; private static final String INVALID_APP_2_NAME = "invalid-app-2"; @@ -180,7 +178,7 @@ public Object[][] selectiveUserSharingWithInvalidDetailsDataProvider() { @Test(dataProvider = "selectiveUserSharingWithInvalidDetailsDataProvider") public void testSelectiveUserSharing(List userIds, Map> organizations, - Map expectedResults) throws InterruptedException { + Map expectedResults) throws Exception { UserShareRequestBody requestBody = new UserShareRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) @@ -195,10 +193,7 @@ public void testSelectiveUserSharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); - } + validateUserSharingResults(userIds, expectedResults); } // Invalid General User Sharing. @@ -231,7 +226,7 @@ public Object[][] generalUserSharingWithInvalidDetailsDataProvider() { @Test(dataProvider = "generalUserSharingWithInvalidDetailsDataProvider") public void testGeneralUserSharing(List userIds, Map policyWithRoles, - Map expectedResults) throws InterruptedException { + Map expectedResults) throws Exception { UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) @@ -247,10 +242,7 @@ public void testGeneralUserSharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); - } + validateUserSharingResults(userIds, expectedResults); } // Invalid General User Unsharing. @@ -281,7 +273,7 @@ public void testGeneralUserUnsharing(List userIds, Map policyWithRoles, Map expectedSharedResults, List removingUserIds, - Map expectedResults) throws InterruptedException { + Map expectedResults) throws Exception { // Sharing valid users. testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); @@ -299,10 +291,7 @@ public void testGeneralUserUnsharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_UNSHARING)); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); - } + validateUserSharingResults(userIds, expectedResults); } // Invalid Selective User Unsharing. @@ -338,7 +327,7 @@ public void testSelectiveUserUnsharing(List userIds, Map expectedSharedResults, List removingUserIds, List removingOrgIds, - Map expectedUnsharedResults) throws InterruptedException { + Map expectedResults) throws Exception { testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); @@ -355,10 +344,7 @@ public void testSelectiveUserUnsharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_UNSHARING)); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedUnsharedResults); - } + validateUserSharingResults(userIds, expectedResults); } // Invalid Selective User Sharing for re-sharing. @@ -369,25 +355,24 @@ public Object[][] selectiveUserSharingWithReSharingDataProvider() { // Test case 1: User re-sharing. List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingWithValidDetailsTestCase1(); - Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingWithValidDetailsTestCase1(); + Map expectedSharedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingWithValidDetailsTestCase1(); Map> organizationsForReSharingTestCase1 = setOrganizationsForSelectiveUserSharingWithReSharingTestCase1(); - Map expectedResultsForReSharingTestCase1 = setExpectedResultsForSelectiveUserSharingWithReSharingTestCase1(); Map reSharingSubOrgDetailsForTestCase1 = orgDetails.get(L1_ORG_1_NAME); + Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingWithReSharingTestCase1(); return new Object[][] { - { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1, organizationsForReSharingTestCase1, expectedResultsForReSharingTestCase1, reSharingSubOrgDetailsForTestCase1 } + { userIdsForTestCase1, organizationsForTestCase1, expectedSharedResultsForTestCase1, organizationsForReSharingTestCase1, reSharingSubOrgDetailsForTestCase1, expectedResultsForTestCase1 } }; } @Test(dataProvider = "selectiveUserSharingWithReSharingDataProvider") public void testSelectiveUserSharingWithReSharing(List userIds, Map> organizations, - Map expectedResults, + Map expectedSharedResults, Map> organizationsForReSharing, - Map expectedResultsForReSharing, - Map reSharingSubOrgDetails) throws Exception { + Map reSharingSubOrgDetails, + Map expectedResults) throws Exception { - List sharedUserIds = new ArrayList<>(); UserShareRequestBody requestBody = new UserShareRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) .organizations(getOrganizationsForSelectiveUserSharing(organizations)); @@ -401,14 +386,7 @@ public void testSelectiveUserSharingWithReSharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); - - Response sharedOrgsResponseOfUserId = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ORGANIZATIONS_PATH); - String sharedUserId = extractSharedUserId(sharedOrgsResponseOfUserId, reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_NAME).toString()); - sharedUserIds.add(sharedUserId); - } + List sharedUserIds = validateUserSharingResultsAndGetSharedUsersList(userIds, reSharingSubOrgDetails, expectedSharedResults); UserShareRequestBody requestBodyForReSharing = new UserShareRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(sharedUserIds)) @@ -418,10 +396,7 @@ public void testSelectiveUserSharingWithReSharing(List userIds, Assert.assertEquals(responseOfReSharing.getStatusLine().getStatusCode(), HttpStatus.SC_ACCEPTED); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : sharedUserIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResultsForReSharing); - } + validateUserSharingResults(sharedUserIds, expectedResults); } // Invalid General User Sharing for re-sharing. @@ -432,22 +407,21 @@ public Object[][] generalUserSharingWithReSharingDataProvider() { // Test case 1: User re-sharing. List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); - Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); - Map expectedResultsForReSharingTestCase1 = setExpectedResultsForGenealUserSharingWithReSharingTestCase1(); + Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); Map reSharingSubOrgDetailsForTestCase1 = orgDetails.get(L1_ORG_1_NAME); + Map expectedResultsForTestCase1 = setExpectedResultsForGenealUserSharingWithReSharingTestCase1(); return new Object[][] { - { userIdsForTestCase1, policyWithRolesForTestCase1, expectedResultsForTestCase1, expectedResultsForReSharingTestCase1, reSharingSubOrgDetailsForTestCase1 } + { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, reSharingSubOrgDetailsForTestCase1, expectedResultsForTestCase1 } }; } @Test(dataProvider = "generalUserSharingWithReSharingDataProvider") public void testGeneralUserSharingWithReSharing(List userIds, Map policyWithRoles, - Map expectedResults, - Map expectedResultsForReSharing, - Map reSharingSubOrgDetails) throws Exception { + Map expectedSharedResults, + Map reSharingSubOrgDetails, + Map expectedResults) throws Exception { - List sharedUserIds = new ArrayList<>(); UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) .policy(getPolicyEnumForGeneralUserSharing(policyWithRoles)) @@ -463,14 +437,7 @@ public void testGeneralUserSharingWithReSharing(List userIds, Map sharedUserIds = validateUserSharingResultsAndGetSharedUsersList(userIds, reSharingSubOrgDetails, expectedSharedResults); UserShareWithAllRequestBody requestBodyForReSharing = new UserShareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) @@ -482,14 +449,9 @@ public void testGeneralUserSharingWithReSharing(List userIds, Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1() { diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 0c84e275a56..0a358973c80 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -124,7 +124,7 @@ public Object[][] selectiveUserSharingDataProvider() { @Test(dataProvider = "selectiveUserSharingDataProvider") public void testSelectiveUserSharing(List userIds, Map> organizations, - Map expectedResults) throws InterruptedException { + Map expectedResults) throws Exception { UserShareRequestBody requestBody = new UserShareRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) @@ -139,10 +139,7 @@ public void testSelectiveUserSharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); - } + validateUserSharingResults(userIds, expectedResults); } // General User Sharing. @@ -181,7 +178,7 @@ public Object[][] generalUserSharingDataProvider() { @Test(dataProvider = "generalUserSharingDataProvider") public void testGeneralUserSharing(List userIds, Map policyWithRoles, - Map expectedResults) throws InterruptedException { + Map expectedResults) throws Exception { UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) @@ -197,10 +194,7 @@ public void testGeneralUserSharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); - } + validateUserSharingResults(userIds, expectedResults); } // General User Unsharing. @@ -222,7 +216,7 @@ public Object[][] generalUserUnsharingDataProvider() { @Test(dataProvider = "generalUserUnsharingDataProvider") public void testGeneralUserUnsharing(List userIds, - Map expectedResults) throws InterruptedException { + Map expectedResults) throws Exception { UserUnshareWithAllRequestBody requestBody = new UserUnshareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserUnsharing(userIds)); @@ -236,10 +230,7 @@ public void testGeneralUserUnsharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_UNSHARING)); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); - } + validateUserSharingResults(userIds, expectedResults); } // Selective User Unsharing. @@ -272,7 +263,7 @@ public void testSelectiveUserUnsharing(List userIds, Map policyWithRoles, Map expectedSharedResults, List removingOrgIds, - Map expectedUnsharedResults) throws InterruptedException { + Map expectedResults) throws Exception { testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); @@ -289,10 +280,7 @@ public void testSelectiveUserUnsharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_UNSHARING)); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedUnsharedResults); - } + validateUserSharingResults(userIds, expectedResults); } // Test cases builders. From 15f54451828d55de5307a90e3862537ad207fc35 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sat, 8 Mar 2025 02:24:04 +0530 Subject: [PATCH 35/39] add Awaitility await() instead of thread sleep and check for the output in given intervals and proceed. --- .../tests-integration/tests-backend/pom.xml | 6 ++ .../management/v1/UserSharingBaseTest.java | 78 +++++++++++++++++-- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/pom.xml b/modules/integration/tests-integration/tests-backend/pom.xml index 4812ec51dcc..2bd6098498f 100644 --- a/modules/integration/tests-integration/tests-backend/pom.xml +++ b/modules/integration/tests-integration/tests-backend/pom.xml @@ -986,6 +986,12 @@ swagger-request-validator-restassured test + + org.awaitility + awaitility + 4.2.0 + test + org.apache.logging.log4j log4j-jul diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 4adbdef42ca..585416b761b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -73,6 +73,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.everyItem; @@ -81,6 +82,7 @@ import static org.wso2.identity.integration.test.restclients.RestBaseClient.CONTENT_TYPE_ATTRIBUTE; import static org.wso2.identity.integration.test.restclients.RestBaseClient.TENANT_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.USER_AGENT_ATTRIBUTE; +import static org.awaitility.Awaitility.await; /** * Base test class for the User Sharing REST APIs. @@ -580,7 +582,8 @@ private void shareApplication(String applicationId) throws Exception { oAuth2RestClient.shareApplication(applicationId, applicationSharePOSTRequest); // Since application sharing is an async operation, wait for some time for it to finish. - Thread.sleep(5000); + //Thread.sleep(5000); + await().atMost(5, TimeUnit.SECONDS).until(() -> true); } // Methods to add users in organizations and sub organizations for testing purposes. @@ -663,24 +666,85 @@ private Map getUserNameAndUserDomain(String domainQualifiedUserN // Method to validate user shared organizations and assigned roles. + /** + * Validates the user sharing results by checking if the users have been shared to the expected organizations + * with the expected roles. + * This method uses the Awaitility library to wait for up to 20 seconds, polling every 2 seconds, to ensure that + * the user sharing results are as expected. If the validation fails within this period, an exception is thrown. + * + * @param userIds The list of user IDs to validate. + * @param expectedResults A map containing the expected results, including the expected organization count, + * expected organization IDs, expected organization names, and expected roles per organization. + * @throws Exception If an error occurs during validation. + */ protected void validateUserSharingResults(List userIds, Map expectedResults) throws Exception { - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + final Object[] lastException = {null}; + + await().atMost(20, TimeUnit.SECONDS) + .pollInterval(2, TimeUnit.SECONDS) + .ignoreExceptions() + .until(() -> { + try { + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedResults); + } + lastException[0] = null; + return true; + } catch (AssertionError | Exception e) { + lastException[0] = e; + return false; + } + }); + + if (lastException[0] != null) { + throw (Exception) lastException[0]; } } + /** + * Validates user sharing results and retrieves the list of shared user IDs. + * This method uses the Awaitility library to wait for up to 20 seconds, polling every 2 seconds, + * to ensure that the user sharing results are as expected. If the validation fails within this period, + * an exception is thrown. + * + * @param userIds The list of user IDs to validate. + * @param reSharingSubOrgDetails The details of the sub-organization for re-sharing. + * @param expectedSharedResults A map containing the expected results, including the expected organization count, + * expected organization IDs, expected organization names, and expected roles per organization. + * @return A list of shared user IDs. + * @throws Exception If an error occurs during validation. + */ protected List validateUserSharingResultsAndGetSharedUsersList(List userIds, Map reSharingSubOrgDetails, Map expectedSharedResults) throws Exception{ + final Object[] lastException = {null}; + List sharedUserIds = new ArrayList<>(); - Thread.sleep(5000); // Waiting until user sharing is completed. - for (String userId : userIds) { - validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedSharedResults); + await().atMost(20, TimeUnit.SECONDS) + .pollInterval(2, TimeUnit.SECONDS) + .ignoreExceptions() + .until(() -> { + try { + for (String userId : userIds) { + validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(userId, expectedSharedResults); + } + lastException[0] = null; + return true; + } catch (AssertionError | Exception e) { + lastException[0] = e; + return false; + } + }); + + if (lastException[0] != null) { + throw (Exception) lastException[0]; + } + // Once assertions pass, extract shared user IDs + for (String userId : userIds) { Response sharedOrgsResponseOfUserId = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ORGANIZATIONS_PATH); String sharedUserId = extractSharedUserId(sharedOrgsResponseOfUserId, reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_NAME).toString()); sharedUserIds.add(sharedUserId); From c9108cbe836465608a706fef2285c953890bbef7 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sat, 8 Mar 2025 02:40:25 +0530 Subject: [PATCH 36/39] fix format issues and update javadoc comments in UserSharingRestClient. --- .../test/restclients/UserSharingRestClient.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserSharingRestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserSharingRestClient.java index b1a71e83f00..03dd26b1e1c 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserSharingRestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/UserSharingRestClient.java @@ -76,14 +76,13 @@ public UserSharingRestClient(String serverUrl, Tenant tenantInfo) { API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + UNSHARE_PATH, tenantDomain); generalUserUnshareEndpoint = serverUrl + ISIntegrationTest.getTenantedRelativePath( API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + UNSHARE_WITH_ALL_PATH, tenantDomain); - } /** - * Share users with all. + * Share users selectively. * * @param userShareRequestBody Selective User Share request body. - * @throws Exception If an error occurs while sharing users with all. + * @throws Exception If an error occurs while sharing users selectively. */ public void shareUsers(UserShareRequestBody userShareRequestBody) throws Exception { @@ -112,10 +111,10 @@ public void shareUsersWithAll(UserShareWithAllRequestBody userShareWithAllReques } /** - * Unshare users with all. + * Unshare users selectively. * * @param userUnshareRequestBody Selective User Unshare request body. - * @throws Exception If an error occurs while unsharing users with all. + * @throws Exception If an error occurs while unsharing users selectively. */ public void unshareUsers(UserUnshareRequestBody userUnshareRequestBody) throws Exception { From 18a813e8f4d331a5c368b2515b0e440a6bdf1f51 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sat, 8 Mar 2025 13:30:38 +0530 Subject: [PATCH 37/39] fix formatting as per 120. --- .../management/v1/UserSharingBaseTest.java | 157 ++++-- .../management/v1/UserSharingFailureTest.java | 499 +++++++++++------- .../management/v1/UserSharingSuccessTest.java | 266 ++++++---- 3 files changed, 596 insertions(+), 326 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 585416b761b..01027b750f4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -26,7 +26,6 @@ import io.restassured.response.Response; import org.apache.commons.lang.StringUtils; import org.apache.http.Header; -import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; @@ -79,7 +78,6 @@ import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.wso2.identity.integration.test.restclients.RestBaseClient.CONTENT_TYPE_ATTRIBUTE; import static org.wso2.identity.integration.test.restclients.RestBaseClient.TENANT_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.USER_AGENT_ATTRIBUTE; import static org.awaitility.Awaitility.await; @@ -104,7 +102,8 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String API_DEFINITION_NAME = "organization-user-share.yaml"; protected static final String AUTHORIZED_APIS_JSON = "user-sharing-apis.json"; protected static final String API_VERSION = "v1"; - private static final String API_PACKAGE_NAME = "org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1"; + private static final String API_PACKAGE_NAME = + "org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1"; protected static final String API_SERVER_BASE_PATH = "/api/server/v1"; protected static final String ORGANIZATION_API_PATH = "/o"; @@ -173,7 +172,7 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String L1_ORG_1_USER_2_USERNAME = "l1Org1User2"; protected static final String L1_ORG_1_USER_3_USERNAME = "l1Org1User3"; protected static final String ROOT_ORG_USER_DUPLICATED_USERNAME = "rootUserDuplicated"; - + protected static final String MAP_KEY_SELECTIVE_ORG_ID = "orgId"; protected static final String MAP_KEY_SELECTIVE_ORG_NAME = "orgName"; protected static final String MAP_KEY_SELECTIVE_POLICY = "selectivePolicy"; @@ -186,13 +185,13 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String MAP_KEY_EXPECTED_ORG_IDS = "expectedOrgIds"; protected static final String MAP_KEY_EXPECTED_ORG_NAMES = "expectedOrgNames"; protected static final String MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG = "expectedRolesPerExpectedOrg"; - + protected static final String MAP_ORG_DETAILS_KEY_ORG_NAME = "orgName"; protected static final String MAP_ORG_DETAILS_KEY_ORG_ID = "orgId"; protected static final String MAP_ORG_DETAILS_KEY_PARENT_ORG_ID = "parentOrgId"; protected static final String MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN = "orgSwitchToken"; protected static final String MAP_ORG_DETAILS_KEY_ORG_LEVEL = "orgLevel"; - + protected static final String MAP_APP_DETAILS_KEY_APP_NAME = "appName"; protected static final String MAP_APP_DETAILS_KEY_APP_ID = "appId"; protected static final String MAP_APP_DETAILS_KEY_APP_AUDIENCE = "appAudience"; @@ -260,7 +259,8 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_TYPE = "roles.audience.type"; protected static final String ERROR_SETUP_SWAGGER_DEFINITION = "Unable to read the swagger definition %s from %s"; - protected static final String SHARED_USER_ID_JSON_PATH = "sharedOrganizations.find { it.orgName == '%s' }.sharedUserId"; + protected static final String SHARED_USER_ID_JSON_PATH = + "sharedOrganizations.find { it.orgName == '%s' }.sharedUserId"; static { try { @@ -292,20 +292,22 @@ public void testFinish() { protected HttpResponse getResponseOfPostToSubOrg(String path, String body, String token) throws Exception { - HttpPost request = new HttpPost(serverURL + TENANT_PATH + tenant + ORGANIZATION_API_PATH + API_SERVER_BASE_PATH + path); + HttpPost request = + new HttpPost(serverURL + TENANT_PATH + tenant + ORGANIZATION_API_PATH + API_SERVER_BASE_PATH + path); request.setHeaders(getHeaders(token)); request.setEntity(new StringEntity(body)); return httpClient.execute(request); } - protected HttpResponse sendGetRequest(String endpointURL, HttpClient client) throws IOException { + protected HttpResponse sendGetRequest(String endpointURL, HttpClient client) throws Exception { HttpGet request = new HttpGet(endpointURL); request.setHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); return client.execute(request); } - protected HttpResponse sendPostRequest(String endpointURL, List urlParameters, HttpClient client) throws IOException { + protected HttpResponse sendPostRequest(String endpointURL, List urlParameters, HttpClient client) + throws Exception { HttpPost request = new HttpPost(endpointURL); request.setHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); @@ -347,7 +349,8 @@ protected void setOrgDetails(String orgName, String orgId, String parentId, int // Methods to add applications and roles for testing purposes. - protected Map createApplication(String appName, String audience, List roleNames) throws Exception{ + protected Map createApplication(String appName, String audience, List roleNames) + throws Exception { Map createdAppDetails = new HashMap<>(); String rootOrgAppName = appName + PATH_SEPARATOR + ROOT_ORG_NAME; @@ -359,11 +362,12 @@ protected Map createApplication(String appName, String audience, String clientSecret = oidcConfig.getClientSecret(); Map roleIdsByName = new HashMap<>(); - if (StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience)){ + if (StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience)) { Audience appRoleAudience = new Audience(APPLICATION_AUDIENCE, appId); for (String roleName : roleNames) { - RoleV2 appRole = new RoleV2(appRoleAudience, roleName, Collections.emptyList(), Collections.emptyList()); + RoleV2 appRole = + new RoleV2(appRoleAudience, roleName, Collections.emptyList(), Collections.emptyList()); String roleId = scim2RestClient.addV2Role(appRole); roleIdsByName.put(roleName, roleId); } @@ -374,7 +378,7 @@ protected Map createApplication(String appName, String audience, switchApplicationAudience(appId, AssociatedRolesConfig.AllowedAudienceEnum.ORGANIZATION); - for (String roleName: roleNames){ + for (String roleName : roleNames) { String roleId = scim2RestClient.getRoleIdByName(roleName); roleIdsByName.put(roleName, roleId); } @@ -407,7 +411,8 @@ protected Map createApplication(String appName, String audience, return createdAppDetails; } - protected Map getAppDetailsOfSubOrg(String appName, String audience, List roleNames, Map orgDetail) throws Exception { + protected Map getAppDetailsOfSubOrg(String appName, String audience, List roleNames, + Map orgDetail) throws Exception { Map subOrgAppDetails = new HashMap<>(); @@ -420,7 +425,7 @@ protected Map getAppDetailsOfSubOrg(String appName, String audie Map subOrgRoleIdsByName = StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience) ? getSubOrgRoleIdsByName(roleNames, APPLICATION_AUDIENCE, subOrgAppName, subOrgAppId, subOrgSwitchToken) : - getSubOrgRoleIdsByName(roleNames,ORGANIZATION_AUDIENCE, subOrgName, subOrgId, subOrgSwitchToken); + getSubOrgRoleIdsByName(roleNames, ORGANIZATION_AUDIENCE, subOrgName, subOrgId, subOrgSwitchToken); subOrgAppDetails.put(MAP_APP_DETAILS_KEY_APP_SUB_ORG_NAME, subOrgName); subOrgAppDetails.put(MAP_APP_DETAILS_KEY_APP_NAME, appName); @@ -432,7 +437,9 @@ protected Map getAppDetailsOfSubOrg(String appName, String audie return subOrgAppDetails; } - protected Map getSubOrgRoleIdsByName(List roleNames, String audienceType, String audienceName, String audienceValue, String subOrgSwitchToken) throws Exception { + protected Map getSubOrgRoleIdsByName(List roleNames, String audienceType, + String audienceName, String audienceValue, + String subOrgSwitchToken) throws Exception { Map roleIdsByName = new HashMap<>(); for (String roleName : roleNames) { @@ -450,7 +457,8 @@ protected Map getSubOrgRoleIdsByName(List roleNames, Str return roleIdsByName; } - protected Map createOrganizationRoles(String orgName, List orgRoleNames) throws IOException { + protected Map createOrganizationRoles(String orgName, List orgRoleNames) + throws Exception { Map orgRoleIdsByName = new HashMap<>(); for (String orgRoleName : orgRoleNames) { @@ -479,7 +487,8 @@ protected RoleWithAudience createRoleWithAudience(String roleName, String displa protected String getSharedOrgsRolesRef(String userId, String orgId) { - return API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + PATH_SEPARATOR + userId + SHARED_ROLES_PATH + QUERY_PARAM_SEPARATOR + QUERY_PARAM_ORG_ID + QUERY_PARAM_VALUE_SEPARATOR + orgId; + return API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + PATH_SEPARATOR + userId + SHARED_ROLES_PATH + + QUERY_PARAM_SEPARATOR + QUERY_PARAM_ORG_ID + QUERY_PARAM_VALUE_SEPARATOR + orgId; } protected void storeRoleDetails(String audienceType, String audienceName, Map rolesOfAudience) { @@ -499,7 +508,8 @@ private ApplicationResponseModel addApplication(String appName) throws Exception ApplicationModel application = new ApplicationModel(); List grantTypes = new ArrayList<>(); - Collections.addAll(grantTypes, GRANT_AUTHORIZATION_CODE, GRANT_IMPLICIT, GRANT_PASSWORD, GRANT_CLIENT_CREDENTIALS, GRANT_REFRESH_TOKEN, GRANT_ORGANIZATION_SWITCH); + Collections.addAll(grantTypes, GRANT_AUTHORIZATION_CODE, GRANT_IMPLICIT, GRANT_PASSWORD, + GRANT_CLIENT_CREDENTIALS, GRANT_REFRESH_TOKEN, GRANT_ORGANIZATION_SWITCH); List callBackUrls = new ArrayList<>(); Collections.addAll(callBackUrls, OAuth2Constant.CALLBACK_URL); @@ -524,14 +534,22 @@ private ApplicationResponseModel addApplication(String appName) throws Exception private ClaimConfiguration setApplicationClaimConfig() { ClaimMappings emailClaim = new ClaimMappings().applicationClaim(CLAIM_EMAIL_URI); - emailClaim.setLocalClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(CLAIM_EMAIL_URI)); + emailClaim.setLocalClaim( + new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( + CLAIM_EMAIL_URI)); ClaimMappings countryClaim = new ClaimMappings().applicationClaim(CLAIM_COUNTRY_URI); - countryClaim.setLocalClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(CLAIM_COUNTRY_URI)); + countryClaim.setLocalClaim( + new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( + CLAIM_COUNTRY_URI)); RequestedClaimConfiguration emailRequestedClaim = new RequestedClaimConfiguration(); - emailRequestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(CLAIM_EMAIL_URI)); + emailRequestedClaim.setClaim( + new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( + CLAIM_EMAIL_URI)); RequestedClaimConfiguration countryRequestedClaim = new RequestedClaimConfiguration(); - countryRequestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(CLAIM_COUNTRY_URI)); + countryRequestedClaim.setClaim( + new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( + CLAIM_COUNTRY_URI)); ClaimConfiguration claimConfiguration = new ClaimConfiguration().dialect(ClaimConfiguration.DialectEnum.CUSTOM); claimConfiguration.addClaimMappingsItem(emailClaim); @@ -553,18 +571,22 @@ private ClaimConfiguration getClaimConfigurationsWithRolesAndGroups() { private RequestedClaimConfiguration getRequestedClaim(String claimUri) { RequestedClaimConfiguration requestedClaim = new RequestedClaimConfiguration(); - requestedClaim.setClaim(new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri(claimUri)); + requestedClaim.setClaim( + new org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.Claim().uri( + claimUri)); return requestedClaim; } - private void updateRequestedClaimsOfApp(String applicationId, ClaimConfiguration claimConfigurationsForApp) throws IOException { + private void updateRequestedClaimsOfApp(String applicationId, ClaimConfiguration claimConfigurationsForApp) + throws Exception { ApplicationPatchModel applicationPatch = new ApplicationPatchModel(); applicationPatch.setClaimConfiguration(claimConfigurationsForApp); oAuth2RestClient.updateApplication(applicationId, applicationPatch); } - private void switchApplicationAudience(String appId, AssociatedRolesConfig.AllowedAudienceEnum newAudience) throws Exception { + private void switchApplicationAudience(String appId, AssociatedRolesConfig.AllowedAudienceEnum newAudience) + throws Exception { AssociatedRolesConfig associatedRolesConfigApp2 = new AssociatedRolesConfig(); associatedRolesConfigApp2.setAllowedAudience(newAudience); @@ -582,7 +604,6 @@ private void shareApplication(String applicationId) throws Exception { oAuth2RestClient.shareApplication(applicationId, applicationSharePOSTRequest); // Since application sharing is an async operation, wait for some time for it to finish. - //Thread.sleep(5000); await().atMost(5, TimeUnit.SECONDS).until(() -> true); } @@ -609,7 +630,7 @@ protected UserObject createUserObject(String userDomain, String userName, String return user; } - protected String createUser(UserObject user) throws Exception{ + protected String createUser(UserObject user) throws Exception { String userId = scim2RestClient.createUser(user); String domainQualifiedUserName = user.getUserName(); @@ -617,8 +638,10 @@ protected String createUser(UserObject user) throws Exception{ Map userDetail = new HashMap<>(); userDetail.put(MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME, domainQualifiedUserName); - userDetail.put(MAP_USER_DETAILS_KEY_USER_NAME, getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME)); - userDetail.put(MAP_USER_DETAILS_KEY_USER_DOMAIN, getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN)); + userDetail.put(MAP_USER_DETAILS_KEY_USER_NAME, + getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME)); + userDetail.put(MAP_USER_DETAILS_KEY_USER_DOMAIN, + getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN)); userDetail.put(MAP_USER_DETAILS_KEY_USER_ID, userId); userDetail.put(MAP_USER_DETAILS_KEY_IS_ROOT_ORG_USER, true); userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_NAME, ROOT_ORG_NAME); @@ -626,19 +649,22 @@ protected String createUser(UserObject user) throws Exception{ userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_LEVEL, 0); userDetails.put(domainQualifiedUserNameWithOrg, userDetail); - return userId; + return userId; } - protected String createSuborgUser(UserObject user, String suborg) throws Exception{ + protected String createSuborgUser(UserObject user, String suborg) throws Exception { - String userId = scim2RestClient.createSubOrgUser(user, (String) orgDetails.get(suborg).get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN)); + String userId = scim2RestClient.createSubOrgUser(user, + (String) orgDetails.get(suborg).get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN)); String domainQualifiedUserName = user.getUserName(); String domainQualifiedUserNameWithOrg = domainQualifiedUserName + PATH_SEPARATOR + suborg; Map userDetail = new HashMap<>(); userDetail.put(MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME, domainQualifiedUserName); - userDetail.put(MAP_USER_DETAILS_KEY_USER_NAME, getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME)); - userDetail.put(MAP_USER_DETAILS_KEY_USER_DOMAIN, getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN)); + userDetail.put(MAP_USER_DETAILS_KEY_USER_NAME, + getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME)); + userDetail.put(MAP_USER_DETAILS_KEY_USER_DOMAIN, + getUserNameAndUserDomain(domainQualifiedUserName).get(MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN)); userDetail.put(MAP_USER_DETAILS_KEY_USER_ID, userId); userDetail.put(MAP_USER_DETAILS_KEY_IS_ROOT_ORG_USER, false); userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_NAME, suborg); @@ -646,7 +672,7 @@ protected String createSuborgUser(UserObject user, String suborg) throws Excepti userDetail.put(MAP_USER_DETAILS_KEY_USER_ORG_LEVEL, orgDetails.get(suborg).get(MAP_ORG_DETAILS_KEY_ORG_LEVEL)); userDetails.put(domainQualifiedUserNameWithOrg, userDetail); - return userId; + return userId; } protected String getUserId(String userName, String userDomain, String orgName) { @@ -672,7 +698,7 @@ private Map getUserNameAndUserDomain(String domainQualifiedUserN * This method uses the Awaitility library to wait for up to 20 seconds, polling every 2 seconds, to ensure that * the user sharing results are as expected. If the validation fails within this period, an exception is thrown. * - * @param userIds The list of user IDs to validate. + * @param userIds The list of user IDs to validate. * @param expectedResults A map containing the expected results, including the expected organization count, * expected organization IDs, expected organization names, and expected roles per organization. * @throws Exception If an error occurs during validation. @@ -709,16 +735,17 @@ protected void validateUserSharingResults(List userIds, Map validateUserSharingResultsAndGetSharedUsersList(List userIds, Map reSharingSubOrgDetails, - Map expectedSharedResults) throws Exception{ + Map expectedSharedResults) + throws Exception { final Object[] lastException = {null}; @@ -745,8 +772,10 @@ protected List validateUserSharingResultsAndGetSharedUsersList(List validateUserSharingResultsAndGetSharedUsersList(List * The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are * predefined in the test data providers. @@ -775,7 +805,8 @@ protected void validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(String u (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_NAMES) ); - Map> expectedRolesPerExpectedOrg = (Map>) expectedResults.get(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG); + Map> expectedRolesPerExpectedOrg = + (Map>) expectedResults.get(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG); for (Map.Entry> entry : expectedRolesPerExpectedOrg.entrySet()) { testGetSharedRolesForOrg(userId, entry.getKey(), entry.getValue()); } @@ -789,7 +820,8 @@ protected void validateUserHasBeenSharedToExpectedOrgsWithExpectedRoles(String u * @param expectedOrgIds The expected IDs of the shared organizations. * @param expectedOrgNames The expected names of the shared organizations. */ - protected void testGetSharedOrganizations(String userId, int expectedOrgCount, List expectedOrgIds, List expectedOrgNames) { + protected void testGetSharedOrganizations(String userId, int expectedOrgCount, List expectedOrgIds, + List expectedOrgNames) { Response response = getResponseOfGet(USER_SHARING_API_BASE_PATH + "/" + userId + SHARED_ORGANIZATIONS_PATH); @@ -882,13 +914,15 @@ protected UserUnshareRequestBodyUserCriteria getUserCriteriaForBaseUserUnsharing * * @param organizations A map where the key is the organization name and the value is a map of organization details. * @return A list of `UserShareRequestBodyOrganizations` objects. + * *

* The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are * predefined in the test data providers. *

*/ @SuppressWarnings("unchecked") - protected List getOrganizationsForSelectiveUserSharing(Map> organizations) { + protected List getOrganizationsForSelectiveUserSharing( + Map> organizations) { List orgs = new ArrayList<>(); @@ -912,9 +946,10 @@ protected List getOrganizationsForSelectiveUs * @param policyWithRoles A map containing the policy and roles for general user sharing. * @return The policy enum for general user sharing. */ - protected UserShareWithAllRequestBody.PolicyEnum getPolicyEnumForGeneralUserSharing(Map policyWithRoles) { + protected UserShareWithAllRequestBody.PolicyEnum getPolicyEnumForGeneralUserSharing( + Map policyWithRoles) { - return (UserShareWithAllRequestBody.PolicyEnum)policyWithRoles.get(MAP_KEY_GENERAL_POLICY) ; + return (UserShareWithAllRequestBody.PolicyEnum) policyWithRoles.get(MAP_KEY_GENERAL_POLICY); } /** @@ -922,6 +957,7 @@ protected UserShareWithAllRequestBody.PolicyEnum getPolicyEnumForGeneralUserShar * * @param policyWithRoles A map containing the policy and roles for general user sharing. * @return A list of `RoleWithAudience` objects representing the roles for general user sharing. + * *

* The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are * predefined in the test data providers. @@ -958,10 +994,11 @@ protected void cleanUpUsers() throws Exception { String orgName = (String) entry.getValue().get(MAP_USER_DETAILS_KEY_USER_ORG_NAME); int orgLevel = (int) entry.getValue().get(MAP_USER_DETAILS_KEY_USER_ORG_LEVEL); - if(orgLevel==0) { + if (orgLevel == 0) { deleteUserIfExists(userId); } else { - deleteSubOrgUserIfExists(userId, (String) orgDetails.get(orgName).get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN)); + deleteSubOrgUserIfExists(userId, + (String) orgDetails.get(orgName).get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN)); } } } @@ -970,24 +1007,25 @@ protected void cleanUpUsers() throws Exception { * Cleans up roles for the specified audiences if exists. * Audiences will always be either ORGANIZATION_AUDIENCE or APPLICATION_AUDIENCE or both. * + * @param audiences The audiences for which roles need to be cleaned up. + * @throws Exception If an error occurs during the cleanup process. + * *

* The `@SuppressWarnings("unchecked")` annotation is used in this method because the values being cast are * predefined in the test data providers. *

- * @param audiences The audiences for which roles need to be cleaned up. - * @throws Exception If an error occurs during the cleanup process. */ @SuppressWarnings("unchecked") protected void cleanUpRoles(String... audiences) throws Exception { - for(String audience : audiences) { + for (String audience : audiences) { Map orgWiseRolesOfAudience = roleDetails.get(audience); for (Map.Entry entry : orgWiseRolesOfAudience.entrySet()) { String audienceName = entry.getKey(); Map roles = (Map) entry.getValue(); for (Map.Entry role : roles.entrySet()) { String roleId = role.getValue(); - if(audienceName.contains(ROOT_ORG_NAME)) { + if (audienceName.contains(ROOT_ORG_NAME)) { deleteRoleIfExists(roleId); } } @@ -1014,13 +1052,14 @@ protected void cleanUpApplications() throws Exception { * @throws Exception If an error occurs while deleting the organizations. */ protected void cleanUpOrganizations() throws Exception { - // Determine the deepest organization level in the hierarchy + + // Determine the deepest organization level in the hierarchy. int maxDepth = orgDetails.values().stream() .mapToInt(details -> (int) details.get(MAP_ORG_DETAILS_KEY_ORG_LEVEL)) .max() .orElse(1); - // Delete organizations starting from the deepest level down to the root level + // Delete organizations starting from the deepest level down to the root level. for (int level = maxDepth; level >= 1; level--) { for (Map.Entry> entry : orgDetails.entrySet()) { if ((int) entry.getValue().get(MAP_ORG_DETAILS_KEY_ORG_LEVEL) == level) { @@ -1054,6 +1093,7 @@ protected void closeRestClients() throws IOException { } private void deleteOrganization(String orgName, Map orgDetail) throws Exception { + String orgId = getOrgId(orgName); String parentOrgId = (String) orgDetail.get(MAP_ORG_DETAILS_KEY_PARENT_ORG_ID); @@ -1109,6 +1149,7 @@ private void deleteOrganizationIfExists(String orgId) throws Exception { // Helper methods. protected String extractSharedUserId(Response response, String orgName) { + JsonPath jsonPath = response.jsonPath(); return jsonPath.getString(String.format(SHARED_USER_ID_JSON_PATH, orgName)); } @@ -1120,10 +1161,10 @@ protected String toJSONString(java.lang.Object object) { } private Header[] getHeaders(String token) { + return new Header[]{ new BasicHeader(HEADER_AUTHORIZATION, HEADER_AUTHORIZATION_VALUE_BEARER + token), new BasicHeader(HEADER_CONTENT_TYPE, String.valueOf(ContentType.JSON)) }; } - } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index ffddfa703b6..1061cf02593 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -18,19 +18,10 @@ package org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1; -import io.restassured.http.ContentType; -import io.restassured.path.json.JsonPath; import io.restassured.response.Response; -import io.restassured.response.ResponseBody; -import org.apache.commons.codec.binary.Base64; -import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.message.BasicHeader; import org.json.JSONObject; import org.testng.Assert; import org.testng.annotations.AfterClass; @@ -39,7 +30,6 @@ import org.testng.annotations.Factory; import org.testng.annotations.Test; import org.wso2.carbon.automation.engine.context.TestUserMode; -import org.wso2.identity.integration.common.utils.ISIntegrationTest; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.RoleWithAudience; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBody; import org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody; @@ -56,24 +46,14 @@ import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletResponse; - import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.everyItem; -import static org.hamcrest.CoreMatchers.hasItems; -import static org.hamcrest.CoreMatchers.notNullValue; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; -import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.ALL_EXISTING_ORGS_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_AND_FUTURE_ORGS; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareWithAllRequestBody.PolicyEnum.IMMEDIATE_EXISTING_ORGS_ONLY; -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; -import static org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.SCIM2_USERS_ENDPOINT; /** * Tests for failure cases of the User Sharing REST APIs. @@ -143,41 +123,60 @@ public static Object[][] restAPIUserConfigProvider() { public Object[][] selectiveUserSharingWithInvalidDetailsDataProvider() { // Test case 1: User sharing with invalid roles. - List userIdsForTestCase1 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1(); - Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase1(); + List userIdsForTestCase1 = + Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map> organizationsForTestCase1 = + setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase1(); + Map expectedResultsForTestCase1 = + setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase1(); // Test case 2: User sharing with invalid organizations. - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map> organizationsForTestCase2 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase2(); - Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase2(); + List userIdsForTestCase2 = + Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map> organizationsForTestCase2 = + setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase2(); + Map expectedResultsForTestCase2 = + setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase2(); // Test case 3: User sharing with invalid users. List userIdsForTestCase3 = Arrays.asList(INVALID_USER_1_ID, INVALID_USER_2_ID); - Map> organizationsForTestCase3 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase3(); - Map expectedResultsForTestCase3 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase3(); + Map> organizationsForTestCase3 = + setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase3(); + Map expectedResultsForTestCase3 = + setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase3(); // Test case 4: User sharing with conflicting users. - List userIdsForTestCase4 = Collections.singletonList(getUserId(ROOT_ORG_USER_DUPLICATED_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map> organizationsForTestCase4 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase4(); - Map expectedResultsForTestCase4 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase4(); + List userIdsForTestCase4 = Collections.singletonList( + getUserId(ROOT_ORG_USER_DUPLICATED_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map> organizationsForTestCase4 = + setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase4(); + Map expectedResultsForTestCase4 = + setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase4(); // Test case 5: User sharing with non-immediate child organizations. - List userIdsForTestCase5 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map> organizationsForTestCase5 = setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase5(); - Map expectedResultsForTestCase5 = setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase5(); - - return new Object[][] { - { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1 }, - { userIdsForTestCase2, organizationsForTestCase2, expectedResultsForTestCase2 }, - { userIdsForTestCase3, organizationsForTestCase3, expectedResultsForTestCase3 }, - { userIdsForTestCase4, organizationsForTestCase4, expectedResultsForTestCase4 } + List userIdsForTestCase5 = + Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map> organizationsForTestCase5 = + setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase5(); + Map expectedResultsForTestCase5 = + setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase5(); + + return new Object[][]{ + {userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1}, + {userIdsForTestCase2, organizationsForTestCase2, expectedResultsForTestCase2}, + {userIdsForTestCase3, organizationsForTestCase3, expectedResultsForTestCase3}, + {userIdsForTestCase4, organizationsForTestCase4, expectedResultsForTestCase4}, + {userIdsForTestCase5, organizationsForTestCase5, expectedResultsForTestCase5} }; } @Test(dataProvider = "selectiveUserSharingWithInvalidDetailsDataProvider") - public void testSelectiveUserSharing(List userIds, - Map> organizations, + public void testSelectiveUserSharing(List userIds, Map> organizations, Map expectedResults) throws Exception { UserShareRequestBody requestBody = new UserShareRequestBody() @@ -202,38 +201,46 @@ public void testSelectiveUserSharing(List userIds, public Object[][] generalUserSharingWithInvalidDetailsDataProvider() { // Test case 1: User sharing with invalid roles. - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase1(); - Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase1(); + List userIdsForTestCase1 = + Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map policyWithRolesForTestCase1 = + setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase1(); + Map expectedResultsForTestCase1 = + setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase1(); // Test case 2: User sharing with invalid users. List userIdsForTestCase2 = Arrays.asList(INVALID_USER_1_ID, INVALID_USER_2_ID); - Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase2(); - Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase2(); + Map policyWithRolesForTestCase2 = + setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase2(); + Map expectedResultsForTestCase2 = + setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase2(); // Test case 3: User sharing with conflicting users. - List userIdsForTestCase3 = Collections.singletonList(getUserId(ROOT_ORG_USER_DUPLICATED_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase3(); - Map expectedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase3(); - - return new Object[][] { - { userIdsForTestCase1, policyWithRolesForTestCase1, expectedResultsForTestCase1 }, - { userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2 }, - { userIdsForTestCase3, policyWithRolesForTestCase3, expectedResultsForTestCase3 } + List userIdsForTestCase3 = Collections.singletonList( + getUserId(ROOT_ORG_USER_DUPLICATED_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map policyWithRolesForTestCase3 = + setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase3(); + Map expectedResultsForTestCase3 = + setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase3(); + + return new Object[][]{ + {userIdsForTestCase1, policyWithRolesForTestCase1, expectedResultsForTestCase1}, + {userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2}, + {userIdsForTestCase3, policyWithRolesForTestCase3, expectedResultsForTestCase3} }; } @Test(dataProvider = "generalUserSharingWithInvalidDetailsDataProvider") - public void testGeneralUserSharing(List userIds, - Map policyWithRoles, - Map expectedResults) throws Exception { + public void testGeneralUserSharing(List userIds, Map policyWithRoles, + Map expectedResults) throws Exception { UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) .policy(getPolicyEnumForGeneralUserSharing(policyWithRoles)) .roles(getRolesForGeneralUserSharing(policyWithRoles)); - Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, toJSONString(requestBody)); + Response response = + getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, toJSONString(requestBody)); response.then() .log().ifValidationFails() @@ -250,29 +257,37 @@ public void testGeneralUserSharing(List userIds, @DataProvider(name = "generalUserUnsharingWithInvalidDetailsDataProvider") public Object[][] generalUserUnsharingWithInvalidDetailsDataProvider() { - List sharingUserIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); - Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + List sharingUserIdsForTestCase1 = + Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map policyWithRolesForTestCase1 = + setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); + Map expectedSharedResultsForTestCase1 = + setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); List userIdsForTestCase1 = Collections.singletonList(INVALID_USER_1_ID); - Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); - - List sharingUserIdsForTestCase2 = Collections.singletonList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); - Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); + Map expectedResultsForTestCase1 = + setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + + List sharingUserIdsForTestCase2 = + Collections.singletonList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map policyWithRolesForTestCase2 = + setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); + Map expectedSharedResultsForTestCase2 = + setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); List userIdsForTestCase2 = Arrays.asList(INVALID_USER_1_ID, INVALID_USER_2_ID); - Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); + Map expectedResultsForTestCase2 = + setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); - return new Object[][] { - { sharingUserIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, userIdsForTestCase1, expectedResultsForTestCase1}, - { sharingUserIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, userIdsForTestCase2, expectedResultsForTestCase2}, + return new Object[][]{ + {sharingUserIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, + userIdsForTestCase1, expectedResultsForTestCase1}, + {sharingUserIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, + userIdsForTestCase2, expectedResultsForTestCase2}, }; } @Test(dataProvider = "generalUserUnsharingWithInvalidDetailsDataProvider") - public void testGeneralUserUnsharing(List userIds, - Map policyWithRoles, - Map expectedSharedResults, - List removingUserIds, + public void testGeneralUserUnsharing(List userIds, Map policyWithRoles, + Map expectedSharedResults, List removingUserIds, Map expectedResults) throws Exception { // Sharing valid users. @@ -282,7 +297,8 @@ public void testGeneralUserUnsharing(List userIds, UserUnshareWithAllRequestBody requestBody = new UserUnshareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserUnsharing(removingUserIds)); - Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + UNSHARE_WITH_ALL_PATH, toJSONString(requestBody)); + Response response = + getResponseOfPost(USER_SHARING_API_BASE_PATH + UNSHARE_WITH_ALL_PATH, toJSONString(requestBody)); response.then() .log().ifValidationFails() @@ -300,34 +316,47 @@ public void testGeneralUserUnsharing(List userIds, public Object[][] selectiveUserUnsharingDataProvider() { // ALL EXISTING - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); - Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); - List removingUserIdsForTestCase1 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), INVALID_USER_1_ID, INVALID_USER_2_ID); - List removingOrgIdsForTestCase1 =Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME)); - Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase1(); + List userIdsForTestCase1 = + Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map policyWithRolesForTestCase1 = + setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); + Map expectedSharedResultsForTestCase1 = + setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + List removingUserIdsForTestCase1 = + Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + INVALID_USER_1_ID, INVALID_USER_2_ID); + List removingOrgIdsForTestCase1 = Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME)); + Map expectedResultsForTestCase1 = + setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase1(); // IMMEDIATE EXISTING AND FUTURE - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); - Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); - List removingUserIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), INVALID_USER_1_ID); + List userIdsForTestCase2 = + Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map policyWithRolesForTestCase2 = + setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase2(); + Map expectedSharedResultsForTestCase2 = + setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase2(); + List removingUserIdsForTestCase2 = + Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), INVALID_USER_1_ID); List removingOrgIdsForTestCase2 = Arrays.asList(getOrgId(L1_ORG_1_NAME), INVALID_ORG_1_ID); - Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase2(); + Map expectedResultsForTestCase2 = + setExpectedResultsForSelectiveUserUnsharingWithInvalidDetailsTestCase2(); - return new Object[][] { - { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, removingUserIdsForTestCase1, removingOrgIdsForTestCase1, expectedResultsForTestCase1}, - { userIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, removingUserIdsForTestCase2, removingOrgIdsForTestCase2, expectedResultsForTestCase2} + return new Object[][]{ + {userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, + removingUserIdsForTestCase1, removingOrgIdsForTestCase1, expectedResultsForTestCase1}, + {userIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, + removingUserIdsForTestCase2, removingOrgIdsForTestCase2, expectedResultsForTestCase2} }; } @Test(dataProvider = "selectiveUserUnsharingDataProvider") - public void testSelectiveUserUnsharing(List userIds, - Map policyWithRoles, - Map expectedSharedResults, - List removingUserIds, - List removingOrgIds, - Map expectedResults) throws Exception { + public void testSelectiveUserUnsharing(List userIds, Map policyWithRoles, + Map expectedSharedResults, List removingUserIds, + List removingOrgIds, Map expectedResults) + throws Exception { testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); @@ -353,15 +382,22 @@ public void testSelectiveUserUnsharing(List userIds, public Object[][] selectiveUserSharingWithReSharingDataProvider() { // Test case 1: User re-sharing. - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingWithValidDetailsTestCase1(); - Map expectedSharedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingWithValidDetailsTestCase1(); - Map> organizationsForReSharingTestCase1 = setOrganizationsForSelectiveUserSharingWithReSharingTestCase1(); + List userIdsForTestCase1 = + Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map> organizationsForTestCase1 = + setOrganizationsForSelectiveUserSharingWithValidDetailsTestCase1(); + Map expectedSharedResultsForTestCase1 = + setExpectedResultsForSelectiveUserSharingWithValidDetailsTestCase1(); + Map> organizationsForReSharingTestCase1 = + setOrganizationsForSelectiveUserSharingWithReSharingTestCase1(); Map reSharingSubOrgDetailsForTestCase1 = orgDetails.get(L1_ORG_1_NAME); - Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingWithReSharingTestCase1(); + Map expectedResultsForTestCase1 = + setExpectedResultsForSelectiveUserSharingWithReSharingTestCase1(); - return new Object[][] { - { userIdsForTestCase1, organizationsForTestCase1, expectedSharedResultsForTestCase1, organizationsForReSharingTestCase1, reSharingSubOrgDetailsForTestCase1, expectedResultsForTestCase1 } + return new Object[][]{ + {userIdsForTestCase1, organizationsForTestCase1, expectedSharedResultsForTestCase1, + organizationsForReSharingTestCase1, reSharingSubOrgDetailsForTestCase1, + expectedResultsForTestCase1} }; } @@ -386,13 +422,16 @@ public void testSelectiveUserSharingWithReSharing(List userIds, .body(RESPONSE_STATUS, equalTo(RESPONSE_STATUS_VALUE)) .body(RESPONSE_DETAILS, equalTo(RESPONSE_DETAIL_VALUE_SHARING)); - List sharedUserIds = validateUserSharingResultsAndGetSharedUsersList(userIds, reSharingSubOrgDetails, expectedSharedResults); + List sharedUserIds = + validateUserSharingResultsAndGetSharedUsersList(userIds, reSharingSubOrgDetails, expectedSharedResults); UserShareRequestBody requestBodyForReSharing = new UserShareRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(sharedUserIds)) .organizations(getOrganizationsForSelectiveUserSharing(organizationsForReSharing)); - HttpResponse responseOfReSharing = getResponseOfPostToSubOrg(USER_SHARING_API_BASE_PATH + SHARE_PATH, toJSONString(requestBodyForReSharing), reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN).toString()); + HttpResponse responseOfReSharing = getResponseOfPostToSubOrg(USER_SHARING_API_BASE_PATH + SHARE_PATH, + toJSONString(requestBodyForReSharing), + reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN).toString()); Assert.assertEquals(responseOfReSharing.getStatusLine().getStatusCode(), HttpStatus.SC_ACCEPTED); @@ -405,14 +444,19 @@ public void testSelectiveUserSharingWithReSharing(List userIds, public Object[][] generalUserSharingWithReSharingDataProvider() { // Test case 1: User re-sharing. - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); - Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); + List userIdsForTestCase1 = + Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + Map policyWithRolesForTestCase1 = + setPolicyWithRolesForGeneralUserSharingWithValidDetailsTestCase1(); + Map expectedSharedResultsForTestCase1 = + setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); Map reSharingSubOrgDetailsForTestCase1 = orgDetails.get(L1_ORG_1_NAME); - Map expectedResultsForTestCase1 = setExpectedResultsForGenealUserSharingWithReSharingTestCase1(); + Map expectedResultsForTestCase1 = + setExpectedResultsForGenealUserSharingWithReSharingTestCase1(); - return new Object[][] { - { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, reSharingSubOrgDetailsForTestCase1, expectedResultsForTestCase1 } + return new Object[][]{ + {userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, + reSharingSubOrgDetailsForTestCase1, expectedResultsForTestCase1} }; } @@ -437,15 +481,17 @@ public void testGeneralUserSharingWithReSharing(List userIds, Map sharedUserIds = validateUserSharingResultsAndGetSharedUsersList(userIds, reSharingSubOrgDetails, expectedSharedResults); + List sharedUserIds = + validateUserSharingResultsAndGetSharedUsersList(userIds, reSharingSubOrgDetails, expectedSharedResults); UserShareWithAllRequestBody requestBodyForReSharing = new UserShareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) .policy(getPolicyEnumForGeneralUserSharing(policyWithRoles)) .roles(getRolesForGeneralUserSharing(policyWithRoles)); - HttpResponse responseOfReSharing = getResponseOfPostToSubOrg(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, - toJSONString(requestBodyForReSharing), reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN).toString()); + HttpResponse responseOfReSharing = getResponseOfPostToSubOrg(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, + toJSONString(requestBodyForReSharing), + reSharingSubOrgDetails.get(MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN).toString()); Assert.assertEquals(responseOfReSharing.getStatusLine().getStatusCode(), HttpStatus.SC_ACCEPTED); @@ -501,16 +547,29 @@ private Map setExpectedResultsForSelectiveUserSharingWithInvalid Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), + getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), + getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, + Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, + L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.emptyList()); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -555,8 +614,12 @@ private Map setExpectedResultsForSelectiveUserSharingWithInvalid expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -647,13 +710,18 @@ private Map setExpectedResultsForSelectiveUserSharingWithInvalid Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -697,8 +765,12 @@ private Map setExpectedResultsForSelectiveUserSharingWithInvalid expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -726,17 +798,29 @@ private Map setExpectedResultsForGeneralUserSharingWithInvalidDe Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), + getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), + getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, + Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, + L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -748,7 +832,9 @@ private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDe Map policyWithRoles = new HashMap<>(); policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_AND_FUTURE_ORGS); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); return policyWithRoles; } @@ -772,7 +858,8 @@ private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDe Map policyWithRoles = new HashMap<>(); policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_ORGS_ONLY); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); return policyWithRoles; } @@ -786,8 +873,10 @@ private Map setExpectedResultsForGeneralUserSharingWithInvalidDe expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -803,7 +892,8 @@ private Map> setOrganizationsForSelectiveUserSharing org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); - org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + org1.put(MAP_KEY_SELECTIVE_ROLES, + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); organizations.put(L1_ORG_1_NAME, org1); @@ -812,7 +902,9 @@ private Map> setOrganizationsForSelectiveUserSharing org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); - org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + org2.put(MAP_KEY_SELECTIVE_ROLES, + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); organizations.put(L1_ORG_2_NAME, org2); @@ -833,16 +925,29 @@ private Map setExpectedResultsForSelectiveUserSharingWithValidDe Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), + getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), + getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, + Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, + L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.emptyList()); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -866,17 +971,29 @@ private Map setExpectedResultsForGeneralUserSharingWithValidDeta Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), + getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), + getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, + Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, + L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -888,7 +1005,9 @@ private Map setPolicyWithRolesForGeneralUserSharingWithValidDeta Map policyWithRoles = new HashMap<>(); policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_ORGS_ONLY); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); return policyWithRoles; } @@ -898,13 +1017,20 @@ private Map setExpectedResultsForGeneralUserSharingWithValidDeta Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -916,15 +1042,23 @@ private Map setExpectedResultsForSelectiveUserUnsharingWithInval Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 5); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), + getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, + Arrays.asList(L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -940,8 +1074,12 @@ private Map setExpectedResultsForSelectiveUserUnsharingWithInval expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -1020,7 +1158,8 @@ private void setupRestClients() throws Exception { oAuth2RestClient = new OAuth2RestClient(serverURL, tenantInfo); scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); - orgMgtRestClient = new OrgMgtRestClient(context, tenantInfo, serverURL, new JSONObject(readResource(AUTHORIZED_APIS_JSON))); + orgMgtRestClient = new OrgMgtRestClient(context, tenantInfo, serverURL, + new JSONObject(readResource(AUTHORIZED_APIS_JSON))); httpClient = HttpClientBuilder.create().build(); } @@ -1042,7 +1181,8 @@ private void setupOrganizations() throws Exception { protected void setupApplicationsAndRoles() throws Exception { - Map rootOrgOrganizationRoles = createOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); + Map rootOrgOrganizationRoles = + createOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(rootOrgOrganizationRoles.keySet())); @@ -1058,6 +1198,7 @@ private void setupUsers() throws Exception { createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_1_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_2_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, L1_ORG_1_USER_3_USERNAME, L1_ORG_1_NAME), L1_ORG_1_NAME); - createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_DUPLICATED_USERNAME, ROOT_ORG_NAME), L1_ORG_1_NAME); + createSuborgUser(createUserObject(USER_DOMAIN_PRIMARY, ROOT_ORG_USER_DUPLICATED_USERNAME, ROOT_ORG_NAME), + L1_ORG_1_NAME); } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index 0a358973c80..cebb0c7685d 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -107,24 +107,27 @@ public static Object[][] restAPIUserConfigProvider() { @DataProvider(name = "selectiveUserSharingDataProvider") public Object[][] selectiveUserSharingDataProvider() { - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase1 = + Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map> organizationsForTestCase1 = setOrganizationsForSelectiveUserSharingTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserSharingTestCase1(); - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase2 = + Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map> organizationsForTestCase2 = setOrganizationsForSelectiveUserSharingTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserSharingTestCase2(); - return new Object[][] { - { userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1 }, - { userIdsForTestCase2, organizationsForTestCase2, expectedResultsForTestCase2 } + return new Object[][]{ + {userIdsForTestCase1, organizationsForTestCase1, expectedResultsForTestCase1}, + {userIdsForTestCase2, organizationsForTestCase2, expectedResultsForTestCase2} }; } @Test(dataProvider = "selectiveUserSharingDataProvider") - public void testSelectiveUserSharing(List userIds, - Map> organizations, - Map expectedResults) throws Exception { + public void testSelectiveUserSharing(List userIds, Map> organizations, + Map expectedResults) throws Exception { UserShareRequestBody requestBody = new UserShareRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) @@ -148,44 +151,51 @@ public void testSelectiveUserSharing(List userIds, public Object[][] generalUserSharingDataProvider() { // ALL EXISTING - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase1 = + Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); Map expectedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); // IMMEDIATE EXISTING AND FUTURE - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase2 = + Arrays.asList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); Map expectedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); // IMMEDIATE EXISTING - List userIdsForTestCase3 = Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase3 = + Collections.singletonList(getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase3 = setPolicyWithRolesForGeneralUserSharingTestCase3(); Map expectedResultsForTestCase3 = setExpectedResultsForGeneralUserSharingTestCase3(); // ALL EXISTING AND FUTURE - List userIdsForTestCase4 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase4 = + Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase4 = setPolicyWithRolesForGeneralUserSharingTestCase4(); Map expectedResultsForTestCase4 = setExpectedResultsForGeneralUserSharingTestCase4(); - return new Object[][] { - { userIdsForTestCase1, policyWithRolesForTestCase1, expectedResultsForTestCase1 }, - { userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2 }, - { userIdsForTestCase3, policyWithRolesForTestCase3, expectedResultsForTestCase3 }, - { userIdsForTestCase4, policyWithRolesForTestCase4, expectedResultsForTestCase4 } + return new Object[][]{ + {userIdsForTestCase1, policyWithRolesForTestCase1, expectedResultsForTestCase1}, + {userIdsForTestCase2, policyWithRolesForTestCase2, expectedResultsForTestCase2}, + {userIdsForTestCase3, policyWithRolesForTestCase3, expectedResultsForTestCase3}, + {userIdsForTestCase4, policyWithRolesForTestCase4, expectedResultsForTestCase4} }; } @Test(dataProvider = "generalUserSharingDataProvider") - public void testGeneralUserSharing(List userIds, - Map policyWithRoles, - Map expectedResults) throws Exception { + public void testGeneralUserSharing(List userIds, Map policyWithRoles, + Map expectedResults) throws Exception { UserShareWithAllRequestBody requestBody = new UserShareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserSharing(userIds)) .policy(getPolicyEnumForGeneralUserSharing(policyWithRoles)) .roles(getRolesForGeneralUserSharing(policyWithRoles)); - Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, toJSONString(requestBody)); + Response response = + getResponseOfPost(USER_SHARING_API_BASE_PATH + SHARE_WITH_ALL_PATH, toJSONString(requestBody)); response.then() .log().ifValidationFails() @@ -202,26 +212,30 @@ public void testGeneralUserSharing(List userIds, @DataProvider(name = "generalUserUnsharingDataProvider") public Object[][] generalUserUnsharingDataProvider() { - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase1 = + Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase2 = + Arrays.asList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); List userIdsForTestCase3 = Collections.emptyList(); Map expectedResultsForTestCase = setExpectedResultsForGeneralUserUnsharingTestCase1(); - return new Object[][] { - { userIdsForTestCase1, expectedResultsForTestCase}, - { userIdsForTestCase2, expectedResultsForTestCase}, - { userIdsForTestCase3, expectedResultsForTestCase} + return new Object[][]{ + {userIdsForTestCase1, expectedResultsForTestCase}, + {userIdsForTestCase2, expectedResultsForTestCase}, + {userIdsForTestCase3, expectedResultsForTestCase} }; } @Test(dataProvider = "generalUserUnsharingDataProvider") - public void testGeneralUserUnsharing(List userIds, - Map expectedResults) throws Exception { + public void testGeneralUserUnsharing(List userIds, Map expectedResults) throws Exception { UserUnshareWithAllRequestBody requestBody = new UserUnshareWithAllRequestBody() .userCriteria(getUserCriteriaForBaseUserUnsharing(userIds)); - Response response = getResponseOfPost(USER_SHARING_API_BASE_PATH + UNSHARE_WITH_ALL_PATH, toJSONString(requestBody)); + Response response = + getResponseOfPost(USER_SHARING_API_BASE_PATH + UNSHARE_WITH_ALL_PATH, toJSONString(requestBody)); response.then() .log().ifValidationFails() @@ -239,31 +253,34 @@ public void testGeneralUserUnsharing(List userIds, public Object[][] selectiveUserUnsharingDataProvider() { // ALL EXISTING - List userIdsForTestCase1 = Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase1 = + Collections.singletonList(getUserId(ROOT_ORG_USER_1_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase1 = setPolicyWithRolesForGeneralUserSharingTestCase1(); Map expectedSharedResultsForTestCase1 = setExpectedResultsForGeneralUserSharingTestCase1(); List removingOrgIdsForTestCase1 = Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME)); Map expectedResultsForTestCase1 = setExpectedResultsForSelectiveUserUnsharingTestCase1(); // IMMEDIATE EXISTING AND FUTURE - List userIdsForTestCase2 = Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); + List userIdsForTestCase2 = + Arrays.asList(getUserId(ROOT_ORG_USER_3_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME), + getUserId(ROOT_ORG_USER_2_USERNAME, USER_DOMAIN_PRIMARY, ROOT_ORG_NAME)); Map policyWithRolesForTestCase2 = setPolicyWithRolesForGeneralUserSharingTestCase2(); Map expectedSharedResultsForTestCase2 = setExpectedResultsForGeneralUserSharingTestCase2(); List removingOrgIdsForTestCase2 = Collections.singletonList(getOrgId(L1_ORG_1_NAME)); Map expectedResultsForTestCase2 = setExpectedResultsForSelectiveUserUnsharingTestCase2(); - return new Object[][] { - { userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, removingOrgIdsForTestCase1, expectedResultsForTestCase1}, - { userIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, removingOrgIdsForTestCase2, expectedResultsForTestCase2} + return new Object[][]{ + {userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, + removingOrgIdsForTestCase1, expectedResultsForTestCase1}, + {userIdsForTestCase2, policyWithRolesForTestCase2, expectedSharedResultsForTestCase2, + removingOrgIdsForTestCase2, expectedResultsForTestCase2} }; } @Test(dataProvider = "selectiveUserUnsharingDataProvider") - public void testSelectiveUserUnsharing(List userIds, - Map policyWithRoles, - Map expectedSharedResults, - List removingOrgIds, - Map expectedResults) throws Exception { + public void testSelectiveUserUnsharing(List userIds, Map policyWithRoles, + Map expectedSharedResults, List removingOrgIds, + Map expectedResults) throws Exception { testGeneralUserSharing(userIds, policyWithRoles, expectedSharedResults); @@ -294,7 +311,8 @@ private Map> setOrganizationsForSelectiveUserSharing org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); - org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + org1.put(MAP_KEY_SELECTIVE_ROLES, + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); organizations.put(L1_ORG_1_NAME, org1); @@ -303,7 +321,9 @@ private Map> setOrganizationsForSelectiveUserSharing org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); - org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + org2.put(MAP_KEY_SELECTIVE_ROLES, + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); organizations.put(L1_ORG_2_NAME, org2); @@ -324,16 +344,29 @@ private Map setExpectedResultsForSelectiveUserSharingTestCase1() Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), + getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), + getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, + Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, + L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.emptyList()); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -350,7 +383,9 @@ private Map> setOrganizationsForSelectiveUserSharing org2.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_2_NAME)); org2.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_2_NAME); org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); - org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList(createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + org2.put(MAP_KEY_SELECTIVE_ROLES, + Arrays.asList(createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_2, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); organizations.put(L1_ORG_2_NAME, org2); @@ -359,7 +394,8 @@ private Map> setOrganizationsForSelectiveUserSharing org3.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_3_NAME)); org3.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_3_NAME); org3.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN); - org3.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); + org3.put(MAP_KEY_SELECTIVE_ROLES, + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); organizations.put(L1_ORG_3_NAME, org3); @@ -371,13 +407,19 @@ private Map setExpectedResultsForSelectiveUserSharingTestCase2() Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_2, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_2, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -389,7 +431,8 @@ private Map setPolicyWithRolesForGeneralUserSharingTestCase1() { Map policyWithRoles = new HashMap<>(); policyWithRoles.put(MAP_KEY_GENERAL_POLICY, ALL_EXISTING_ORGS_ONLY); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); return policyWithRoles; } @@ -399,17 +442,29 @@ private Map setExpectedResultsForGeneralUserSharingTestCase1() { Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), + getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), + getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, + Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, + L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -421,7 +476,9 @@ private Map setPolicyWithRolesForGeneralUserSharingTestCase2() { Map policyWithRoles = new HashMap<>(); policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_AND_FUTURE_ORGS); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); return policyWithRoles; } @@ -431,13 +488,20 @@ private Map setExpectedResultsForGeneralUserSharingTestCase2() { Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -449,7 +513,8 @@ private Map setPolicyWithRolesForGeneralUserSharingTestCase3() { Map policyWithRoles = new HashMap<>(); policyWithRoles.put(MAP_KEY_GENERAL_POLICY, IMMEDIATE_EXISTING_ORGS_ONLY); - policyWithRoles.put(MAP_KEY_GENERAL_ROLES, Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + policyWithRoles.put(MAP_KEY_GENERAL_ROLES, + Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); return policyWithRoles; } @@ -459,13 +524,17 @@ private Map setExpectedResultsForGeneralUserSharingTestCase3() { Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 3); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L1_ORG_3_NAME))); expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_1_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -487,8 +556,13 @@ private Map setExpectedResultsForGeneralUserSharingTestCase4() { Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 7); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L1_ORG_1_NAME), getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), + getOrgId(L3_ORG_1_NAME), getOrgId(L1_ORG_2_NAME), getOrgId(L2_ORG_3_NAME), + getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, + Arrays.asList(L1_ORG_1_NAME, L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L1_ORG_2_NAME, L2_ORG_3_NAME, + L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), Collections.emptyList()); @@ -523,15 +597,23 @@ private Map setExpectedResultsForSelectiveUserUnsharingTestCase1 Map expectedResults = new HashMap<>(); expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 5); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Arrays.asList(getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); + expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, + Arrays.asList(getOrgId(L2_ORG_1_NAME), getOrgId(L2_ORG_2_NAME), getOrgId(L3_ORG_1_NAME), + getOrgId(L2_ORG_3_NAME), getOrgId(L1_ORG_3_NAME))); + expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, + Arrays.asList(L2_ORG_1_NAME, L2_ORG_2_NAME, L3_ORG_1_NAME, L2_ORG_3_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -547,8 +629,12 @@ private Map setExpectedResultsForSelectiveUserUnsharingTestCase2 expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Arrays.asList(L1_ORG_2_NAME, L1_ORG_3_NAME)); Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Arrays.asList(createRoleWithAudience(APP_ROLE_3, APP_1_NAME, APPLICATION_AUDIENCE), + createRoleWithAudience(ORG_ROLE_3, L1_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -569,7 +655,8 @@ private void setupRestClients() throws Exception { oAuth2RestClient = new OAuth2RestClient(serverURL, tenantInfo); scim2RestClient = new SCIM2RestClient(serverURL, tenantInfo); - orgMgtRestClient = new OrgMgtRestClient(context, tenantInfo, serverURL, new JSONObject(readResource(AUTHORIZED_APIS_JSON))); + orgMgtRestClient = new OrgMgtRestClient(context, tenantInfo, serverURL, + new JSONObject(readResource(AUTHORIZED_APIS_JSON))); httpClient = HttpClientBuilder.create().build(); } @@ -591,7 +678,8 @@ private void setupOrganizations() throws Exception { protected void setupApplicationsAndRoles() throws Exception { - Map rootOrgOrganizationRoles = createOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); + Map rootOrgOrganizationRoles = + createOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(rootOrgOrganizationRoles.keySet())); From 04e719f744c7c8f4542423bf3281f92c8733bb1d Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Sat, 8 Mar 2025 15:29:23 +0530 Subject: [PATCH 38/39] addressed SonarLint warns. --- .../management/v1/UserSharingFailureTest.java | 70 +++++++------------ 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 1061cf02593..6d89c8d6f7e 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -48,6 +48,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_EXISTING_IMMEDIATE_CHILDREN_ONLY; @@ -452,7 +453,7 @@ public Object[][] generalUserSharingWithReSharingDataProvider() { setExpectedResultsForGeneralUserSharingWithValidDetailsTestCase1(); Map reSharingSubOrgDetailsForTestCase1 = orgDetails.get(L1_ORG_1_NAME); Map expectedResultsForTestCase1 = - setExpectedResultsForGenealUserSharingWithReSharingTestCase1(); + setExpectedResultsForGeneralUserSharingWithReSharingTestCase1(); return new Object[][]{ {userIdsForTestCase1, policyWithRolesForTestCase1, expectedSharedResultsForTestCase1, @@ -665,16 +666,7 @@ private Map> setOrganizationsForSelectiveUserSharing private Map setExpectedResultsForSelectiveUserSharingWithInvalidDetailsTestCase3() { - Map expectedResults = new HashMap<>(); - - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); - - Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); - - return expectedResults; + return setExpectedResultsForEmptySharedResult(); } private Map> setOrganizationsForSelectiveUserSharingWithInvalidDetailsTestCase4() { @@ -749,7 +741,7 @@ private Map> setOrganizationsForSelectiveUserSharing org2.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_EXISTING_IMMEDIATE_AND_FUTURE_CHILDREN); org2.put(MAP_KEY_SELECTIVE_ROLES, Arrays.asList( createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); + createRoleWithAudience(ORG_ROLE_2, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE))); organizations.put(L1_ORG_2_NAME, org2); @@ -767,10 +759,10 @@ private Map setExpectedResultsForSelectiveUserSharingWithInvalid Map> expectedRolesPerExpectedOrg = new HashMap<>(); expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_1, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); + createRoleWithAudience(ORG_ROLE_2, L1_ORG_2_NAME, ORGANIZATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), - createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); + createRoleWithAudience(ORG_ROLE_2, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -788,7 +780,7 @@ private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDe createRoleWithAudience(INVALID_APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(INVALID_ORG_ROLE_1, ROOT_ORG_NAME, ORGANIZATION_AUDIENCE), createRoleWithAudience(INVALID_ORG_ROLE_2, INVALID_ORG_1_NAME, ORGANIZATION_AUDIENCE), - createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); return policyWithRoles; } @@ -808,19 +800,19 @@ private Map setExpectedResultsForGeneralUserSharingWithInvalidDe Map> expectedRolesPerExpectedOrg = new HashMap<>(); expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_1_NAME), - Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_1_NAME), - Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_2_NAME), - Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L3_ORG_1_NAME), - Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_2_NAME), - Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), - Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), - Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -841,16 +833,7 @@ private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDe private Map setExpectedResultsForGeneralUserSharingWithInvalidDetailsTestCase2() { - Map expectedResults = new HashMap<>(); - - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); - - Map> expectedRolesPerExpectedOrg = new HashMap<>(); - expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); - - return expectedResults; + return setExpectedResultsForEmptySharedResult(); } private Map setPolicyWithRolesForGeneralUserSharingWithInvalidDetailsTestCase3() { @@ -891,7 +874,7 @@ private Map> setOrganizationsForSelectiveUserSharing Map org1 = new HashMap<>(); org1.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_1_NAME)); org1.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_1_NAME); - org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY); + org1.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN); org1.put(MAP_KEY_SELECTIVE_ROLES, Collections.singletonList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE))); @@ -913,7 +896,8 @@ private Map> setOrganizationsForSelectiveUserSharing org3.put(MAP_KEY_SELECTIVE_ORG_ID, getOrgId(L1_ORG_3_NAME)); org3.put(MAP_KEY_SELECTIVE_ORG_NAME, L1_ORG_3_NAME); org3.put(MAP_KEY_SELECTIVE_POLICY, SELECTED_ORG_ONLY); - org3.put(MAP_KEY_SELECTIVE_ROLES, Collections.emptyList()); + org3.put(MAP_KEY_SELECTIVE_ROLES, + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); organizations.put(L1_ORG_3_NAME, org3); @@ -948,7 +932,8 @@ private Map setExpectedResultsForSelectiveUserSharingWithValidDe expectedRolesPerExpectedOrg.put(getOrgId(L2_ORG_3_NAME), Arrays.asList(createRoleWithAudience(APP_ROLE_1, APP_1_NAME, APPLICATION_AUDIENCE), createRoleWithAudience(ORG_ROLE_1, L2_ORG_3_NAME, ORGANIZATION_AUDIENCE))); - expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), Collections.emptyList()); + expectedRolesPerExpectedOrg.put(getOrgId(L1_ORG_3_NAME), + Collections.singletonList(createRoleWithAudience(APP_ROLE_2, APP_1_NAME, APPLICATION_AUDIENCE))); expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); @@ -1116,20 +1101,15 @@ private Map> setOrganizationsForSelectiveUserSharing private Map setExpectedResultsForSelectiveUserSharingWithReSharingTestCase1() { - Map expectedResults = new HashMap<>(); - - expectedResults.put(MAP_KEY_EXPECTED_ORG_COUNT, 0); - expectedResults.put(MAP_KEY_EXPECTED_ORG_IDS, Collections.emptyList()); - expectedResults.put(MAP_KEY_EXPECTED_ORG_NAMES, Collections.emptyList()); + return setExpectedResultsForEmptySharedResult(); + } - Map> expectedRolesPerExpectedOrg = new HashMap<>(); + private Map setExpectedResultsForGeneralUserSharingWithReSharingTestCase1() { - expectedResults.put(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG, expectedRolesPerExpectedOrg); - - return expectedResults; + return setExpectedResultsForEmptySharedResult(); } - private Map setExpectedResultsForGenealUserSharingWithReSharingTestCase1() { + private Map setExpectedResultsForEmptySharedResult() { Map expectedResults = new HashMap<>(); From a8a91fc0d56e04619a735e7689b9f1fdebfd7742 Mon Sep 17 00:00:00 2001 From: BimsaraBodaragama Date: Tue, 11 Mar 2025 14:07:13 +0530 Subject: [PATCH 39/39] Move constants to a separate class. --- .../management/v1/UserSharingBaseTest.java | 265 ++++++------------ .../management/v1/UserSharingFailureTest.java | 51 +++- .../management/v1/UserSharingSuccessTest.java | 49 +++- .../v1/constant/UserSharingConstants.java | 189 +++++++++++++ 4 files changed, 375 insertions(+), 179 deletions(-) create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/constant/UserSharingConstants.java diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java index 01027b750f4..9f1a7c15b5b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingBaseTest.java @@ -78,6 +78,87 @@ import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.API_DEFINITION_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.API_PACKAGE_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.API_SERVER_V1_BASE_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APPLICATION_AUDIENCE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ATTRIBUTE_USER_EMAIL_DOMAIN; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ATTRIBUTE_USER_PASSWORD; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ATTRIBUTE_USER_SCHEMA_SCIM2_USER; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.CLAIM_COUNTRY_URI; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.CLAIM_EMAIL_URI; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.CLAIM_GROUPS_URI; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.CLAIM_ROLES_URI; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ERROR_SETUP_SWAGGER_DEFINITION; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.GRANT_AUTHORIZATION_CODE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.GRANT_CLIENT_CREDENTIALS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.GRANT_IMPLICIT; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.GRANT_ORGANIZATION_SWITCH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.GRANT_PASSWORD; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.GRANT_REFRESH_TOKEN; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.HEADER_AUTHORIZATION; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.HEADER_AUTHORIZATION_VALUE_BEARER; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.HEADER_CONTENT_TYPE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_APP_DETAILS_KEY_APP_AUDIENCE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_APP_DETAILS_KEY_APP_DETAILS_OF_SUB_ORGS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_APP_DETAILS_KEY_APP_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_APP_DETAILS_KEY_APP_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_APP_DETAILS_KEY_APP_SUB_ORG_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_APP_DETAILS_KEY_CLIENT_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_APP_DETAILS_KEY_CLIENT_SECRET; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_APP_DETAILS_KEY_ROLE_IDS_BY_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_APP_DETAILS_KEY_ROLE_NAMES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ORG_COUNT; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ORG_IDS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ORG_NAMES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_GENERAL_POLICY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_GENERAL_ROLES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_ORG_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_POLICY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_ROLES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_ORG_DETAILS_KEY_ORG_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_ORG_DETAILS_KEY_ORG_LEVEL; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_ORG_DETAILS_KEY_ORG_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_ORG_DETAILS_KEY_PARENT_ORG_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DETAILS_KEY_IS_ROOT_ORG_USER; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DETAILS_KEY_USER_DOMAIN; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DETAILS_KEY_USER_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DETAILS_KEY_USER_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DETAILS_KEY_USER_ORG_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DETAILS_KEY_USER_ORG_LEVEL; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DETAILS_KEY_USER_ORG_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORGANIZATION_API_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORGANIZATION_AUDIENCE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.PATH_SEPARATOR; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.QUERY_PARAM_ORG_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.QUERY_PARAM_SEPARATOR; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.QUERY_PARAM_VALUE_SEPARATOR; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_EMPTY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_ROLES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_TYPE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_ROLES_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_ROLES_REF; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_ROLES_SIZE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_SHARED_TYPE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SHARED_ORGS_SIZE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_LINKS_SIZE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.SHARED_ORGANIZATIONS_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.SHARED_ROLES_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.SHARED_TYPE_SHARED; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.SHARED_USER_ID_JSON_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.UNDERSCORE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.USER_SHARING_API_BASE_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.TENANT_PATH; import static org.wso2.identity.integration.test.restclients.RestBaseClient.USER_AGENT_ATTRIBUTE; import static org.awaitility.Awaitility.await; @@ -99,169 +180,6 @@ public class UserSharingBaseTest extends RESTAPIServerTestBase { protected Map> appDetails; protected Map> roleDetails; - protected static final String API_DEFINITION_NAME = "organization-user-share.yaml"; - protected static final String AUTHORIZED_APIS_JSON = "user-sharing-apis.json"; - protected static final String API_VERSION = "v1"; - private static final String API_PACKAGE_NAME = - "org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1"; - - protected static final String API_SERVER_BASE_PATH = "/api/server/v1"; - protected static final String ORGANIZATION_API_PATH = "/o"; - protected static final String USER_SHARING_API_BASE_PATH = "/users"; - protected static final String SHARE_PATH = "/share"; - protected static final String SHARE_WITH_ALL_PATH = "/share-with-all"; - protected static final String UNSHARE_PATH = "/unshare"; - protected static final String UNSHARE_WITH_ALL_PATH = "/unshare-with-all"; - protected static final String SHARED_ORGANIZATIONS_PATH = "/shared-organizations"; - protected static final String SHARED_ROLES_PATH = "/shared-roles"; - - protected static final String PATH_SEPARATOR = "/"; - protected static final String QUERY_PARAM_SEPARATOR = "?"; - protected static final String QUERY_PARAM_VALUE_SEPARATOR = "="; - - protected static final String HEADER_AUTHORIZATION = "Authorization"; - protected static final String HEADER_AUTHORIZATION_VALUE_BEARER = "Bearer "; - protected static final String HEADER_CONTENT_TYPE = "Content-Type"; - - protected static final String SHARED_TYPE_SHARED = "SHARED"; - protected static final String SHARED_TYPE_OWNER = "OWNER"; - protected static final String SHARED_TYPE_INVITED = "INVITED"; - - protected static final String PATH_PARAM_USER_ID = "userId"; - protected static final String QUERY_PARAM_ORG_ID = "orgId"; - protected static final String QUERY_PARAM_LIMIT = "limit"; - protected static final String QUERY_PARAM_AFTER = "after"; - protected static final String QUERY_PARAM_BEFORE = "before"; - protected static final String QUERY_PARAM_FILTER = "filter"; - protected static final String QUERY_PARAM_RECURSIVE = "recursive"; - - protected static final String ERROR_CODE_BAD_REQUEST = "UE-10000"; - protected static final String ERROR_CODE_INVALID_PAGINATION_CURSOR = "ORG-60026"; - protected static final String ERROR_CODE_SERVER_ERROR = "SE-50000"; - - protected static final String ROOT_ORG_NAME = "Super"; - protected static final String L1_ORG_1_NAME = "L1 - Organization 1"; - protected static final String L1_ORG_2_NAME = "L1 - Organization 2"; - protected static final String L1_ORG_3_NAME = "L1 - Organization 3"; - protected static final String L2_ORG_1_NAME = "L2 - Organization 1"; - protected static final String L2_ORG_2_NAME = "L2 - Organization 2"; - protected static final String L2_ORG_3_NAME = "L2 - Organization 3"; - protected static final String L3_ORG_1_NAME = "L3 - Organization 1"; - - protected static final String ROOT_ORG_ID = "10084a8d-113f-4211-a0d5-efe36b082211"; - - protected static final String APP_1_NAME = "App 1"; - protected static final String APP_2_NAME = "App 2"; - - protected static final String APPLICATION_AUDIENCE = "application"; - protected static final String ORGANIZATION_AUDIENCE = "organization"; - - protected static final String APP_ROLE_1 = "app-role-1"; - protected static final String APP_ROLE_2 = "app-role-2"; - protected static final String APP_ROLE_3 = "app-role-3"; - protected static final String ORG_ROLE_1 = "org-role-1"; - protected static final String ORG_ROLE_2 = "org-role-2"; - protected static final String ORG_ROLE_3 = "org-role-3"; - - protected static final String USER_DOMAIN_PRIMARY = "PRIMARY"; - - protected static final String ROOT_ORG_USER_1_USERNAME = "rootUser1"; - protected static final String ROOT_ORG_USER_2_USERNAME = "rootUser2"; - protected static final String ROOT_ORG_USER_3_USERNAME = "rootUser3"; - protected static final String L1_ORG_1_USER_1_USERNAME = "l1Org1User1"; - protected static final String L1_ORG_1_USER_2_USERNAME = "l1Org1User2"; - protected static final String L1_ORG_1_USER_3_USERNAME = "l1Org1User3"; - protected static final String ROOT_ORG_USER_DUPLICATED_USERNAME = "rootUserDuplicated"; - - protected static final String MAP_KEY_SELECTIVE_ORG_ID = "orgId"; - protected static final String MAP_KEY_SELECTIVE_ORG_NAME = "orgName"; - protected static final String MAP_KEY_SELECTIVE_POLICY = "selectivePolicy"; - protected static final String MAP_KEY_SELECTIVE_ROLES = "selectiveRoles"; - - protected static final String MAP_KEY_GENERAL_POLICY = "generalPolicy"; - protected static final String MAP_KEY_GENERAL_ROLES = "generalRoles"; - - protected static final String MAP_KEY_EXPECTED_ORG_COUNT = "expectedOrgCount"; - protected static final String MAP_KEY_EXPECTED_ORG_IDS = "expectedOrgIds"; - protected static final String MAP_KEY_EXPECTED_ORG_NAMES = "expectedOrgNames"; - protected static final String MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG = "expectedRolesPerExpectedOrg"; - - protected static final String MAP_ORG_DETAILS_KEY_ORG_NAME = "orgName"; - protected static final String MAP_ORG_DETAILS_KEY_ORG_ID = "orgId"; - protected static final String MAP_ORG_DETAILS_KEY_PARENT_ORG_ID = "parentOrgId"; - protected static final String MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN = "orgSwitchToken"; - protected static final String MAP_ORG_DETAILS_KEY_ORG_LEVEL = "orgLevel"; - - protected static final String MAP_APP_DETAILS_KEY_APP_NAME = "appName"; - protected static final String MAP_APP_DETAILS_KEY_APP_ID = "appId"; - protected static final String MAP_APP_DETAILS_KEY_APP_AUDIENCE = "appAudience"; - protected static final String MAP_APP_DETAILS_KEY_CLIENT_ID = "clientId"; - protected static final String MAP_APP_DETAILS_KEY_CLIENT_SECRET = "clientSecret"; - protected static final String MAP_APP_DETAILS_KEY_ROLE_NAMES = "roleNames"; - protected static final String MAP_APP_DETAILS_KEY_ROLE_IDS_BY_NAME = "roleIdsByName"; - protected static final String MAP_APP_DETAILS_KEY_APP_DETAILS_OF_SUB_ORGS = "appDetailsOfSubOrgs"; - protected static final String MAP_APP_DETAILS_KEY_APP_SUB_ORG_NAME = "subOrgName"; - - protected static final String MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME = "domainQualifiedUserName"; - protected static final String MAP_USER_DETAILS_KEY_USER_NAME = "userName"; - protected static final String MAP_USER_DETAILS_KEY_USER_ID = "userId"; - protected static final String MAP_USER_DETAILS_KEY_USER_DOMAIN = "userDomain"; - protected static final String MAP_USER_DETAILS_KEY_USER_ORG_NAME = "userOrgName"; - protected static final String MAP_USER_DETAILS_KEY_USER_ORG_ID = "userOrgId"; - protected static final String MAP_USER_DETAILS_KEY_USER_ORG_LEVEL = "userOrgLevel"; - protected static final String MAP_USER_DETAILS_KEY_IS_ROOT_ORG_USER = "isRootOrgUser"; - - protected static final String MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME = "userName"; - protected static final String MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN = "userDomain"; - - protected static final String SCOPE_INTERNAL_USER_SHARE = "internal_user_share"; - protected static final String SCOPE_INTERNAL_USER_UNSHARE = "internal_user_unshare"; - protected static final String SCOPE_INTERNAL_USER_SHARED_ACCESS_VIEW = "internal_user_shared_access_view"; - protected static final String SCOPE_INTERNAL_ORG_USER_SHARE = "internal_org_user_share"; - protected static final String SCOPE_INTERNAL_ORG_USER_UNSHARE = "internal_org_user_unshare"; - protected static final String SCOPE_INTERNAL_ORG_USER_SHARED_ACCESS_VIEW = "internal_org_user_shared_access_view"; - - protected static final String GRANT_AUTHORIZATION_CODE = "authorization_code"; - protected static final String GRANT_IMPLICIT = "implicit"; - protected static final String GRANT_PASSWORD = "password"; - protected static final String GRANT_CLIENT_CREDENTIALS = "client_credentials"; - protected static final String GRANT_REFRESH_TOKEN = "refresh_token"; - protected static final String GRANT_ORGANIZATION_SWITCH = "organization_switch"; - - protected static final String CLAIM_EMAIL_URI = "http://wso2.org/claims/emailaddress"; - protected static final String CLAIM_COUNTRY_URI = "http://wso2.org/claims/country"; - protected static final String CLAIM_ROLES_URI = "http://wso2.org/claims/roles"; - protected static final String CLAIM_GROUPS_URI = "http://wso2.org/claims/groups"; - - protected static final String ATTRIBUTE_USER_PASSWORD = "Admin123"; - protected static final String ATTRIBUTE_USER_EMAIL_DOMAIN = "@gmail.com"; - protected static final String ATTRIBUTE_USER_SCHEMA_SCIM2_USER = "urn:ietf:params:scim:schemas:core:2.0:User"; - - protected static final String RESPONSE_STATUS = "status"; - protected static final String RESPONSE_DETAILS = "details"; - protected static final String RESPONSE_STATUS_VALUE = "Processing"; - protected static final String RESPONSE_DETAIL_VALUE_SHARING = "User sharing process triggered successfully."; - protected static final String RESPONSE_DETAIL_VALUE_UNSHARING = "User unsharing process triggered successfully."; - - protected static final String RESPONSE_LINKS_SIZE = "links.size()"; - protected static final String RESPONSE_LINKS_EMPTY = "links[0].isEmpty()"; - protected static final String RESPONSE_LINKS_SHARED_ORGS = "sharedOrganizations"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_SIZE = "sharedOrganizations.size()"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_ID = "sharedOrganizations.orgId"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_NAME = "sharedOrganizations.orgName"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_SHARED_USER_ID = "sharedOrganizations.sharedUserId"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_SHARED_TYPE = "sharedOrganizations.sharedType"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_REF = "sharedOrganizations.rolesRef"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES = "roles"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_SIZE = "roles.size()"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_NAME = "roles.displayName"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_NAME = "roles.audience.display"; - protected static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_TYPE = "roles.audience.type"; - - protected static final String ERROR_SETUP_SWAGGER_DEFINITION = "Unable to read the swagger definition %s from %s"; - protected static final String SHARED_USER_ID_JSON_PATH = - "sharedOrganizations.find { it.orgName == '%s' }.sharedUserId"; - static { try { swaggerDefinition = getAPISwaggerDefinition(API_PACKAGE_NAME, API_DEFINITION_NAME); @@ -292,8 +210,8 @@ public void testFinish() { protected HttpResponse getResponseOfPostToSubOrg(String path, String body, String token) throws Exception { - HttpPost request = - new HttpPost(serverURL + TENANT_PATH + tenant + ORGANIZATION_API_PATH + API_SERVER_BASE_PATH + path); + HttpPost request = new HttpPost( + serverURL + TENANT_PATH + tenant + ORGANIZATION_API_PATH + API_SERVER_V1_BASE_PATH + path); request.setHeaders(getHeaders(token)); request.setEntity(new StringEntity(body)); return httpClient.execute(request); @@ -353,7 +271,7 @@ protected Map createApplication(String appName, String audience, throws Exception { Map createdAppDetails = new HashMap<>(); - String rootOrgAppName = appName + PATH_SEPARATOR + ROOT_ORG_NAME; + String rootOrgAppName = appName + UNDERSCORE + ROOT_ORG_NAME; ApplicationResponseModel application = addApplication(appName); String appId = application.getId(); @@ -363,7 +281,6 @@ protected Map createApplication(String appName, String audience, Map roleIdsByName = new HashMap<>(); if (StringUtils.equalsIgnoreCase(APPLICATION_AUDIENCE, audience)) { - Audience appRoleAudience = new Audience(APPLICATION_AUDIENCE, appId); for (String roleName : roleNames) { RoleV2 appRole = @@ -373,11 +290,8 @@ protected Map createApplication(String appName, String audience, } storeRoleDetails(APPLICATION_AUDIENCE, rootOrgAppName, roleIdsByName); createdAppDetails.put(MAP_APP_DETAILS_KEY_APP_AUDIENCE, APPLICATION_AUDIENCE); - } else { - switchApplicationAudience(appId, AssociatedRolesConfig.AllowedAudienceEnum.ORGANIZATION); - for (String roleName : roleNames) { String roleId = scim2RestClient.getRoleIdByName(roleName); roleIdsByName.put(roleName, roleId); @@ -457,7 +371,7 @@ protected Map getSubOrgRoleIdsByName(List roleNames, Str return roleIdsByName; } - protected Map createOrganizationRoles(String orgName, List orgRoleNames) + protected Map setUpOrganizationRoles(String orgName, List orgRoleNames) throws Exception { Map orgRoleIdsByName = new HashMap<>(); @@ -487,7 +401,7 @@ protected RoleWithAudience createRoleWithAudience(String roleName, String displa protected String getSharedOrgsRolesRef(String userId, String orgId) { - return API_SERVER_BASE_PATH + USER_SHARING_API_BASE_PATH + PATH_SEPARATOR + userId + SHARED_ROLES_PATH + + return API_SERVER_V1_BASE_PATH + USER_SHARING_API_BASE_PATH + PATH_SEPARATOR + userId + SHARED_ROLES_PATH + QUERY_PARAM_SEPARATOR + QUERY_PARAM_ORG_ID + QUERY_PARAM_VALUE_SEPARATOR + orgId; } @@ -798,12 +712,9 @@ protected List validateUserSharingResultsAndGetSharedUsersList(List expectedResults) { - testGetSharedOrganizations( - userId, - (int) expectedResults.get(MAP_KEY_EXPECTED_ORG_COUNT), + testGetSharedOrganizations(userId, (int) expectedResults.get(MAP_KEY_EXPECTED_ORG_COUNT), (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_IDS), - (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_NAMES) - ); + (List) expectedResults.get(MAP_KEY_EXPECTED_ORG_NAMES)); Map> expectedRolesPerExpectedOrg = (Map>) expectedResults.get(MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java index 6d89c8d6f7e..1110b4d675b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingFailureTest.java @@ -47,6 +47,55 @@ import java.util.Map; import static org.hamcrest.CoreMatchers.equalTo; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.API_VERSION; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APPLICATION_AUDIENCE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_1_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_2_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_ROLE_1; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_ROLE_2; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_ROLE_3; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.AUTHORIZED_APIS_JSON; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_1_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_1_USER_1_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_1_USER_2_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_1_USER_3_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_2_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_3_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L2_ORG_1_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L2_ORG_2_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L2_ORG_3_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L3_ORG_1_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ORG_COUNT; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ORG_IDS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ORG_NAMES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_GENERAL_POLICY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_GENERAL_ROLES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_ORG_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_ORG_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_POLICY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_ROLES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORGANIZATION_AUDIENCE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORG_ROLE_1; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORG_ROLE_2; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORG_ROLE_3; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_DETAILS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_DETAIL_VALUE_SHARING; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_DETAIL_VALUE_UNSHARING; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_STATUS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_STATUS_VALUE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_USER_1_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_USER_2_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_USER_3_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_USER_DUPLICATED_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.SHARE_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.SHARE_WITH_ALL_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.UNSHARE_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.UNSHARE_WITH_ALL_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.USER_DOMAIN_PRIMARY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.USER_SHARING_API_BASE_PATH; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; @@ -1162,7 +1211,7 @@ private void setupOrganizations() throws Exception { protected void setupApplicationsAndRoles() throws Exception { Map rootOrgOrganizationRoles = - createOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); + setUpOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(rootOrgOrganizationRoles.keySet())); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java index cebb0c7685d..50d6ee8c84b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/UserSharingSuccessTest.java @@ -45,6 +45,53 @@ import java.util.Map; import static org.hamcrest.CoreMatchers.equalTo; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.API_VERSION; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APPLICATION_AUDIENCE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_1_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_2_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_ROLE_1; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_ROLE_2; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.APP_ROLE_3; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.AUTHORIZED_APIS_JSON; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_1_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_1_USER_1_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_1_USER_2_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_1_USER_3_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_2_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L1_ORG_3_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L2_ORG_1_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L2_ORG_2_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L2_ORG_3_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.L3_ORG_1_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ORG_COUNT; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ORG_IDS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ORG_NAMES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_GENERAL_POLICY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_GENERAL_ROLES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_ORG_ID; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_ORG_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_POLICY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.MAP_KEY_SELECTIVE_ROLES; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORGANIZATION_AUDIENCE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORG_ROLE_1; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORG_ROLE_2; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ORG_ROLE_3; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_DETAILS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_DETAIL_VALUE_SHARING; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_DETAIL_VALUE_UNSHARING; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_STATUS; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.RESPONSE_STATUS_VALUE; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_NAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_USER_1_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_USER_2_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.ROOT_ORG_USER_3_USERNAME; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.SHARE_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.SHARE_WITH_ALL_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.UNSHARE_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.UNSHARE_WITH_ALL_PATH; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.USER_DOMAIN_PRIMARY; +import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant.UserSharingConstants.USER_SHARING_API_BASE_PATH; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_ONLY; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_AND_FUTURE_CHILDREN; import static org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.model.UserShareRequestBodyOrganizations.PolicyEnum.SELECTED_ORG_WITH_ALL_EXISTING_CHILDREN_ONLY; @@ -679,7 +726,7 @@ private void setupOrganizations() throws Exception { protected void setupApplicationsAndRoles() throws Exception { Map rootOrgOrganizationRoles = - createOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); + setUpOrganizationRoles(ROOT_ORG_NAME, Arrays.asList(ORG_ROLE_1, ORG_ROLE_2, ORG_ROLE_3)); createApplication(APP_1_NAME, APPLICATION_AUDIENCE, Arrays.asList(APP_ROLE_1, APP_ROLE_2, APP_ROLE_3)); createApplication(APP_2_NAME, ORGANIZATION_AUDIENCE, new ArrayList<>(rootOrgOrganizationRoles.keySet())); diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/constant/UserSharingConstants.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/constant/UserSharingConstants.java new file mode 100644 index 00000000000..34c69f40593 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/user/sharing/management/v1/constant/UserSharingConstants.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.user.sharing.management.v1.constant; + +/** + * Constants for organization user sharing. + */ +public class UserSharingConstants { + + public static final String API_DEFINITION_NAME = "organization-user-share.yaml"; + public static final String AUTHORIZED_APIS_JSON = "user-sharing-apis.json"; + public static final String API_VERSION = "v1"; + public static final String API_PACKAGE_NAME = + "org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1"; + + public static final String API_SERVER_V1_BASE_PATH = "/api/server/v1"; + public static final String ORGANIZATION_API_PATH = "/o"; + public static final String USER_SHARING_API_BASE_PATH = "/users"; + public static final String SHARE_PATH = "/share"; + public static final String SHARE_WITH_ALL_PATH = "/share-with-all"; + public static final String UNSHARE_PATH = "/unshare"; + public static final String UNSHARE_WITH_ALL_PATH = "/unshare-with-all"; + public static final String SHARED_ORGANIZATIONS_PATH = "/shared-organizations"; + public static final String SHARED_ROLES_PATH = "/shared-roles"; + + public static final String PATH_SEPARATOR = "/"; + public static final String QUERY_PARAM_SEPARATOR = "?"; + public static final String QUERY_PARAM_VALUE_SEPARATOR = "="; + public static final String UNDERSCORE = "_"; + + public static final String HEADER_AUTHORIZATION = "Authorization"; + public static final String HEADER_AUTHORIZATION_VALUE_BEARER = "Bearer "; + public static final String HEADER_CONTENT_TYPE = "Content-Type"; + + public static final String SHARED_TYPE_SHARED = "SHARED"; + public static final String SHARED_TYPE_OWNER = "OWNER"; + public static final String SHARED_TYPE_INVITED = "INVITED"; + + public static final String PATH_PARAM_USER_ID = "userId"; + public static final String QUERY_PARAM_ORG_ID = "orgId"; + public static final String QUERY_PARAM_LIMIT = "limit"; + public static final String QUERY_PARAM_AFTER = "after"; + public static final String QUERY_PARAM_BEFORE = "before"; + public static final String QUERY_PARAM_FILTER = "filter"; + public static final String QUERY_PARAM_RECURSIVE = "recursive"; + + public static final String ERROR_CODE_BAD_REQUEST = "UE-10000"; + public static final String ERROR_CODE_INVALID_PAGINATION_CURSOR = "ORG-60026"; + public static final String ERROR_CODE_SERVER_ERROR = "SE-50000"; + + public static final String ROOT_ORG_NAME = "Super"; + public static final String L1_ORG_1_NAME = "L1 - Organization 1"; + public static final String L1_ORG_2_NAME = "L1 - Organization 2"; + public static final String L1_ORG_3_NAME = "L1 - Organization 3"; + public static final String L2_ORG_1_NAME = "L2 - Organization 1"; + public static final String L2_ORG_2_NAME = "L2 - Organization 2"; + public static final String L2_ORG_3_NAME = "L2 - Organization 3"; + public static final String L3_ORG_1_NAME = "L3 - Organization 1"; + + public static final String ROOT_ORG_ID = "10084a8d-113f-4211-a0d5-efe36b082211"; + + public static final String APP_1_NAME = "App 1"; + public static final String APP_2_NAME = "App 2"; + + public static final String APPLICATION_AUDIENCE = "application"; + public static final String ORGANIZATION_AUDIENCE = "organization"; + + public static final String APP_ROLE_1 = "app-role-1"; + public static final String APP_ROLE_2 = "app-role-2"; + public static final String APP_ROLE_3 = "app-role-3"; + public static final String ORG_ROLE_1 = "org-role-1"; + public static final String ORG_ROLE_2 = "org-role-2"; + public static final String ORG_ROLE_3 = "org-role-3"; + + public static final String USER_DOMAIN_PRIMARY = "PRIMARY"; + + public static final String ROOT_ORG_USER_1_USERNAME = "rootUser1"; + public static final String ROOT_ORG_USER_2_USERNAME = "rootUser2"; + public static final String ROOT_ORG_USER_3_USERNAME = "rootUser3"; + public static final String L1_ORG_1_USER_1_USERNAME = "l1Org1User1"; + public static final String L1_ORG_1_USER_2_USERNAME = "l1Org1User2"; + public static final String L1_ORG_1_USER_3_USERNAME = "l1Org1User3"; + public static final String ROOT_ORG_USER_DUPLICATED_USERNAME = "rootUserDuplicated"; + + public static final String MAP_KEY_SELECTIVE_ORG_ID = "orgId"; + public static final String MAP_KEY_SELECTIVE_ORG_NAME = "orgName"; + public static final String MAP_KEY_SELECTIVE_POLICY = "selectivePolicy"; + public static final String MAP_KEY_SELECTIVE_ROLES = "selectiveRoles"; + + public static final String MAP_KEY_GENERAL_POLICY = "generalPolicy"; + public static final String MAP_KEY_GENERAL_ROLES = "generalRoles"; + + public static final String MAP_KEY_EXPECTED_ORG_COUNT = "expectedOrgCount"; + public static final String MAP_KEY_EXPECTED_ORG_IDS = "expectedOrgIds"; + public static final String MAP_KEY_EXPECTED_ORG_NAMES = "expectedOrgNames"; + public static final String MAP_KEY_EXPECTED_ROLES_PER_EXPECTED_ORG = "expectedRolesPerExpectedOrg"; + + public static final String MAP_ORG_DETAILS_KEY_ORG_NAME = "orgName"; + public static final String MAP_ORG_DETAILS_KEY_ORG_ID = "orgId"; + public static final String MAP_ORG_DETAILS_KEY_PARENT_ORG_ID = "parentOrgId"; + public static final String MAP_ORG_DETAILS_KEY_ORG_SWITCH_TOKEN = "orgSwitchToken"; + public static final String MAP_ORG_DETAILS_KEY_ORG_LEVEL = "orgLevel"; + + public static final String MAP_APP_DETAILS_KEY_APP_NAME = "appName"; + public static final String MAP_APP_DETAILS_KEY_APP_ID = "appId"; + public static final String MAP_APP_DETAILS_KEY_APP_AUDIENCE = "appAudience"; + public static final String MAP_APP_DETAILS_KEY_CLIENT_ID = "clientId"; + public static final String MAP_APP_DETAILS_KEY_CLIENT_SECRET = "clientSecret"; + public static final String MAP_APP_DETAILS_KEY_ROLE_NAMES = "roleNames"; + public static final String MAP_APP_DETAILS_KEY_ROLE_IDS_BY_NAME = "roleIdsByName"; + public static final String MAP_APP_DETAILS_KEY_APP_DETAILS_OF_SUB_ORGS = "appDetailsOfSubOrgs"; + public static final String MAP_APP_DETAILS_KEY_APP_SUB_ORG_NAME = "subOrgName"; + + public static final String MAP_USER_DETAILS_KEY_DOMAIN_QUALIFIED_USER_NAME = "domainQualifiedUserName"; + public static final String MAP_USER_DETAILS_KEY_USER_NAME = "userName"; + public static final String MAP_USER_DETAILS_KEY_USER_ID = "userId"; + public static final String MAP_USER_DETAILS_KEY_USER_DOMAIN = "userDomain"; + public static final String MAP_USER_DETAILS_KEY_USER_ORG_NAME = "userOrgName"; + public static final String MAP_USER_DETAILS_KEY_USER_ORG_ID = "userOrgId"; + public static final String MAP_USER_DETAILS_KEY_USER_ORG_LEVEL = "userOrgLevel"; + public static final String MAP_USER_DETAILS_KEY_IS_ROOT_ORG_USER = "isRootOrgUser"; + + public static final String MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_NAME = "userName"; + public static final String MAP_USER_DOMAIN_QUALIFIED_USER_NAME_USER_DOMAIN = "userDomain"; + + public static final String SCOPE_INTERNAL_USER_SHARE = "internal_user_share"; + public static final String SCOPE_INTERNAL_USER_UNSHARE = "internal_user_unshare"; + public static final String SCOPE_INTERNAL_USER_SHARED_ACCESS_VIEW = "internal_user_shared_access_view"; + public static final String SCOPE_INTERNAL_ORG_USER_SHARE = "internal_org_user_share"; + public static final String SCOPE_INTERNAL_ORG_USER_UNSHARE = "internal_org_user_unshare"; + public static final String SCOPE_INTERNAL_ORG_USER_SHARED_ACCESS_VIEW = "internal_org_user_shared_access_view"; + + public static final String GRANT_AUTHORIZATION_CODE = "authorization_code"; + public static final String GRANT_IMPLICIT = "implicit"; + public static final String GRANT_PASSWORD = "password"; + public static final String GRANT_CLIENT_CREDENTIALS = "client_credentials"; + public static final String GRANT_REFRESH_TOKEN = "refresh_token"; + public static final String GRANT_ORGANIZATION_SWITCH = "organization_switch"; + + public static final String CLAIM_EMAIL_URI = "http://wso2.org/claims/emailaddress"; + public static final String CLAIM_COUNTRY_URI = "http://wso2.org/claims/country"; + public static final String CLAIM_ROLES_URI = "http://wso2.org/claims/roles"; + public static final String CLAIM_GROUPS_URI = "http://wso2.org/claims/groups"; + + public static final String ATTRIBUTE_USER_PASSWORD = "Admin123"; + public static final String ATTRIBUTE_USER_EMAIL_DOMAIN = "@gmail.com"; + public static final String ATTRIBUTE_USER_SCHEMA_SCIM2_USER = "urn:ietf:params:scim:schemas:core:2.0:User"; + + public static final String RESPONSE_STATUS = "status"; + public static final String RESPONSE_DETAILS = "details"; + public static final String RESPONSE_STATUS_VALUE = "Processing"; + public static final String RESPONSE_DETAIL_VALUE_SHARING = "User sharing process triggered successfully."; + public static final String RESPONSE_DETAIL_VALUE_UNSHARING = "User unsharing process triggered successfully."; + + public static final String RESPONSE_LINKS_SIZE = "links.size()"; + public static final String RESPONSE_LINKS_EMPTY = "links[0].isEmpty()"; + public static final String RESPONSE_LINKS_SHARED_ORGS = "sharedOrganizations"; + public static final String RESPONSE_LINKS_SHARED_ORGS_SIZE = "sharedOrganizations.size()"; + public static final String RESPONSE_LINKS_SHARED_ORGS_ID = "sharedOrganizations.orgId"; + public static final String RESPONSE_LINKS_SHARED_ORGS_NAME = "sharedOrganizations.orgName"; + public static final String RESPONSE_LINKS_SHARED_ORGS_SHARED_USER_ID = "sharedOrganizations.sharedUserId"; + public static final String RESPONSE_LINKS_SHARED_ORGS_SHARED_TYPE = "sharedOrganizations.sharedType"; + public static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_REF = "sharedOrganizations.rolesRef"; + public static final String RESPONSE_LINKS_SHARED_ORGS_ROLES = "roles"; + public static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_SIZE = "roles.size()"; + public static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_NAME = "roles.displayName"; + public static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_NAME = "roles.audience.display"; + public static final String RESPONSE_LINKS_SHARED_ORGS_ROLES_AUDIENCE_TYPE = "roles.audience.type"; + + public static final String ERROR_SETUP_SWAGGER_DEFINITION = "Unable to read the swagger definition %s from %s"; + public static final String SHARED_USER_ID_JSON_PATH = + "sharedOrganizations.find { it.orgName == '%s' }.sharedUserId"; +}