From 9b246852efe6916990e9cf2cd9f5213a3b836263 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Wed, 22 Nov 2017 19:45:36 -0500 Subject: [PATCH] Add test for #762 --- ...tionInterceptorResourceProviderR4Test.java | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorResourceProviderR4Test.java index 7c43f896e51..ab1a109eca2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorResourceProviderR4Test.java @@ -18,11 +18,8 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.hl7.fhir.instance.model.api.IIdType; -import org.hl7.fhir.r4.model.IdType; -import org.hl7.fhir.r4.model.Observation; +import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.Observation.ObservationStatus; -import org.hl7.fhir.r4.model.Patient; -import org.hl7.fhir.r4.model.Reference; import org.junit.AfterClass; import org.junit.Test; @@ -340,6 +337,45 @@ public class AuthorizationInterceptorResourceProviderR4Test extends BaseResource } + /** + * See #762 + */ + @Test + public void testInstanceRuleOkForResourceWithNoId() { + + ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { + @Override + public List buildRuleList(RequestDetails theRequestDetails) { + return new RuleBuilder() + .deny().write().instance("Patient/123").andThen() + .allowAll() + .build(); + } + }); + + /* + * Create a transaction using linked IDs + */ + + Bundle request = new Bundle(); + request.setType(Bundle.BundleType.TRANSACTION); + + Patient p = new Patient(); + p.setActive(true); + p.setId(IdType.newRandomUuid()); + request.addEntry().setResource(p).getRequest().setMethod(Bundle.HTTPVerb.POST).setUrl(p.getId()); + + Observation o = new Observation(); + o.getCode().setText("Some Observation"); + o.getSubject().setResource(p); + request.addEntry().setResource(o).getRequest().setMethod(Bundle.HTTPVerb.POST); + + Bundle resp = myClient.transaction().withBundle(request).execute(); + assertEquals(2, resp.getEntry().size()); + + + } + private void unregisterInterceptors() { for (IServerInterceptor next : new ArrayList(ourRestServer.getInterceptors())) {