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:
parent
14be0553d0
commit
ece6661120
|
@ -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."
|
|
@ -202,12 +202,24 @@ public class InteractionBlockingInterceptor {
|
||||||
|
|
||||||
String resourceName = theSpec.substring(0, colonIdx);
|
String resourceName = theSpec.substring(0, colonIdx);
|
||||||
String interactionName = theSpec.substring(colonIdx + 1);
|
String interactionName = theSpec.substring(colonIdx + 1);
|
||||||
RestOperationTypeEnum interaction = RestOperationTypeEnum.forCode(interactionName);
|
if (interactionName.equals("search")) {
|
||||||
Validate.notNull(interaction, "Unknown interaction %s in spec %s", interactionName, theSpec);
|
interactionName = "search-type";
|
||||||
addAllowedInteraction(resourceName, interaction);
|
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;
|
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.
|
* Adds an interaction that will be permitted.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,6 +10,7 @@ import ca.uhn.fhir.test.utilities.ITestDataBuilder;
|
||||||
import ca.uhn.fhir.test.utilities.server.RestfulServerExtension;
|
import ca.uhn.fhir.test.utilities.server.RestfulServerExtension;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
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.CapabilityStatement;
|
||||||
import org.hl7.fhir.r4.model.IdType;
|
import org.hl7.fhir.r4.model.IdType;
|
||||||
import org.hl7.fhir.r4.model.Observation;
|
import org.hl7.fhir.r4.model.Observation;
|
||||||
|
@ -48,6 +49,8 @@ public class InteractionBlockingInterceptorTest implements ITestDataBuilder {
|
||||||
// Setup
|
// Setup
|
||||||
mySvc = new InteractionBlockingInterceptor.Builder(ourCtx)
|
mySvc = new InteractionBlockingInterceptor.Builder(ourCtx)
|
||||||
.addAllowedSpec("Patient:read")
|
.addAllowedSpec("Patient:read")
|
||||||
|
.addAllowedSpec("Patient:search")
|
||||||
|
.addAllowedSpec("Patient:history")
|
||||||
.addAllowedSpec("Observation:read")
|
.addAllowedSpec("Observation:read")
|
||||||
.addAllowedSpec("Observation:create")
|
.addAllowedSpec("Observation:create")
|
||||||
.build();
|
.build();
|
||||||
|
@ -63,11 +66,16 @@ public class InteractionBlockingInterceptorTest implements ITestDataBuilder {
|
||||||
"Observation:vread",
|
"Observation:vread",
|
||||||
"OperationDefinition:read",
|
"OperationDefinition:read",
|
||||||
"Patient:read",
|
"Patient:read",
|
||||||
"Patient:vread"
|
"Patient:vread",
|
||||||
|
"Patient:search-type",
|
||||||
|
"Patient:history-instance",
|
||||||
|
"Patient:history-type"
|
||||||
));
|
));
|
||||||
|
|
||||||
// Verify Server
|
// Verify Server
|
||||||
verifyCreateObservationOk();
|
verifyCreateObservationOk();
|
||||||
|
verifySearchObservationOk();
|
||||||
|
verifyHistoryObservationOk();
|
||||||
verifyReadObservationOk();
|
verifyReadObservationOk();
|
||||||
verifyReadEncounterFails();
|
verifyReadEncounterFails();
|
||||||
}
|
}
|
||||||
|
@ -111,6 +119,15 @@ public class InteractionBlockingInterceptorTest implements ITestDataBuilder {
|
||||||
myServer.getFhirClient().read().resource("Observation").withId("O0").execute();
|
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() {
|
private void verifyCreateObservationOk() {
|
||||||
myServer.getFhirClient().create().resource(new Observation()).execute();
|
myServer.getFhirClient().create().resource(new Observation()).execute();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue