Skip to content

Commit

Permalink
Flips default behavior, strict by default and client can opt out (#4720)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankowitz authored Nov 13, 2024
1 parent e891cea commit 7ea7204
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ internal static bool GetIsStrictHandlingEnabled(this RequestContextAccessor<IFhi
{
EnsureArg.IsNotNull(contextAccessor, nameof(contextAccessor));

bool isStrictHandlingEnabled = false;
return GetHandlingHeader(contextAccessor) == SearchParameterHandling.Strict;
}

internal static SearchParameterHandling? GetHandlingHeader(this RequestContextAccessor<IFhirRequestContext> contextAccessor)
{
EnsureArg.IsNotNull(contextAccessor, nameof(contextAccessor));

if (contextAccessor.RequestContext?.RequestHeaders != null &&
contextAccessor.RequestContext.RequestHeaders.TryGetValue(KnownHeaders.Prefer, out StringValues values))
Expand All @@ -40,14 +45,11 @@ internal static bool GetIsStrictHandlingEnabled(this RequestContextAccessor<IFhi
string.Join(",", Enum.GetNames<SearchParameterHandling>())));
}

if (handling == SearchParameterHandling.Strict)
{
isStrictHandlingEnabled = true;
}
return handling;
}
}

return isStrictHandlingEnabled;
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ private ExportJobFormatConfiguration ParseFormat(string formatName, bool useCont

private void ValidateTypeFilters(IList<ExportJobFilter> filters)
{
if (!_contextAccessor.GetIsStrictHandlingEnabled())
if (_contextAccessor.GetHandlingHeader() == SearchParameterHandling.Lenient)
{
_logger.LogInformation("Validation skipped due to strict handling disabled.");
_logger.LogInformation("Validation skipped due to opting for Lenient error handling.");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public static IEnumerable<object[]> ValidateTypeFilters
}
},
},
string.Empty,
SearchParameterHandling.Lenient.ToString(),
},
new object[]
{
Expand Down Expand Up @@ -458,7 +458,7 @@ public async Task GivenARequestWithIncorectFilters_WhenConverted_ThenABadRequest

[Theory]
[MemberData(nameof(ValidateTypeFilters))]
public async Task GivenARequestWithFilters_WhenInvalidParameterFoundWithStrictHandlingEnabled_ThenABadRequestIsReturned(
public async Task GivenARequestWithFilters_WhenInvalidParameterFound_ThenABadRequestIsReturned(
IDictionary<string, IList<KeyValuePair<string, string>>> filters,
IDictionary<string, ISet<string>> invalidParameters,
#pragma warning disable xUnit1026 // Theory methods should use all of their parameters
Expand All @@ -473,14 +473,6 @@ await _fhirOperationDataStore.CreateExportJobAsync(
}),
Arg.Any<CancellationToken>());

var fhirRequestContext = Substitute.For<IFhirRequestContext>();
fhirRequestContext.RequestHeaders.Returns(
new Dictionary<string, StringValues>
{
{ KnownHeaders.Prefer, new StringValues($"handling={SearchParameterHandling.Strict}") },
});
_requestContextAccessor.RequestContext.Returns(fhirRequestContext);

var filterString = new StringBuilder();
foreach (var kv in filters)
{
Expand Down Expand Up @@ -543,7 +535,7 @@ await _fhirOperationDataStore.CreateExportJobAsync(

[Theory]
[MemberData(nameof(ValidateTypeFilters))]
public async Task GivenARequestWithFilters_WhenInvalidParameterFoundWithStrictHandlingDisabled_ThenValidateTypeFiltersShouldBeSkipped(
public async Task GivenARequestWithFilters_WhenInvalidParameterFoundWithLenientHandlingSpecified_ThenValidateTypeFiltersShouldBeSkipped(
IDictionary<string, IList<KeyValuePair<string, string>>> filters,
IDictionary<string, ISet<string>> invalidParameters,
string searchParameterHandling)
Expand Down

0 comments on commit 7ea7204

Please sign in to comment.