Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flips behavior, validate by default, opt out with Lenient #4720

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading