Skip to content

Commit

Permalink
Block jp2 processing for x-raw-panasonic. Add unit test (#1829)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbpennel authored Nov 7, 2024
1 parent cc6f856 commit fcc6ef5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit fcc6ef5

Please sign in to comment.