Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #864 from arminha/fix-tar-regression
Fix regression when extracting tar archive to a path containig a symlink
- Loading branch information
Showing
4 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...test/java/com/github/eirslett/maven/plugins/frontend/lib/DefaultArchiveExtractorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.github.eirslett.maven.plugins.frontend.lib; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Assume; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.fail; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
public class DefaultArchiveExtractorTest { | ||
|
||
private final String BAD_TAR = "src/test/resources/bad.tgz"; | ||
private final String GOOD_TAR = "src/test/resources/good.tgz"; | ||
|
||
@Rule | ||
public final TemporaryFolder temp = new TemporaryFolder(); | ||
|
||
private ArchiveExtractor extractor; | ||
|
||
@Before | ||
public void setup() { | ||
extractor = new DefaultArchiveExtractor(); | ||
} | ||
|
||
@Test | ||
public void extractGoodTarFile() throws Exception { | ||
File destination = temp.newFolder("destination"); | ||
extractor.extract(GOOD_TAR, destination.getPath()); | ||
} | ||
|
||
@Test | ||
public void extractGoodTarFileSymlink() throws Exception { | ||
File destination = temp.newFolder("destination"); | ||
Path link = createSymlinkOrSkipTest(temp.getRoot().toPath().resolve("link"), destination.toPath()); | ||
extractor.extract(GOOD_TAR, link.toString()); | ||
} | ||
|
||
@Test(expected = ArchiveExtractionException.class) | ||
public void extractBadTarFile() throws Exception { | ||
File destination = temp.newFolder("destination"); | ||
extractor.extract(BAD_TAR, destination.getPath()); | ||
} | ||
|
||
@Test(expected = ArchiveExtractionException.class) | ||
public void extractBadTarFileSymlink() throws Exception { | ||
File destination = temp.newFolder("destination"); | ||
Path link = createSymlinkOrSkipTest(temp.getRoot().toPath().resolve("link"), destination.toPath()); | ||
extractor.extract(BAD_TAR, link.toString()); | ||
} | ||
|
||
private Path createSymlinkOrSkipTest(Path link, Path target) { | ||
try { | ||
return Files.createSymbolicLink(link, target); | ||
} catch (UnsupportedOperationException | IOException e) { | ||
assumeTrue("symlinks not supported", false); | ||
return null; | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.