Fix possible panic during plugin installation (#15689)

Этот коммит содержится в:
Claudio Costa
2020-10-02 09:25:50 +02:00
коммит произвёл GitHub
родитель 6d7c5c5bf3
Коммит 51d790300f
2 изменённых файлов: 38 добавлений и 0 удалений

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

@@ -376,6 +376,8 @@ func (a *App) installExtractedPlugin(manifest *model.Manifest, fromPluginDir str
updatedManifest, _, err := pluginsEnvironment.Activate(manifest.Id)
if err != nil {
return nil, model.NewAppError("installExtractedPlugin", "app.plugin.restart.app_error", nil, err.Error(), http.StatusInternalServerError)
} else if updatedManifest == nil {
return nil, model.NewAppError("installExtractedPlugin", "app.plugin.restart.app_error", nil, "failed to activate plugin: plugin already active", http.StatusInternalServerError)
}
manifest = updatedManifest
}

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

@@ -8,10 +8,14 @@ import (
"bytes"
"compress/gzip"
"io"
"os"
"path/filepath"
"sort"
"testing"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -259,3 +263,35 @@ func TestInstallPluginLocally(t *testing.T) {
})
})
}
func TestInstallPluginAlreadyActive(t *testing.T) {
th := Setup(t)
defer th.TearDown()
path, _ := fileutils.FindDir("tests")
reader, err := os.Open(filepath.Join(path, "testplugin.tar.gz"))
require.NoError(t, err)
actualManifest, appError := th.App.InstallPlugin(reader, true)
require.NotNil(t, actualManifest)
require.Nil(t, appError)
appError = th.App.EnablePlugin(actualManifest.Id)
require.Nil(t, appError)
pluginsEnvironment := th.App.GetPluginsEnvironment()
require.NotNil(t, pluginsEnvironment)
bundleInfos, err := pluginsEnvironment.Available()
require.Nil(t, err)
require.NotEmpty(t, bundleInfos)
for _, bundleInfo := range bundleInfos {
if bundleInfo.Manifest.Id == actualManifest.Id {
err := os.RemoveAll(bundleInfo.Path)
require.NoError(t, err)
}
}
actualManifest, appError = th.App.InstallPlugin(reader, true)
require.NotNil(t, appError)
require.Nil(t, actualManifest)
require.Equal(t, "app.plugin.restart.app_error", appError.Id)
}