fix(cbx): "Archive too large" error for invalid/corrupt CBX files (#2205)
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
+18
@@ -1,6 +1,8 @@
|
||||
package com.adityachandel.booklore.service.reader;
|
||||
|
||||
import com.adityachandel.booklore.exception.APIException;
|
||||
import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryPathEntity;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
@@ -167,6 +169,22 @@ class CbxReaderServiceTest {
|
||||
"Page count should be exactly 130 (actual comic pages only)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAvailablePages_whenArchiveIsCorrupt_shouldThrowFileReadError() throws IOException {
|
||||
Path corruptCbz = tempDir.resolve("corrupt.cbz");
|
||||
Files.writeString(corruptCbz, "This is not a zip file");
|
||||
|
||||
testBook.setFileName(corruptCbz.getFileName().toString());
|
||||
testBook.getLibraryPath().setPath(tempDir.toString());
|
||||
|
||||
APIException exception = assertThrows(APIException.class, () -> service.getAvailablePages(bookId));
|
||||
|
||||
assertNotEquals(ApiError.CACHE_TOO_LARGE.getMessage(), exception.getMessage(),
|
||||
"Should not throw CACHE_TOO_LARGE for a corrupt file");
|
||||
assertTrue(exception.getMessage().startsWith("Error reading files from path"),
|
||||
"Should throw FILE_READ_ERROR (message starts with 'Error reading files from path'), actual: '" + exception.getMessage() + "'");
|
||||
}
|
||||
|
||||
private void createTestCbzWithMacOsFiles(File cbzFile) throws IOException {
|
||||
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(cbzFile))) {
|
||||
for (int i = 1; i <= 130; i++) {
|
||||
|
||||
Reference in New Issue
Block a user