mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-18 02:45:07 +00:00
Test fix
This commit is contained in:
parent
c8ce07c40e
commit
0bee7a7b53
@ -102,7 +102,7 @@ public class AuthorizationInterceptorResourceProviderR4Test extends BaseResource
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateConditional() {
|
public void testUpdateConditional() {
|
||||||
|
|
||||||
Patient patient = new Patient();
|
Patient patient = new Patient();
|
||||||
patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100");
|
patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100");
|
||||||
@ -150,6 +150,68 @@ public class AuthorizationInterceptorResourceProviderR4Test extends BaseResource
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateConditionalViaTransaction() {
|
||||||
|
ourRestServer.getInterceptorService().registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) {
|
||||||
|
@Override
|
||||||
|
public List<IAuthRule> buildRuleList(RequestDetails theRequestDetails) {
|
||||||
|
return new RuleBuilder()
|
||||||
|
.allow().createConditional().resourcesOfType("Patient").andThen()
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a patient (allowed)
|
||||||
|
{
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100");
|
||||||
|
patient.addName().setFamily("Tester").addGiven("Raghad");
|
||||||
|
|
||||||
|
Bundle request = new Bundle();
|
||||||
|
request.setType(Bundle.BundleType.TRANSACTION);
|
||||||
|
request.addEntry()
|
||||||
|
.setResource(patient)
|
||||||
|
.getRequest()
|
||||||
|
.setMethod(Bundle.HTTPVerb.POST)
|
||||||
|
.setIfNoneExist("Patient?identifier=http://uhn.ca/mrns|100");
|
||||||
|
Bundle response = ourClient.transaction().withBundle(request).execute();
|
||||||
|
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(response));
|
||||||
|
|
||||||
|
try {
|
||||||
|
ourClient.update().resource(patient).execute();
|
||||||
|
fail();
|
||||||
|
} catch (ForbiddenOperationException e) {
|
||||||
|
assertEquals("HTTP 403 Forbidden: Access denied by default policy (no applicable rules)", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a patient (blocked)
|
||||||
|
{
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100");
|
||||||
|
patient.addName().setFamily("Tester").addGiven("Raghad");
|
||||||
|
|
||||||
|
Bundle request = new Bundle();
|
||||||
|
request.setType(Bundle.BundleType.TRANSACTION);
|
||||||
|
request.addEntry()
|
||||||
|
.setResource(patient)
|
||||||
|
.getRequest()
|
||||||
|
.setMethod(Bundle.HTTPVerb.POST)
|
||||||
|
.setIfNoneExist("Patient?identifier=http://uhn.ca/mrns|100");
|
||||||
|
Bundle response = ourClient.transaction().withBundle(request).execute();
|
||||||
|
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(response));
|
||||||
|
|
||||||
|
try {
|
||||||
|
ourClient.update().resource(patient).execute();
|
||||||
|
fail();
|
||||||
|
} catch (ForbiddenOperationException e) {
|
||||||
|
assertEquals("HTTP 403 Forbidden: Access denied by default policy (no applicable rules)", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadInTransaction() {
|
public void testReadInTransaction() {
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public class Dstu2_1BundleFactory implements IVersionSpecificBundleFactory {
|
|||||||
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
|
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
|
||||||
|
|
||||||
for (ResourceReferenceInfo nextRefInfo : references) {
|
for (ResourceReferenceInfo nextRefInfo : references) {
|
||||||
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) {
|
if (theBundleInclusionRule != null && !theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ public class Dstu3BundleFactory implements IVersionSpecificBundleFactory {
|
|||||||
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
|
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
|
||||||
|
|
||||||
for (ResourceReferenceInfo nextRefInfo : references) {
|
for (ResourceReferenceInfo nextRefInfo : references) {
|
||||||
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) {
|
if (theBundleInclusionRule != null && !theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ public class R4BundleFactory implements IVersionSpecificBundleFactory {
|
|||||||
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
|
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
|
||||||
|
|
||||||
for (ResourceReferenceInfo nextRefInfo : references) {
|
for (ResourceReferenceInfo nextRefInfo : references) {
|
||||||
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) {
|
if (theBundleInclusionRule != null && !theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ public class R5BundleFactory implements IVersionSpecificBundleFactory {
|
|||||||
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
|
List<IAnyResource> addedResourcesThisPass = new ArrayList<IAnyResource>();
|
||||||
|
|
||||||
for (ResourceReferenceInfo nextRefInfo : references) {
|
for (ResourceReferenceInfo nextRefInfo : references) {
|
||||||
if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) {
|
if (theBundleInclusionRule != null && !theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user