From fcc6ef5e005e909019522d2dc393d52b1545ed37 Mon Sep 17 00:00:00 2001 From: Ben Pennell Date: Thu, 7 Nov 2024 12:46:55 -0500 Subject: [PATCH] Block jp2 processing for x-raw-panasonic. Add unit test (#1829) --- .../images/ImageDerivativeProcessor.java | 2 +- .../images/ImageDerivativeProcessorTest.java | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/images/ImageDerivativeProcessorTest.java diff --git a/services-camel-app/src/main/java/edu/unc/lib/boxc/services/camel/images/ImageDerivativeProcessor.java b/services-camel-app/src/main/java/edu/unc/lib/boxc/services/camel/images/ImageDerivativeProcessor.java index 2b5d916b04..418f91a248 100644 --- a/services-camel-app/src/main/java/edu/unc/lib/boxc/services/camel/images/ImageDerivativeProcessor.java +++ b/services-camel-app/src/main/java/edu/unc/lib/boxc/services/camel/images/ImageDerivativeProcessor.java @@ -19,7 +19,7 @@ public class ImageDerivativeProcessor implements Processor { private static final Pattern MIMETYPE_PATTERN = Pattern.compile("^(image.*$|application.*?(photoshop|psd)$)"); - private static final Pattern DISALLOWED_PATTERN = Pattern.compile(".*(vnd\\.fpx|x-icon).*"); + private static final Pattern DISALLOWED_PATTERN = Pattern.compile(".*(vnd\\.fpx|x-icon|x-raw-panasonic).*"); /** * Returns true if the subject of the exchange is a binary which diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/images/ImageDerivativeProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/images/ImageDerivativeProcessorTest.java new file mode 100644 index 0000000000..5da7eba5dd --- /dev/null +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/images/ImageDerivativeProcessorTest.java @@ -0,0 +1,76 @@ +package edu.unc.lib.boxc.services.camel.images; + +import edu.unc.lib.boxc.services.camel.util.CdrFcrepoHeaders; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; + +/** + * @author bbpennel + */ +public class ImageDerivativeProcessorTest { + @Mock + private Exchange exchange; + @Mock + private Message messageIn; + private AutoCloseable closeable; + private ImageDerivativeProcessor processor; + + @BeforeEach + public void init() { + closeable = openMocks(this); + + when(exchange.getIn()).thenReturn(messageIn); + when(messageIn.getHeader(CdrFcrepoHeaders.CdrBinaryPath)).thenReturn("path/to/binary"); + + processor = new ImageDerivativeProcessor(); + } + + @AfterEach + public void close() throws Exception { + closeable.close(); + } + + @Test + public void testAllowedImageTypePanasonicRaw() { + when(messageIn.getHeader(CdrFcrepoHeaders.CdrBinaryMimeType)).thenReturn("image/x-raw-panasonic"); + + assertFalse(ImageDerivativeProcessor.allowedImageType(exchange)); + } + + @Test + public void testAllowedImageTypePanasonicRw2() { + when(messageIn.getHeader(CdrFcrepoHeaders.CdrBinaryMimeType)).thenReturn("image/x-panasonic-rw2"); + + assertTrue(ImageDerivativeProcessor.allowedImageType(exchange)); + } + + @Test + public void testAllowedImageTypeIcon() { + when(messageIn.getHeader(CdrFcrepoHeaders.CdrBinaryMimeType)).thenReturn("image/x-icon"); + + assertFalse(ImageDerivativeProcessor.allowedImageType(exchange)); + } + + @Test + public void testAllowedImageTypeJpeg() { + when(messageIn.getHeader(CdrFcrepoHeaders.CdrBinaryMimeType)).thenReturn("image/jpeg"); + + assertTrue(ImageDerivativeProcessor.allowedImageType(exchange)); + } + + @Test + public void testAllowedImageTypePhotoshop() { + when(messageIn.getHeader(CdrFcrepoHeaders.CdrBinaryMimeType)).thenReturn("application/photoshop"); + + assertTrue(ImageDerivativeProcessor.allowedImageType(exchange)); + } +}