ZipFiles { public static void unzip(String zipPath, String destination) { File dest = new File(destination); if(!dest.exists()) { dest.mkdirs(); } Verify.thatArgument(dest.isDirectory(), "Unzip destination must be a directory"); try { ZipUtil.unpack(new File(zipPath), dest); } catch (org.zeroturnaround.zip.ZipException e) { IllegalArgumentException ex = new IllegalArgumentException( e.getMessage()); ex.setStackTrace(e.getStackTrace()); throw ex; } }  static ByteBuffer getEntryContent(String zipFile,
            String relativeEntryPath); static String getEntryContentUtf8(String zipFile,
            String relativeEntryPath); static void unzip(String zipPath, String destination);  }
@Test(expected = IllegalArgumentException.class) public void testCannotExtractZipContainingEntryWithPathTraversalCharacters() throws IOException { String zip = Resources.getAbsolutePath("/evil.zip"); String parent = FileOps.tempDir("zip"); String dest = Paths.get(parent).resolve("target").toAbsolutePath() .toString(); ZipFiles.unzip(zip, dest); Assert.assertEquals(1, Files.list(Paths.get(dest)).count()); Assert.assertEquals(1, Files.list(Paths.get(parent)).count()); }
@Test(expected = IllegalArgumentException.class) public void testCannotExtractZipFileToNonDestination() { String zip = Resources.getAbsolutePath("/good.zip"); String dest = FileOps.tempFile(); ZipFiles.unzip(zip, dest); }
@Test public void testUnzip() throws IOException { String zip = Resources.getAbsolutePath("/good.zip"); String parent = FileOps.tempDir("zip"); String dest = Paths.get(parent).resolve("target").toAbsolutePath() .toString(); ZipFiles.unzip(zip, dest); Assert.assertEquals(1, Files.list(Paths.get(dest)).count()); Assert.assertEquals(1, Files.list(Paths.get(parent)).count()); }