Skip to content

Commit

Permalink
fix: handle multiple owners for single entity for owners in HR scope …
Browse files Browse the repository at this point in the history
…matching
  • Loading branch information
Arun-KumarH committed Apr 11, 2024
1 parent 1de3f87 commit e6c5f55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/core/hierarchicalScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,20 @@ export const checkHierarchicalScope = async (ruleTarget: Target,
const reducedHRScopes = context?.subject?.hierarchical_scopes?.filter((hrObj) => hrObj?.role === ruleRole);
for (let [resourceId, owners] of resourceIdOwnersMap) {
// validate scoping Entity first
let ownerInstance: string;
let ownerInstances: string[] = [];
const entityMatch = owners?.some((ownerObj) => {
return reducedUserRoleAssocs?.some((roleObj) => {
if (roleObj?.attributes?.some((roleAttributeObject) => roleAttributeObject?.id === urns.get('roleScopingEntity')
&& ownerObj?.id === urns.get('ownerEntity') && ownerObj.value === ruleRoleScopingEntity && ownerObj.value === roleAttributeObject?.value)) {
ownerObj?.attributes?.forEach((obj) => ownerInstance = obj.value);
ownerObj?.attributes?.forEach((obj) => ownerInstances.push(obj.value));
return true;
}
});
});
// validate the ownerInstance from HR scope tree for matched scoping entity
if (entityMatch && ownerInstance) {
if (entityMatch && ownerInstances?.length > 0) {
traverse(reducedHRScopes).forEach((node: any) => { // depth-first search
if (node?.id === ownerInstance) {
if (ownerInstances.includes(node?.id)) {
deleteMapEntries.push(resourceId);
}
});
Expand Down
14 changes: 13 additions & 1 deletion test/microservice_acs_enabled.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ describe('testing microservice', () => {
});

// Create with two different scopes assigned for same role
it('should PERMIT to create test rule with ACS enabled without providing scope in subject with multilple instances assigned to same role', async () => {
it('should PERMIT to create test rule with ACS enabled with multiple owners without providing scope in subject with multilple instances assigned to same role', async () => {
let testRule1 = [{
name: '1 test rule for test entitiy',
description: '1 test rule',
Expand All @@ -978,6 +978,12 @@ describe('testing microservice', () => {
attributes: [{
id: 'urn:restorecommerce:acs:names:ownerInstance',
value: 'org1'
}, {
id: 'urn:restorecommerce:acs:names:ownerInstance',
value: 'org2'
}, {
id: 'urn:restorecommerce:acs:names:ownerInstance',
value: 'org3'
}]
}]
}
Expand Down Expand Up @@ -1030,8 +1036,14 @@ describe('testing microservice', () => {
id: 'urn:restorecommerce:acs:names:ownerIndicatoryEntity',
value: 'urn:restorecommerce:acs:model:organization.Organization',
attributes: [{
id: 'urn:restorecommerce:acs:names:ownerInstance',
value: 'org1'
}, {
id: 'urn:restorecommerce:acs:names:ownerInstance',
value: 'org2'
}, {
id: 'urn:restorecommerce:acs:names:ownerInstance',
value: 'org3'
}]
}]
}
Expand Down

0 comments on commit e6c5f55

Please sign in to comment.