MM-12641 not panic when dont have permission in the plugin folder (#9690)

* MM-12641 not panic when dont have permission in the plugin folder

* udpate return statment
Этот коммит содержится в:
Carlos Tadeu Panato Junior
2018-11-08 19:25:08 +01:00
коммит произвёл Christopher Speller
родитель 8d56fcf568
Коммит c52e808e34
2 изменённых файлов: 28 добавлений и 10 удалений

Просмотреть файл

@@ -273,25 +273,23 @@ func FindManifest(dir string) (manifest *Manifest, path string, err error) {
f, ferr := os.Open(path)
if ferr != nil {
if !os.IsNotExist(ferr) {
err = ferr
return
return nil, "", ferr
}
continue
}
b, ioerr := ioutil.ReadAll(f)
f.Close()
if ioerr != nil {
err = ioerr
return
return nil, path, ioerr
}
var parsed Manifest
err = yaml.Unmarshal(b, &parsed)
if err != nil {
return
return nil, path, err
}
manifest = &parsed
manifest.Id = strings.ToLower(manifest.Id)
return
return manifest, path, nil
}
path = filepath.Join(dir, "plugin.json")
@@ -300,16 +298,15 @@ func FindManifest(dir string) (manifest *Manifest, path string, err error) {
if os.IsNotExist(ferr) {
path = ""
}
err = ferr
return
return nil, path, ferr
}
defer f.Close()
var parsed Manifest
err = json.NewDecoder(f).Decode(&parsed)
if err != nil {
return
return nil, path, err
}
manifest = &parsed
manifest.Id = strings.ToLower(manifest.Id)
return
return manifest, path, nil
}

Просмотреть файл

@@ -185,6 +185,27 @@ func TestFindManifest_FileErrors(t *testing.T) {
}
}
func TestFindManifest_FolderPermission(t *testing.T) {
for _, tc := range []string{"plugin.yaml", "plugin.json"} {
dir, err := ioutil.TempDir("", "mm-plugin-test")
defer os.RemoveAll(dir)
path := filepath.Join(dir, tc)
require.NoError(t, os.Mkdir(path, 0700))
//User does not have permission in the plugin folder
err = os.Chmod(dir, 0066)
require.NoError(t, err)
m, mpath, err := FindManifest(dir)
assert.Nil(t, m)
assert.Equal(t, "", mpath)
assert.Error(t, err, tc)
assert.False(t, os.IsNotExist(err), tc)
}
}
func TestManifestJson(t *testing.T) {
manifest := &Manifest{
Id: "theid",