Skip to content

Commit

Permalink
fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
AnuradhaSK committed Oct 22, 2023
1 parent 7928bd0 commit 1927d1c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4223,8 +4223,6 @@ private void setRolesOfUser(List<String> rolesOfUser, Map<String, Group> groupMe
User scimUser) throws org.wso2.carbon.user.core.UserStoreException, CharonException,
IdentitySCIMException, BadRequestException {

// TODO: Read from config whether v1 roles ot v2 roles are used
boolean useRoleV2 = true;
// Add roles of user.
for (String roleName : rolesOfUser) {
if (CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME.equalsIgnoreCase(roleName)) {
Expand All @@ -4242,7 +4240,14 @@ private void setRolesOfUser(List<String> rolesOfUser, Map<String, Group> groupMe
groupMetaAttributesCache.put(roleName, groupObject);
}

if (useRoleV2) {
if (CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME) {
Role role = new Role();
role.setDisplayName(removeInternalDomain(groupObject.getDisplayName()));
role.setId(groupObject.getId());
String location = SCIMCommonUtils.getSCIMRoleURL(groupObject.getId());
role.setLocation(location);
scimUser.setRole(role);
} else {
RoleV2 role = new RoleV2();
role.setDisplayName(removeInternalDomain(groupObject.getDisplayName()));
role.setId(groupObject.getId());
Expand All @@ -4261,13 +4266,6 @@ private void setRolesOfUser(List<String> rolesOfUser, Map<String, Group> groupMe
return;
}
scimUser.setRoleV2(role);
} else {
Role role = new Role();
role.setDisplayName(removeInternalDomain(groupObject.getDisplayName()));
role.setId(groupObject.getId());
String location = SCIMCommonUtils.getSCIMRoleURL(groupObject.getId());
role.setLocation(location);
scimUser.setRole(role);
}
}
}
Expand Down Expand Up @@ -4472,8 +4470,6 @@ private void setGroupRoles(Group group) throws org.wso2.carbon.user.core.UserSto
List<String> rolesOfGroup = carbonUM.getHybridRoleListOfGroup(UserCoreUtil.removeDomainFromName(groupName),
UserCoreUtil.extractDomainFromName(groupName));

// TODO: read from config.
boolean useV2Roles = true;
// Add roles of group.
for (String roleName : rolesOfGroup) {
if (CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME.equalsIgnoreCase(roleName)) {
Expand All @@ -4491,7 +4487,14 @@ private void setGroupRoles(Group group) throws org.wso2.carbon.user.core.UserSto
groupMetaAttributesCache.put(roleName, groupObject);
}

if (useV2Roles) {
if (CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME) {
Role role = new Role();
role.setDisplayName(removeInternalDomain(groupObject.getDisplayName()));
role.setId(groupObject.getId());
String location = SCIMCommonUtils.getSCIMRoleURL(groupObject.getId());
role.setLocation(location);
group.setRole(role);
} else {
RoleV2 role = new RoleV2();
role.setDisplayName(removeInternalDomain(groupObject.getDisplayName()));
role.setId(groupObject.getId());
Expand All @@ -4509,13 +4512,6 @@ private void setGroupRoles(Group group) throws org.wso2.carbon.user.core.UserSto
return;
}
group.setRoleV2(role);
} else {
Role role = new Role();
role.setDisplayName(removeInternalDomain(groupObject.getDisplayName()));
role.setId(groupObject.getId());
String location = SCIMCommonUtils.getSCIMRoleURL(groupObject.getId());
role.setLocation(location);
group.setRole(role);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.ObjectFactory;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.identity.application.common.model.InboundProvisioningConfig;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
Expand Down Expand Up @@ -125,7 +126,7 @@
SCIMAttributeSchema.class, AttributeMapper.class, ClaimMetadataHandler.class, SCIMCommonUtils.class,
IdentityTenantUtil.class, AbstractUserStoreManager.class, Group.class, UserCoreUtil.class,
ApplicationManagementService.class, RolePermissionManagementService.class, SCIMCommonComponentHolder.class,
SCIMUserManager.class})
SCIMUserManager.class, CarbonConstants.class})
@PowerMockIgnore({"java.sql.*","javax.xml.*","org.w3c.dom.*","org.xml.sax.*"})
public class SCIMUserManagerTest extends PowerMockTestCase {

Expand Down Expand Up @@ -316,6 +317,10 @@ public void testGetGroup(String groupId, String roleName, String userStoreDomain
thenReturn(buildUserCoreGroupResponse(roleName, groupId, userStoreDomain));
mockStatic(SCIMCommonUtils.class);
when(SCIMCommonUtils.getSCIMGroupURL()).thenReturn("https://localhost:9443/scim2/Groups");

mockStatic(CarbonConstants.class);
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;

SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockedClaimManager);
Group result = scimUserManager.getGroup(groupId, new HashMap<>());
String actual = null;
Expand Down Expand Up @@ -425,6 +430,9 @@ public void testListGroupsWithFilter(String filter, String roleName, String user

when(mockIdentityUtil.extractDomainFromName(anyString())).thenReturn("value");

mockStatic(CarbonConstants.class);
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;

Map<String, String> scimToLocalClaimsMap = new HashMap<>();
scimToLocalClaimsMap.put("urn:ietf:params:scim:schemas:core:2.0:User:userName",
"http://wso2.org/claims/username");
Expand Down Expand Up @@ -1021,6 +1029,9 @@ public void testFilterApplicationRolesWithDomainParam(String filter, String[] ro
mockStatic(SCIMCommonUtils.class);
when(SCIMCommonUtils.getSCIMGroupURL()).thenReturn("https://localhost:9443/scim2/Groups");

mockStatic(CarbonConstants.class);
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;

SCIMUserManager scimUserManager = new SCIMUserManager(abstractUserStoreManager, mockedClaimManager);
GroupsGetResponse groupsResponse = scimUserManager
.listGroupsWithGET(node, 1, null, null, null, "Application", requiredAttributes);
Expand Down Expand Up @@ -1329,6 +1340,9 @@ public void testGetUser(Boolean isGroupsVsRolesSeparationImprovementsEnabled, Ma
when(SCIMCommonUtils.prependDomain(anyString())).thenCallRealMethod();
when(SCIMCommonUtils.isHybridRole(anyString())).thenCallRealMethod();

mockStatic(CarbonConstants.class);
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;

org.wso2.carbon.user.core.common.User user = mock(org.wso2.carbon.user.core.common.User.class);
when(user.getUserStoreDomain()).thenReturn(userStoreDomainName);
when(user.getUsername()).thenReturn((username));
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
<cxf-bundle.version>3.3.7</cxf-bundle.version>
<inbound.auth.oauth.version>6.5.3</inbound.auth.oauth.version>
<commons-collections.version>3.2.0.wso2v1</commons-collections.version>
<carbon.kernel.version>4.9.4</carbon.kernel.version>
<carbon.kernel.version>4.9.15</carbon.kernel.version>
<identity.framework.version>5.25.374</identity.framework.version>
<junit.version>4.13.1</junit.version>
<commons.lang.version>20030203.000129</commons.lang.version>
Expand Down

0 comments on commit 1927d1c

Please sign in to comment.