Add tar extract permission tests

Signed-off-by: walkafwalka <2865898-walkafwalka@users.noreply.gitlab.com>
pull/5428/head
walkafwalka 7 years ago
parent 796f5eea85
commit 7eb7567e6b

@ -217,15 +217,16 @@ func TestExtract(t *testing.T) {
tw := tar.NewWriter(&tarbuf) tw := tar.NewWriter(&tarbuf)
var files = []struct { var files = []struct {
Name, Body string Name, Body string
Mode int64
}{ }{
{"../../plugin.yaml", "sneaky plugin metadata"}, {"../../plugin.yaml", "sneaky plugin metadata", 0600},
{"README.md", "some text"}, {"README.md", "some text", 0777},
} }
for _, file := range files { for _, file := range files {
hdr := &tar.Header{ hdr := &tar.Header{
Name: file.Name, Name: file.Name,
Typeflag: tar.TypeReg, Typeflag: tar.TypeReg,
Mode: 0600, Mode: file.Mode,
Size: int64(len(file.Body)), Size: int64(len(file.Body)),
} }
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {
@ -257,21 +258,25 @@ func TestExtract(t *testing.T) {
} }
pluginYAMLFullPath := filepath.Join(cacheDir, "plugin.yaml") pluginYAMLFullPath := filepath.Join(cacheDir, "plugin.yaml")
if _, err := os.Stat(pluginYAMLFullPath); err != nil { if info, err := os.Stat(pluginYAMLFullPath); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
t.Errorf("Expected %s to exist but doesn't", pluginYAMLFullPath) t.Errorf("Expected %s to exist but doesn't", pluginYAMLFullPath)
} else { } else {
t.Error(err) t.Error(err)
} }
} else if info.Mode().Perm() != 0600 {
t.Errorf("Expected %s to have 0600 mode it but has %o", pluginYAMLFullPath, info.Mode().Perm())
} }
readmeFullPath := filepath.Join(cacheDir, "README.md") readmeFullPath := filepath.Join(cacheDir, "README.md")
if _, err := os.Stat(readmeFullPath); err != nil { if info, err := os.Stat(readmeFullPath); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
t.Errorf("Expected %s to exist but doesn't", readmeFullPath) t.Errorf("Expected %s to exist but doesn't", readmeFullPath)
} else { } else {
t.Error(err) t.Error(err)
} }
} else if info.Mode().Perm() != 0777 {
t.Errorf("Expected %s to have 0777 mode it but has %o", readmeFullPath, info.Mode().Perm())
} }
} }

Loading…
Cancel
Save