MM-21374 - Fixed extracting icon for prepackaged and local plugins (#13633)
* Merge upstream * Added extracting iconData for prepackaged and local plugins * Fixed tests * Removed report.xml Co-authored-by: Jason Paul Deland <9366595+jaydeland@users.noreply.github.com> Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
50e965510a
Коммит
ebfd332161
@@ -7,6 +7,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@@ -23,6 +24,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/utils"
|
"github.com/mattermost/mattermost-server/v5/utils"
|
||||||
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
|
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
|
||||||
|
|
||||||
|
svg "github.com/h2non/go-is-svg"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -602,10 +604,15 @@ func TestGetInstalledMarketplacePlugins(t *testing.T) {
|
|||||||
manifest, resp := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
manifest, resp := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
testIcon, err := ioutil.ReadFile(filepath.Join(path, "test.svg"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, svg.Is(testIcon))
|
||||||
|
testIconData := fmt.Sprintf("data:image/svg+xml;base64,%s", base64.StdEncoding.EncodeToString(testIcon))
|
||||||
|
|
||||||
expectedPlugins := append(samplePlugins, &model.MarketplacePlugin{
|
expectedPlugins := append(samplePlugins, &model.MarketplacePlugin{
|
||||||
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
||||||
HomepageURL: "https://example.com/homepage",
|
HomepageURL: "https://example.com/homepage",
|
||||||
IconData: "",
|
IconData: testIconData,
|
||||||
DownloadURL: "",
|
DownloadURL: "",
|
||||||
Labels: []model.MarketplaceLabel{{
|
Labels: []model.MarketplaceLabel{{
|
||||||
Name: "Local",
|
Name: "Local",
|
||||||
@@ -711,6 +718,11 @@ func TestSearchGetMarketplacePlugins(t *testing.T) {
|
|||||||
tarDataV2, err := ioutil.ReadFile(filepath.Join(path, "testplugin2.tar.gz"))
|
tarDataV2, err := ioutil.ReadFile(filepath.Join(path, "testplugin2.tar.gz"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
testIcon, err := ioutil.ReadFile(filepath.Join(path, "test.svg"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, svg.Is(testIcon))
|
||||||
|
testIconData := fmt.Sprintf("data:image/svg+xml;base64,%s", base64.StdEncoding.EncodeToString(testIcon))
|
||||||
|
|
||||||
t.Run("search installed plugin", func(t *testing.T) {
|
t.Run("search installed plugin", func(t *testing.T) {
|
||||||
th := Setup().InitBasic()
|
th := Setup().InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
@@ -740,7 +752,7 @@ func TestSearchGetMarketplacePlugins(t *testing.T) {
|
|||||||
plugin1 := &model.MarketplacePlugin{
|
plugin1 := &model.MarketplacePlugin{
|
||||||
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
||||||
HomepageURL: "https://example.com/homepage",
|
HomepageURL: "https://example.com/homepage",
|
||||||
IconData: "",
|
IconData: testIconData,
|
||||||
DownloadURL: "",
|
DownloadURL: "",
|
||||||
Labels: []model.MarketplaceLabel{{
|
Labels: []model.MarketplaceLabel{{
|
||||||
Name: "Local",
|
Name: "Local",
|
||||||
@@ -754,10 +766,11 @@ func TestSearchGetMarketplacePlugins(t *testing.T) {
|
|||||||
|
|
||||||
manifest, resp = th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarDataV2))
|
manifest, resp = th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarDataV2))
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
plugin2 := &model.MarketplacePlugin{
|
plugin2 := &model.MarketplacePlugin{
|
||||||
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
||||||
HomepageURL: "https://example.com/homepage2",
|
IconData: testIconData,
|
||||||
IconData: "",
|
HomepageURL: "https://example.com/homepage",
|
||||||
DownloadURL: "",
|
DownloadURL: "",
|
||||||
Labels: []model.MarketplaceLabel{{
|
Labels: []model.MarketplaceLabel{{
|
||||||
Name: "Local",
|
Name: "Local",
|
||||||
@@ -896,8 +909,14 @@ func TestGetLocalPluginInMarketplace(t *testing.T) {
|
|||||||
manifest, resp := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
manifest, resp := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
testIcon, err := ioutil.ReadFile(filepath.Join(path, "test.svg"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, svg.Is(testIcon))
|
||||||
|
testIconData := fmt.Sprintf("data:image/svg+xml;base64,%s", base64.StdEncoding.EncodeToString(testIcon))
|
||||||
|
|
||||||
newPlugin := &model.MarketplacePlugin{
|
newPlugin := &model.MarketplacePlugin{
|
||||||
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
||||||
|
IconData: testIconData,
|
||||||
HomepageURL: "https://example.com/homepage",
|
HomepageURL: "https://example.com/homepage",
|
||||||
Manifest: manifest,
|
Manifest: manifest,
|
||||||
},
|
},
|
||||||
@@ -930,10 +949,16 @@ func TestGetLocalPluginInMarketplace(t *testing.T) {
|
|||||||
manifest, resp := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
manifest, resp := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
|
testIcon, err := ioutil.ReadFile(filepath.Join(path, "test.svg"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, svg.Is(testIcon))
|
||||||
|
testIconData := fmt.Sprintf("data:image/svg+xml;base64,%s", base64.StdEncoding.EncodeToString(testIcon))
|
||||||
|
|
||||||
newPlugin := &model.MarketplacePlugin{
|
newPlugin := &model.MarketplacePlugin{
|
||||||
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
||||||
HomepageURL: "https://example.com/homepage",
|
|
||||||
Manifest: manifest,
|
Manifest: manifest,
|
||||||
|
IconData: testIconData,
|
||||||
|
HomepageURL: "https://example.com/homepage",
|
||||||
Labels: []model.MarketplaceLabel{{
|
Labels: []model.MarketplaceLabel{{
|
||||||
Name: "Local",
|
Name: "Local",
|
||||||
Description: "This plugin is not listed in the marketplace",
|
Description: "This plugin is not listed in the marketplace",
|
||||||
|
|||||||
@@ -534,7 +534,9 @@ func (a *App) mergePrepackagedPlugins(remoteMarketplacePlugins map[string]*model
|
|||||||
|
|
||||||
prepackagedMarketplace := &model.MarketplacePlugin{
|
prepackagedMarketplace := &model.MarketplacePlugin{
|
||||||
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
||||||
Manifest: prepackaged.Manifest,
|
HomepageURL: prepackaged.Manifest.HomepageURL,
|
||||||
|
IconData: prepackaged.IconData,
|
||||||
|
Manifest: prepackaged.Manifest,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,6 +589,14 @@ func (a *App) mergeLocalPlugins(remoteMarketplacePlugins map[string]*model.Marke
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iconData := ""
|
||||||
|
if plugin.Manifest.IconPath != "" {
|
||||||
|
iconData, err = getIcon(filepath.Join(plugin.Path, plugin.Manifest.IconPath))
|
||||||
|
if err != nil {
|
||||||
|
mlog.Warn("Error loading local plugin icon", mlog.String("plugin", plugin.Manifest.Id), mlog.String("icon_path", plugin.Manifest.IconPath), mlog.Err(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var labels []model.MarketplaceLabel
|
var labels []model.MarketplaceLabel
|
||||||
if *a.Config().PluginSettings.EnableRemoteMarketplace {
|
if *a.Config().PluginSettings.EnableRemoteMarketplace {
|
||||||
// Labels should not (yet) be localized as the labels sent by the Marketplace are not (yet) localizable.
|
// Labels should not (yet) be localized as the labels sent by the Marketplace are not (yet) localizable.
|
||||||
@@ -598,6 +608,7 @@ func (a *App) mergeLocalPlugins(remoteMarketplacePlugins map[string]*model.Marke
|
|||||||
|
|
||||||
remoteMarketplacePlugins[plugin.Manifest.Id] = &model.MarketplacePlugin{
|
remoteMarketplacePlugins[plugin.Manifest.Id] = &model.MarketplacePlugin{
|
||||||
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
||||||
|
IconData: iconData,
|
||||||
HomepageURL: plugin.Manifest.HomepageURL,
|
HomepageURL: plugin.Manifest.HomepageURL,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Manifest: plugin.Manifest,
|
Manifest: plugin.Manifest,
|
||||||
@@ -813,7 +824,7 @@ func getPrepackagedPlugin(pluginPath *pluginSignaturePath, pluginFile io.ReadSee
|
|||||||
}
|
}
|
||||||
|
|
||||||
if manifest.IconPath != "" {
|
if manifest.IconPath != "" {
|
||||||
iconData, err := getIcon(manifest.IconPath)
|
iconData, err := getIcon(filepath.Join(pluginDir, manifest.IconPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", errors.Wrapf(err, "Failed to read icon at %s", manifest.IconPath)
|
return nil, "", errors.Wrapf(err, "Failed to read icon at %s", manifest.IconPath)
|
||||||
}
|
}
|
||||||
|
|||||||
Двоичные данные
tests/testplugin.tar.gz
Двоичные данные
tests/testplugin.tar.gz
Двоичный файл не отображается.
@@ -1,14 +1,14 @@
|
|||||||
-----BEGIN PGP SIGNATURE-----
|
-----BEGIN PGP SIGNATURE-----
|
||||||
|
|
||||||
iQGzBAABCAAdFiEE8/rOReDeZCyL1qjmTHxlYsGSzB8FAl4hYxIACgkQTHxlYsGS
|
iQGzBAABCAAdFiEE8/rOReDeZCyL1qjmTHxlYsGSzB8FAl4hzNEACgkQTHxlYsGS
|
||||||
zB97wwwAqI1gZQsOg6zsKIPCJ6kQ721rG5EaI/eDseRbKnxaFdcoe2+QzqDXE0Ax
|
zB9+oQv+LoGzdDKmJu1J021S5lw6fIoUtEB0AUFHXZyij9bSLhMxey8LbW5l6JnG
|
||||||
P5RhZBKr+5hcS4msxjKPPMAVUZeMrhM7pYFV7y1zSkYQkyk8bcfspL3bVbAT4lXA
|
0Op0SEDU4c97eQMwFvfrLnJDepziFrlSZmt60v/6LxEraB4CfCQ/D6M2/dkcERnG
|
||||||
x2u2HN6zQqajmX5231hM60ScyIaQXE4aAyruJs4Jw0Cky+NWbXlmo+VVacRxjjp4
|
c7AUsbObiS6eYpkw5isLz6dP8LoHZBSl4Sw2aSujQL1IvPC3tAzkBDZ7HlxRK4Py
|
||||||
eAodiF+WNuQb0+72qdrvaP/X6PVi/eKe3uv/fWGOKeQUb7yV8WBOcXbyhA7qHY9F
|
x9ekBj26mrkwY+1A6to3GofK1fSo8NZtstuJ2408r4crGplOXahLrW2hW5f++4pJ
|
||||||
n2utzLXyu34UBKlkUA7T/RQvFFJCzZAoctR3oN0lPOVdRzRIw0T1WqSxRNbnRgW4
|
L0c4945emSO5XkHXMlz46WcRNvgEAeaLMZwmKxfVH5gDR9kbzrrEgDQibSZtn+mF
|
||||||
YPJdKvED7M68HFpdK37SBiMDivseU9I9vOfHRoaQlCK8CYTs1qHPx2hrivj7s5qN
|
mfMk22vlJ4wZUGnvWnbpEKUWllwmJcCXUkHc/Xw8s8vB+qcToAWZYFzIxydiUdVm
|
||||||
DStkmzcx1C6OwDt93my3M7WdUHeQ96ryXxFpS9Fj6vYdNTgOE03CW1WIPoNxXJme
|
oUzDvh/QcG2G4I6q+Qp2YqZs8QVCSJIQN50AAXKnNEh1D0M9EiK/3e/GfHvNnPwQ
|
||||||
FHu5o9DNr0bNcsye8TNWqoemmM6NlAEdk239NoODwMwtoTia2eufmfMqkgeH8kR8
|
uWjNw0bXKBIduDl/dZp7DSSRmtkFAmwu+tAZZbzaqb+qRzL1GuWneZbcgyCpze1C
|
||||||
BNCgEYSq
|
KXSi4aDJ
|
||||||
=8YEF
|
=1iVn
|
||||||
-----END PGP SIGNATURE-----
|
-----END PGP SIGNATURE-----
|
||||||
|
|||||||
Двоичные данные
tests/testplugin.tar.gz.sig
Двоичные данные
tests/testplugin.tar.gz.sig
Двоичный файл не отображается.
Двоичные данные
tests/testplugin2.tar.gz
Двоичные данные
tests/testplugin2.tar.gz
Двоичный файл не отображается.
14
tests/testplugin2.tar.gz.asc
Обычный файл
14
tests/testplugin2.tar.gz.asc
Обычный файл
@@ -0,0 +1,14 @@
|
|||||||
|
-----BEGIN PGP SIGNATURE-----
|
||||||
|
|
||||||
|
iQGzBAABCAAdFiEE8/rOReDeZCyL1qjmTHxlYsGSzB8FAl4fca4ACgkQTHxlYsGS
|
||||||
|
zB8qkgv/cTe71xkIHALB0HAvnd2HD6NqA3/AdOWIvZtmtU8une2s6Int28sPMkt9
|
||||||
|
HNmVsBpiDnsmB+jfkrf4NXpCVn3to/gB1qWSmudPWb+b54XGdD8SGOpmCT9Fd2qN
|
||||||
|
EGHjgvmHJ/2F5PQ5B+FazLflyFn0JcA+BCikBcJfmTvDdBgEwR5QEsowDy5mLb3v
|
||||||
|
AxKZR9PnmOkAt0/fs2geyqPZ1s+NTlsIHRP0Hvtkxq7BvQJWoTmcJb5mFbBvAz24
|
||||||
|
nsXzGpAFKpBjx9v9WErcq8Fy2Ad3Iqu7mKgTQxPrpreCRZceWJg327fFr8A2YVCU
|
||||||
|
Zo2cC/+By2GUmnotHVD4abead0J8t3eVyexg0CwOstQCeIEKfYtuU8UuyJtqhO6t
|
||||||
|
cKkE1oiBOo7TtYdWRQyR/9zlim7Wlj94WvquJLemCfazoQdq68hyvGa6C2lakZx3
|
||||||
|
iSzYw00V6U+aEXffadzXnmbQiJKcOu7gIyumBbGIDLOfM5ypACvnCNHxQ/mlYHjD
|
||||||
|
+HOR5g+1
|
||||||
|
=FsxQ
|
||||||
|
-----END PGP SIGNATURE-----
|
||||||
Двоичные данные
tests/testplugin2.tar.gz.sig
Двоичные данные
tests/testplugin2.tar.gz.sig
Двоичный файл не отображается.
Ссылка в новой задаче
Block a user