From 7eb7567e6b7dbdc9fa67c05d17f492b026794ddb Mon Sep 17 00:00:00 2001 From: walkafwalka <2865898-walkafwalka@users.noreply.gitlab.com> Date: Tue, 2 Apr 2019 17:53:05 -0700 Subject: [PATCH] Add tar extract permission tests Signed-off-by: walkafwalka <2865898-walkafwalka@users.noreply.gitlab.com> --- pkg/plugin/installer/http_installer_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/plugin/installer/http_installer_test.go b/pkg/plugin/installer/http_installer_test.go index 73af75e8c..d11513749 100644 --- a/pkg/plugin/installer/http_installer_test.go +++ b/pkg/plugin/installer/http_installer_test.go @@ -217,15 +217,16 @@ func TestExtract(t *testing.T) { tw := tar.NewWriter(&tarbuf) var files = []struct { Name, Body string + Mode int64 }{ - {"../../plugin.yaml", "sneaky plugin metadata"}, - {"README.md", "some text"}, + {"../../plugin.yaml", "sneaky plugin metadata", 0600}, + {"README.md", "some text", 0777}, } for _, file := range files { hdr := &tar.Header{ Name: file.Name, Typeflag: tar.TypeReg, - Mode: 0600, + Mode: file.Mode, Size: int64(len(file.Body)), } if err := tw.WriteHeader(hdr); err != nil { @@ -257,21 +258,25 @@ func TestExtract(t *testing.T) { } 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) { t.Errorf("Expected %s to exist but doesn't", pluginYAMLFullPath) } else { 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") - if _, err := os.Stat(readmeFullPath); err != nil { + if info, err := os.Stat(readmeFullPath); err != nil { if os.IsNotExist(err) { t.Errorf("Expected %s to exist but doesn't", readmeFullPath) } else { 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()) } }