Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
illiliti authored and AJ ONeal committed Oct 13, 2020
1 parent b0ffd5a commit a9434ff
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,60 @@ func symmetricTest(t *testing.T, formatName, dest string, testSymlinks, testMode
}
}

func TestUnarchiveWithStripComponents(t *testing.T) {
testArchives := []string{
"testdata/sample.rar",
"testdata/testarchives/evilarchives/evil.zip",
"testdata/testarchives/evilarchives/evil.tar",
"testdata/testarchives/evilarchives/evil.tar.gz",
"testdata/testarchives/evilarchives/evil.tar.bz2",
}

to := "testdata/testarchives/destarchives/"

for _, archiveName := range testArchives {
f, err := ByExtension(archiveName)

if err != nil {
t.Error(err)
}

var target string

switch v := f.(type) {
case *Rar:
v.OverwriteExisting = false
v.ImplicitTopLevelFolder = false
v.StripComponents = 1
target = "quote1.txt"
case *Zip:
case *Tar:
v.OverwriteExisting = false
v.ImplicitTopLevelFolder = false
v.StripComponents = 1
target = "safefile"
case *TarGz:
case *TarBz2:
v.Tar.OverwriteExisting = false
v.Tar.ImplicitTopLevelFolder = false
v.Tar.StripComponents = 1
target = "safefile"
}

u := f.(Unarchiver)

if err := u.Unarchive(archiveName, to); err != nil {
fmt.Println(err)
}

if _, err := os.Stat(filepath.Join(to, target)); os.IsNotExist(err) {
t.Errorf("file is incorrectly extracted: %s", target)
}

os.RemoveAll(to)
}
}

// test at runtime if the CheckFilename function is behaving properly for the archive formats
func TestSafeExtraction(t *testing.T) {

Expand Down

0 comments on commit a9434ff

Please sign in to comment.