forked from Qortal/qortal
Fixed bugs preventing single file GIF repositories and QCHAT attachments from passing validation.
This commit is contained in:
parent
8ad46b6344
commit
e31515b4a2
@ -24,6 +24,10 @@ public enum Service {
|
|||||||
// Custom validation function to require a single file, with a whitelisted extension
|
// Custom validation function to require a single file, with a whitelisted extension
|
||||||
int fileCount = 0;
|
int fileCount = 0;
|
||||||
File[] files = path.toFile().listFiles();
|
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) {
|
if (files != null) {
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
@ -80,6 +84,10 @@ public enum Service {
|
|||||||
// Custom validation function to require .gif files only, and at least 1
|
// Custom validation function to require .gif files only, and at least 1
|
||||||
int gifCount = 0;
|
int gifCount = 0;
|
||||||
File[] files = path.toFile().listFiles();
|
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) {
|
if (files != null) {
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
|
@ -120,6 +120,24 @@ public class ArbitraryServiceTests extends Common {
|
|||||||
assertEquals(ValidationResult.OK, service.validate(path));
|
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
|
@Test
|
||||||
public void testValidateMultiLayerGifRepository() throws IOException {
|
public void testValidateMultiLayerGifRepository() throws IOException {
|
||||||
// Generate some random data
|
// Generate some random data
|
||||||
@ -188,6 +206,24 @@ public class ArbitraryServiceTests extends Common {
|
|||||||
assertEquals(ValidationResult.OK, service.validate(path));
|
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
|
@Test
|
||||||
public void testValidateInvalidQChatAttachmentFileExtension() throws IOException {
|
public void testValidateInvalidQChatAttachmentFileExtension() throws IOException {
|
||||||
// Generate some random data
|
// Generate some random data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user