Fixed bugs preventing single file GIF repositories and QCHAT attachments from passing validation.

This commit is contained in:
CalDescent 2023-01-20 10:14:42 +00:00
parent 8ad46b6344
commit e31515b4a2
2 changed files with 44 additions and 0 deletions

View File

@ -24,6 +24,10 @@ public enum Service {
// Custom validation function to require a single file, with a whitelisted extension
int fileCount = 0;
File[] files = path.toFile().listFiles();
// If already a single file, replace the list with one that contains that file only
if (files == null && path.toFile().isFile()) {
files = new File[] { path.toFile() };
}
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
@ -80,6 +84,10 @@ public enum Service {
// Custom validation function to require .gif files only, and at least 1
int gifCount = 0;
File[] files = path.toFile().listFiles();
// If already a single file, replace the list with one that contains that file only
if (files == null && path.toFile().isFile()) {
files = new File[] { path.toFile() };
}
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {

View File

@ -120,6 +120,24 @@ public class ArbitraryServiceTests extends Common {
assertEquals(ValidationResult.OK, service.validate(path));
}
@Test
public void testValidateSingleFileGifRepository() throws IOException {
// Generate some random data
byte[] data = new byte[1024];
new Random().nextBytes(data);
// Write the data to a single file in a temp path
Path path = Files.createTempDirectory("testValidateSingleFileGifRepository");
path.toFile().deleteOnExit();
Path imagePath = Paths.get(path.toString(), "image1.gif");
Files.write(imagePath, data, StandardOpenOption.CREATE);
Service service = Service.GIF_REPOSITORY;
assertTrue(service.isValidationRequired());
assertEquals(ValidationResult.OK, service.validate(imagePath));
}
@Test
public void testValidateMultiLayerGifRepository() throws IOException {
// Generate some random data
@ -188,6 +206,24 @@ public class ArbitraryServiceTests extends Common {
assertEquals(ValidationResult.OK, service.validate(path));
}
@Test
public void testValidateSingleFileQChatAttachment() throws IOException {
// Generate some random data
byte[] data = new byte[1024];
new Random().nextBytes(data);
// Write the data a single file in a temp path
Path path = Files.createTempDirectory("testValidateSingleFileQChatAttachment");
path.toFile().deleteOnExit();
Path filePath = Paths.get(path.toString(), "document.pdf");
Files.write(filePath, data, StandardOpenOption.CREATE);
Service service = Service.QCHAT_ATTACHMENT;
assertTrue(service.isValidationRequired());
assertEquals(ValidationResult.OK, service.validate(filePath));
}
@Test
public void testValidateInvalidQChatAttachmentFileExtension() throws IOException {
// Generate some random data