From a5fb87bb1d22fa28f3c6fa4d44f9ca2ee8d6e7f4 Mon Sep 17 00:00:00 2001 From: Etienne Poirier <33007955+epeartree@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:09:17 -0400 Subject: [PATCH] 4142 resource contents are written to logs on subscription failure (#4143) * Add test reproducing the issue. * Adding solution and changelog. * Modification following code review. Co-authored-by: peartree --- ...itten-to-logs-on-subscription-failure.yaml | 5 ++++ .../BaseSubscriptionDeliverySubscriber.java | 2 +- ...aseSubscriptionDeliverySubscriberTest.java | 28 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4142-resource-contents-written-to-logs-on-subscription-failure.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4142-resource-contents-written-to-logs-on-subscription-failure.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4142-resource-contents-written-to-logs-on-subscription-failure.yaml new file mode 100644 index 00000000000..103a9f61634 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4142-resource-contents-written-to-logs-on-subscription-failure.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 4142 +jira: SMILE-5312 +title: "Upon hitting a subscription delivery failure, we currently log the failing payload which could be considered PHI. Resource content is no longer written to logs on subscription failure." diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriber.java index f7816559690..2c03c3903e9 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriber.java @@ -94,7 +94,7 @@ public abstract class BaseSubscriptionDeliverySubscriber implements MessageHandl return; } - throw new MessagingException(theMessage, Msg.code(2) + errorMsg, e); + throw new MessagingException(Msg.code(2) + errorMsg, e); } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java index dc1a6774088..158e1a6df4c 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java @@ -41,6 +41,7 @@ import javax.annotation.Nonnull; import java.net.URISyntaxException; import java.time.LocalDate; import java.util.Collection; +import java.util.Date; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; @@ -48,6 +49,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasSize; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; @@ -316,6 +318,32 @@ public class BaseSubscriptionDeliverySubscriberTest { assertEquals(jsonMessage.getPayload().getRequestPartitionId().toJson(), RequestPartitionId.defaultPartition().toJson()); } + @Test + public void testRestHookDeliveryFails_raisedExceptionShouldNotIncludeSubmittedResource() { + when(myInterceptorBroadcaster.callHooks(any(), any())).thenReturn(true); + + String familyName = "FAMILY"; + + Patient patient = generatePatient(); + patient.addName().setFamily(familyName); + CanonicalSubscription subscription = generateSubscription(); + + ResourceDeliveryMessage payload = new ResourceDeliveryMessage(); + payload.setSubscription(subscription); + payload.setPayload(myCtx, patient, EncodingEnum.JSON); + payload.setOperationType(ResourceModifiedMessage.OperationTypeEnum.CREATE); + + when(myGenericClient.update()).thenThrow(new InternalErrorException("FOO")); + + try { + mySubscriber.handleMessage(new ResourceDeliveryJsonMessage(payload)); + fail(); + } catch (MessagingException e) { + String messageExceptionAsString = e.toString(); + assertFalse(messageExceptionAsString.contains(familyName)); + } + } + @Nonnull private Patient generatePatient() { Patient patient = new Patient();