Fix to interceptor (#4578)

* Fix to interceptor

* Changes from code review

* Extracting method

---------

Co-authored-by: Simon Zuccherato <szuccher@Simons-MacBook-Pro.local>
This commit is contained in:
Simon Zuccherato 2023-03-21 10:26:36 -04:00 committed by GitHub
parent 14be0553d0
commit ece6661120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 4 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 4601
title: "The InteractionBlockingInterceptor did not have support for the interactions
'search' and 'history' despite them being declared in the code system. This has been fixed."

View File

@ -202,12 +202,24 @@ public class InteractionBlockingInterceptor {
String resourceName = theSpec.substring(0, colonIdx);
String interactionName = theSpec.substring(colonIdx + 1);
RestOperationTypeEnum interaction = RestOperationTypeEnum.forCode(interactionName);
Validate.notNull(interaction, "Unknown interaction %s in spec %s", interactionName, theSpec);
addAllowedInteraction(resourceName, interaction);
if (interactionName.equals("search")) {
interactionName = "search-type";
validateInteraction(interactionName, theSpec, resourceName);
} else if (interactionName.equals("history")) {
validateInteraction("history-instance", theSpec, resourceName);
validateInteraction("history-type", theSpec, resourceName);
} else {
validateInteraction(interactionName, theSpec, resourceName);
}
return this;
}
private void validateInteraction(String theInteractionName, String theSpec, String theResourceName) {
RestOperationTypeEnum interaction = RestOperationTypeEnum.forCode(theInteractionName);
Validate.notNull(interaction, "Unknown interaction %s in spec %s", theInteractionName, theSpec);
addAllowedInteraction(theResourceName, interaction);
}
/**
* Adds an interaction that will be permitted.
*/

View File

@ -10,6 +10,7 @@ import ca.uhn.fhir.test.utilities.ITestDataBuilder;
import ca.uhn.fhir.test.utilities.server.RestfulServerExtension;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CapabilityStatement;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Observation;
@ -48,6 +49,8 @@ public class InteractionBlockingInterceptorTest implements ITestDataBuilder {
// Setup
mySvc = new InteractionBlockingInterceptor.Builder(ourCtx)
.addAllowedSpec("Patient:read")
.addAllowedSpec("Patient:search")
.addAllowedSpec("Patient:history")
.addAllowedSpec("Observation:read")
.addAllowedSpec("Observation:create")
.build();
@ -63,11 +66,16 @@ public class InteractionBlockingInterceptorTest implements ITestDataBuilder {
"Observation:vread",
"OperationDefinition:read",
"Patient:read",
"Patient:vread"
"Patient:vread",
"Patient:search-type",
"Patient:history-instance",
"Patient:history-type"
));
// Verify Server
verifyCreateObservationOk();
verifySearchObservationOk();
verifyHistoryObservationOk();
verifyReadObservationOk();
verifyReadEncounterFails();
}
@ -111,6 +119,15 @@ public class InteractionBlockingInterceptorTest implements ITestDataBuilder {
myServer.getFhirClient().read().resource("Observation").withId("O0").execute();
}
private void verifySearchObservationOk() {
myServer.getFhirClient().search().forResource("Patient").execute();
}
private void verifyHistoryObservationOk() {
myServer.getFhirClient().history().onInstance("Patient/P0").returnBundle(Bundle.class).execute();
myServer.getFhirClient().history().onType("Patient").returnBundle(Bundle.class).execute();
}
private void verifyCreateObservationOk() {
myServer.getFhirClient().create().resource(new Observation()).execute();
}