From e6308b9e4c4155aa6d537b330de31e42736e7f4c Mon Sep 17 00:00:00 2001
From: Martin Vogel <martin.vogel@sinc.de>
Date: Wed, 18 Jan 2023 14:38:24 +0100
Subject: [PATCH] fix: add missed test that was removed on the laste merge

---
 .../fitconnect/client/SubscriberClient.java   |  5 ++-
 .../client/SubscriberClientTest.java          | 43 +++++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/client/src/main/java/dev/fitko/fitconnect/client/SubscriberClient.java b/client/src/main/java/dev/fitko/fitconnect/client/SubscriberClient.java
index 837b1686f..313362935 100644
--- a/client/src/main/java/dev/fitko/fitconnect/client/SubscriberClient.java
+++ b/client/src/main/java/dev/fitko/fitconnect/client/SubscriberClient.java
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 
+import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
 import static dev.fitko.fitconnect.client.util.SubmissionUtil.buildDecryptedAttachmentPayload;
 import static dev.fitko.fitconnect.client.util.SubmissionUtil.getDataHashFromMetadata;
 import static dev.fitko.fitconnect.client.util.SubmissionUtil.mapToReceivedAttachments;
@@ -42,8 +43,8 @@ import static dev.fitko.fitconnect.client.util.SubmissionUtil.mapToReceivedAttac
 public class SubscriberClient {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(SubscriberClient.class);
+    private static final ObjectMapper MAPPER = new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
     private static final int DEFAULT_SUBMISSION_LIMIT = 500;
-
     private final Subscriber subscriber;
     private final RSAKey privateKey;
 
@@ -184,7 +185,7 @@ public class SubscriberClient {
 
     private Metadata decryptMetadata(final String encryptedMetadata) throws IOException {
         final byte[] metadataBytes = subscriber.decryptStringContent(privateKey, encryptedMetadata);
-        return new ObjectMapper().readValue(metadataBytes, Metadata.class);
+        return MAPPER.readValue(metadataBytes, Metadata.class);
     }
 
     private ValidationResult validateAttachments(final List<DecryptedAttachmentPayload> decryptedAttachmentPayloads) {
diff --git a/client/src/test/java/dev/fitko/fitconnect/client/SubscriberClientTest.java b/client/src/test/java/dev/fitko/fitconnect/client/SubscriberClientTest.java
index a7c42664c..ef92c9b38 100644
--- a/client/src/test/java/dev/fitko/fitconnect/client/SubscriberClientTest.java
+++ b/client/src/test/java/dev/fitko/fitconnect/client/SubscriberClientTest.java
@@ -314,6 +314,49 @@ class SubscriberClientTest {
         logs.assertContains("Metadata does not match schema");
     }
 
+    @Test
+    void testUnknownPropertyOnMetadata() throws JsonProcessingException {
+        // Given
+        final var submissionId = UUID.randomUUID();
+        final var destinationId = UUID.randomUUID();
+        final var caseId = UUID.randomUUID();
+
+        final var submission = new Submission();
+        submission.setSubmissionId(submissionId);
+        submission.setDestinationId(destinationId);
+        submission.setCaseId(caseId);
+
+        final Map<String, Map<?, ?>> metadata = Map.of(
+                "$schemaFoo", Collections.emptyMap(),
+                "contentStructure", Map.of(
+                        "data", Map.of(
+                                "hash", Map.of(
+                                        "type", SignatureType.SHA_512,
+                                        "content", "bla"
+                                ),
+                                "submissionSchema", Map.of(
+                                        "schemaUri", URI.create("https://dummy.schema.url"),
+                                        "mimeType", MimeType.APPLICATION_JSON
+                                )
+                        )
+                )
+        );
+
+        final var invalidMetadata = mapper.writeValueAsBytes(metadata);
+
+        when(subscriberMock.getSubmission(any())).thenReturn(submission);
+        when(subscriberMock.decryptStringContent(any(), any())).thenReturn(invalidMetadata);
+        when(subscriberMock.validateMetadata(any())).thenReturn(ValidationResult.ok());
+        when(subscriberMock.validateHashIntegrity(any(), any())).thenReturn(ValidationResult.ok());
+
+        // When
+        final var receivedSubmission = underTest.requestSubmission(submissionId);
+
+        // Then
+        assertNotNull(receivedSubmission);
+        assertThat(receivedSubmission.getSubmissionMetadata().getContentStructure().getData().getHash().getContent(), is("bla"));
+    }
+
     @Test
     void testCorruptedData() throws JsonProcessingException {
 
-- 
GitLab