You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/03/04 14:34:48 UTC

(commons-compress) 02/03: [COMPRESS-644] Add disabled tests for TAR files

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 746382eaf96f2076ae67eeae5116a65d7923bb8a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Mar 4 08:33:40 2024 -0500

    [COMPRESS-644] Add disabled tests for TAR files
---
 .../commons/compress/DetectArchiverTest.java       | 44 ++++++++++++++++++----
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/src/test/java/org/apache/commons/compress/DetectArchiverTest.java b/src/test/java/org/apache/commons/compress/DetectArchiverTest.java
index 2a9f0d408..04103bb51 100644
--- a/src/test/java/org/apache/commons/compress/DetectArchiverTest.java
+++ b/src/test/java/org/apache/commons/compress/DetectArchiverTest.java
@@ -18,44 +18,62 @@
  */
 package org.apache.commons.compress;
 
+import static org.junit.Assert.assertNull;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.BufferedInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveException;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.compress.archivers.ar.ArArchiveInputStream;
 import org.apache.commons.compress.archivers.arj.ArjArchiveInputStream;
 import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 public final class DetectArchiverTest extends AbstractTest {
 
     final ClassLoader classLoader = getClass().getClassLoader();
 
+    private void checkDetectedType(final String type, final Path path) throws ArchiveException, IOException {
+        try (BufferedInputStream inputStream = new BufferedInputStream(Files.newInputStream(path))) {
+            // SPECIAL case:
+            // For now JAR files are detected as ZIP files.
+            assertEquals(ArchiveStreamFactory.JAR.equals(type) ? ArchiveStreamFactory.ZIP : type, ArchiveStreamFactory.detect(inputStream));
+        }
+    }
+
     private void checkEmptyArchive(final String type) throws Exception {
-        final Path ar = createEmptyArchive(type); // will be deleted by tearDown()
+        final Path path = createEmptyArchive(type); // will be deleted by tearDown()
         assertDoesNotThrow(() -> {
-            try (BufferedInputStream inputStream = new BufferedInputStream(Files.newInputStream(ar));
+            try (BufferedInputStream inputStream = new BufferedInputStream(Files.newInputStream(path));
                     ArchiveInputStream<?> ais = factory.createArchiveInputStream(inputStream)) {
                 // empty
             }
         }, "Should have recognized empty archive for " + type);
+        checkDetectedType(type, path);
     }
 
     @SuppressWarnings("resource") // Caller closes
     private <T extends ArchiveInputStream<? extends E>, E extends ArchiveEntry> T createArchiveInputStream(final String resource)
             throws ArchiveException, IOException {
-        return factory.createArchiveInputStream(new BufferedInputStream(newInputStream(resource)));
+        return factory.createArchiveInputStream(createBufferedInputStream(resource));
+    }
+
+    private BufferedInputStream createBufferedInputStream(final String resource) throws IOException {
+        return new BufferedInputStream(newInputStream(resource));
     }
 
     @Test
@@ -136,12 +154,24 @@ public final class DetectArchiverTest extends AbstractTest {
         checkEmptyArchive("jar");
     }
 
-    // empty tar archives just have 512 null bytes
-//    public void testEmptyTarArchive() throws Exception {
-//        checkEmptyArchive("tar");
-//    }
+    @Disabled
+    @Test
+    public void testEmptyTarArchive() throws Exception {
+        checkEmptyArchive("tar");
+    }
+
     @Test
     public void testEmptyZipArchive() throws Exception {
         checkEmptyArchive("zip");
     }
+
+    @Disabled
+    @Test
+    public void testIgnoreZeroByteEntryInTarDetect_COMPRESS644() {
+        assertThrows(ArchiveException.class, () -> {
+            try (InputStream in = createBufferedInputStream("org/apache/commons/compress/COMPRESS-644/ARW05UP.ICO")) {
+                assertNull(ArchiveStreamFactory.detect(in));
+            }
+        });
+    }
 }