/// <summary> /// Assert that two <see cref="ResourcePolicyResponse"/> have the same property in the same positions. /// </summary> /// <param name="expected">An instance with the expected values.</param> /// <param name="actual">The instance to verify.</param> public static void AssertResourcePolicyResponseEqual(ResourcePolicyResponse expected, ResourcePolicyResponse actual) { if (actual.ResourcePolicies != null || expected.ResourcePolicies != null) { AssertCollections(expected.ResourcePolicies, actual.ResourcePolicies, AssertResourcePolicyEqual); } AssertCollections(expected.AppId, actual.AppId, AssertAttributeMatchEqual); Assert.Equal(expected.MinimumAuthenticationLevel, actual.MinimumAuthenticationLevel); if (expected.ErrorResponse != null && actual.ErrorResponse != null) { Assert.Equal(expected.ErrorResponse, actual.ErrorResponse); } }
public async Task <ActionResult> GetResourcePolicies([FromBody] List <List <AttributeMatch> > appIdList, [FromQuery] string language) { List <ResourcePolicyResponse> resourcePolicyResponses = new List <ResourcePolicyResponse>(); foreach (var attributeMatches in appIdList) { ResourcePolicyResponse response = new ResourcePolicyResponse { AppId = attributeMatches }; resourcePolicyResponses.Add(response); string org = attributeMatches.FirstOrDefault(match => match.Id == XacmlRequestAttribute.OrgAttribute)?.Value; string app = attributeMatches.FirstOrDefault(match => match.Id == XacmlRequestAttribute.AppAttribute)?.Value; if (string.IsNullOrWhiteSpace(org)) { response.ErrorResponse = "Organisation must be defined in the path"; continue; } if (string.IsNullOrWhiteSpace(app)) { response.ErrorResponse = "App must be defined in the path"; continue; } XacmlPolicy policy = await _prp.GetPolicyAsync(org, app); if (policy == null) { response.ErrorResponse = $"No valid policy found for org '{org}' and app '{app}'"; continue; } response.MinimumAuthenticationLevel = PolicyHelper.GetMinimumAuthenticationLevelFromXacmlPolicy(policy); response.ResourcePolicies = new List <ResourcePolicy>(); List <ResourcePolicy> list = PolicyHelper.GetResourcePoliciesFromXacmlPolicy(policy, language); foreach (ResourcePolicy resourcePolicy in list) { if (resourcePolicy.Resource.First(a => a.Id == XacmlRequestAttribute.OrgAttribute).Value == org && resourcePolicy.Resource.First(a => a.Id == XacmlRequestAttribute.AppAttribute).Value == app) { response.ResourcePolicies.Add(resourcePolicy); } } } return(Ok(resourcePolicyResponses)); }