Skip to content

Commit

Permalink
[ODS-6067] Handle misconfigured profiles (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
simpat-jesus authored Jan 17, 2024
1 parent 3d92970 commit 071d0b4
Show file tree
Hide file tree
Showing 3 changed files with 459 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class ProfileContentTypeContextMiddleware
"The profile usage segment in the profile-based '{0}' header was not recognized.";
private const string NonExistingProfileFormat =
"The profile specified by the content type in the '{0}' header is not supported by this host.";
private const string MisconfiguredProfileFormat =
"The profile specified by the content type in the '{0}' header is configured but invalid.";

private const int ResourceNameFacet = 0;
private const int ProfileNameFacet = 1;
Expand Down Expand Up @@ -153,9 +155,20 @@ await WriteResponse(
return (false, null);
}

// Validate that the Profile exists
// Validate that the Profile exists and is valid
string profileName = profileContentTypeFacets[ProfileNameFacet].Value;

if (_profileMetadataProvider.GetValidationResults().Any(x => x.Name.Equals(profileName, StringComparison.OrdinalIgnoreCase)))
{
await WriteResponse(
response,
StatusCodes.Status406NotAcceptable,
headerName,
MisconfiguredProfileFormat);

return (false, null);
}

if (!_profileMetadataProvider.ProfileDefinitionsByName.ContainsKey(profileName))
{
await WriteResponse(
Expand Down
20 changes: 20 additions & 0 deletions Application/EdFi.Ods.Profiles.Test/Profiles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -888,4 +888,24 @@
</WriteContentType>
</Resource>
</Profile>

<!-- Misconfigured Profiles-->
<Profile name="Test-Profile-With-Unexisting-Resource">
<Resource name="Schools">
<ReadContentType memberSelection="IncludeAll" />
<WriteContentType memberSelection="IncludeAll" />
</Resource>
</Profile>

<Profile name="Test-Profile-With-Unexisting-Property">
<Resource name="School">
<ReadContentType memberSelection="IncludeOnly">
<Property name="NameOfInstitutions" />
</ReadContentType>
<WriteContentType memberSelection="IncludeOnly">
<Property name="ShortNameOfInstitutions" />
</WriteContentType>
</Resource>
</Profile>

</Profiles>
Loading

0 comments on commit 071d0b4

Please sign in to comment.