github.com/weiwenhao/getter@v1.30.1/decompress_zip_test.go (about)

     1  package getter
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"runtime"
     7  	"testing"
     8  )
     9  
    10  func TestZipDecompressor(t *testing.T) {
    11  	cases := []TestDecompressCase{
    12  		{
    13  			"empty.zip",
    14  			false,
    15  			true,
    16  			nil,
    17  			"",
    18  			nil,
    19  		},
    20  
    21  		{
    22  			"single.zip",
    23  			false,
    24  			false,
    25  			nil,
    26  			"d3b07384d113edec49eaa6238ad5ff00",
    27  			nil,
    28  		},
    29  
    30  		{
    31  			"single.zip",
    32  			true,
    33  			false,
    34  			[]string{"file"},
    35  			"",
    36  			nil,
    37  		},
    38  
    39  		{
    40  			"multiple.zip",
    41  			true,
    42  			false,
    43  			[]string{"file1", "file2"},
    44  			"",
    45  			nil,
    46  		},
    47  
    48  		{
    49  			"multiple.zip",
    50  			false,
    51  			true,
    52  			nil,
    53  			"",
    54  			nil,
    55  		},
    56  
    57  		{
    58  			"subdir.zip",
    59  			true,
    60  			false,
    61  			[]string{"file1", "subdir/", "subdir/child"},
    62  			"",
    63  			nil,
    64  		},
    65  
    66  		{
    67  			"subdir_empty.zip",
    68  			true,
    69  			false,
    70  			[]string{"file1", "subdir/"},
    71  			"",
    72  			nil,
    73  		},
    74  
    75  		{
    76  			"subdir_missing_dir.zip",
    77  			true,
    78  			false,
    79  			[]string{"file1", "subdir/", "subdir/child"},
    80  			"",
    81  			nil,
    82  		},
    83  
    84  		// Tests that a zip can't contain references with "..".
    85  		{
    86  			"outside_parent.zip",
    87  			true,
    88  			true,
    89  			nil,
    90  			"",
    91  			nil,
    92  		},
    93  	}
    94  
    95  	for i, tc := range cases {
    96  		cases[i].Input = filepath.Join("./testdata", "decompress-zip", tc.Input)
    97  	}
    98  
    99  	TestDecompressor(t, new(ZipDecompressor), cases)
   100  }
   101  
   102  func TestDecompressZipPermissions(t *testing.T) {
   103  	d := new(ZipDecompressor)
   104  	input := "./test-fixtures/decompress-zip/permissions.zip"
   105  
   106  	var expected map[string]int
   107  	var masked int
   108  
   109  	if runtime.GOOS == "windows" {
   110  		expected = map[string]int{
   111  			"directory/public":  0666,
   112  			"directory/private": 0666,
   113  			"directory/exec":    0666,
   114  			"directory/setuid":  0666,
   115  		}
   116  		masked = 0666
   117  	} else {
   118  		expected = map[string]int{
   119  			"directory/public":  0666,
   120  			"directory/private": 0600,
   121  			"directory/exec":    0755,
   122  			"directory/setuid":  040000755,
   123  		}
   124  		masked = 0755
   125  	}
   126  
   127  	testDecompressorPermissions(t, d, input, expected, os.FileMode(0))
   128  
   129  	expected["directory/setuid"] = masked
   130  	testDecompressorPermissions(t, d, input, expected, os.FileMode(060000000))
   131  }