* Posts * Add missing translation * Fix internal store marshaling * [MM-22051] Remove To/From JSON (Channels) (#18116) * Channels * Channel members * ChannelSearch * Channel categories, list, sidebar, stats, view * Fix conversions * [MM-22051] Remove To/From JSON (Users) (#18121) * User related structs * Fix return * Team related structures (#18127) * [MM-22051] Remove To/From JSON (Status, Bot, Reaction, Thread, FileInfo) (#18130) * Status * Bot * Reaction * Thread * FileInfo * Some fixes * Translations update from Weblate (#18143) * Translated using Weblate (German) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ * Translated using Weblate (German) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Translated using Weblate (English (Australia)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/en_AU/ * Translated using Weblate (Bulgarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/bg/ * Translated using Weblate (Japanese) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ja/ * Translated using Weblate (Chinese (Simplified)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/zh_Hans/ Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> * [MM-22051] Remove To/From JSON methods from model (#18138) * Scheme * Role * Session * Config * Status * Fix logic * Emoji * GuestsInvite * Group * Command * ClusterInfo * License * Job * System * Plugin * Command2 * IncomingWebhook * OutgoingWebhook * Fix tests * Update traslation * Some fixes * Add missing return * Simplify * Make Config.ToJSONFiltered() return []byte * Make Busy.ToJSON() return []byte * Include error in log * Split logic * [MM-22051] Remove To/From JSON (final) (#18150) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * [MM-23280] Fix linting for ToJSON/FromJSON (#18153) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * Fix linting for ToJSON/FromJSON * Fix conversions Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
301 строка
9.1 KiB
Go
301 строка
9.1 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"archive/tar"
|
|
"bytes"
|
|
"compress/gzip"
|
|
"encoding/json"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/model"
|
|
"github.com/mattermost/mattermost-server/v6/utils/fileutils"
|
|
)
|
|
|
|
type nilReadSeeker struct {
|
|
}
|
|
|
|
func (r *nilReadSeeker) Read(p []byte) (int, error) {
|
|
return 0, io.EOF
|
|
}
|
|
|
|
func (r *nilReadSeeker) Seek(offset int64, whence int) (int64, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
type testFile struct {
|
|
Name, Body string
|
|
}
|
|
|
|
func makeInMemoryGzipTarFile(t *testing.T, files []testFile) *bytes.Reader {
|
|
var buf bytes.Buffer
|
|
gzWriter := gzip.NewWriter(&buf)
|
|
|
|
tgz := tar.NewWriter(gzWriter)
|
|
|
|
for _, file := range files {
|
|
hdr := &tar.Header{
|
|
Name: file.Name,
|
|
Mode: 0600,
|
|
Size: int64(len(file.Body)),
|
|
}
|
|
err := tgz.WriteHeader(hdr)
|
|
require.NoError(t, err, "failed to write %s to in-memory tar file", file.Name)
|
|
_, err = tgz.Write([]byte(file.Body))
|
|
require.NoError(t, err, "failed to write body of %s to in-memory tar file", file.Name)
|
|
}
|
|
err := tgz.Close()
|
|
require.NoError(t, err, "failed to close in-memory tar file")
|
|
|
|
err = gzWriter.Close()
|
|
require.NoError(t, err, "failed to close in-memory tar.gz file")
|
|
|
|
return bytes.NewReader(buf.Bytes())
|
|
}
|
|
|
|
type byBundleInfoId []*model.BundleInfo
|
|
|
|
func (b byBundleInfoId) Len() int { return len(b) }
|
|
func (b byBundleInfoId) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
|
func (b byBundleInfoId) Less(i, j int) bool { return b[i].Manifest.Id < b[j].Manifest.Id }
|
|
|
|
func TestInstallPluginLocally(t *testing.T) {
|
|
t.Run("invalid tar", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
|
|
actualManifest, appErr := th.App.installPluginLocally(&nilReadSeeker{}, nil, installPluginLocallyOnlyIfNew)
|
|
require.NotNil(t, appErr)
|
|
assert.Equal(t, "app.plugin.extract.app_error", appErr.Id, appErr.Error())
|
|
require.Nil(t, actualManifest)
|
|
})
|
|
|
|
t.Run("missing manifest", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
|
|
reader := makeInMemoryGzipTarFile(t, []testFile{
|
|
{"test", "test file"},
|
|
})
|
|
|
|
actualManifest, appErr := th.App.installPluginLocally(reader, nil, installPluginLocallyOnlyIfNew)
|
|
require.NotNil(t, appErr)
|
|
assert.Equal(t, "app.plugin.manifest.app_error", appErr.Id, appErr.Error())
|
|
require.Nil(t, actualManifest)
|
|
})
|
|
|
|
installPlugin := func(t *testing.T, th *TestHelper, id, version string, installationStrategy pluginInstallationStrategy) (*model.Manifest, *model.AppError) {
|
|
t.Helper()
|
|
|
|
manifest := &model.Manifest{
|
|
Id: id,
|
|
Version: version,
|
|
}
|
|
manifestJSON, jsonErr := json.Marshal(manifest)
|
|
require.NoError(t, jsonErr)
|
|
reader := makeInMemoryGzipTarFile(t, []testFile{
|
|
{"plugin.json", string(manifestJSON)},
|
|
})
|
|
|
|
actualManifest, appError := th.App.installPluginLocally(reader, nil, installationStrategy)
|
|
if actualManifest != nil {
|
|
require.Equal(t, manifest, actualManifest)
|
|
}
|
|
|
|
return actualManifest, appError
|
|
}
|
|
|
|
t.Run("invalid plugin id", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
|
|
actualManifest, appErr := installPlugin(t, th, "invalid#plugin#id", "version", installPluginLocallyOnlyIfNew)
|
|
require.NotNil(t, appErr)
|
|
assert.Equal(t, "app.plugin.invalid_id.app_error", appErr.Id, appErr.Error())
|
|
require.Nil(t, actualManifest)
|
|
})
|
|
|
|
// The following tests fail mysteriously on CI due to an unexpected bundle being present.
|
|
// This exists to clean up manually until we figure out what test isn't cleaning up after
|
|
// itself.
|
|
cleanExistingBundles := func(t *testing.T, th *TestHelper) {
|
|
pluginsEnvironment := th.App.GetPluginsEnvironment()
|
|
require.NotNil(t, pluginsEnvironment)
|
|
bundleInfos, err := pluginsEnvironment.Available()
|
|
require.NoError(t, err)
|
|
|
|
for _, bundleInfo := range bundleInfos {
|
|
err := th.App.removePluginLocally(bundleInfo.Manifest.Id)
|
|
require.Nilf(t, err, "failed to remove existing plugin %s", bundleInfo.Manifest.Id)
|
|
}
|
|
}
|
|
|
|
assertBundleInfoManifests := func(t *testing.T, th *TestHelper, manifests []*model.Manifest) {
|
|
pluginsEnvironment := th.App.GetPluginsEnvironment()
|
|
require.NotNil(t, pluginsEnvironment)
|
|
bundleInfos, err := pluginsEnvironment.Available()
|
|
require.NoError(t, err)
|
|
|
|
sort.Sort(byBundleInfoId(bundleInfos))
|
|
|
|
actualManifests := make([]*model.Manifest, 0, len(bundleInfos))
|
|
for _, bundleInfo := range bundleInfos {
|
|
actualManifests = append(actualManifests, bundleInfo.Manifest)
|
|
}
|
|
|
|
require.Equal(t, manifests, actualManifests)
|
|
}
|
|
|
|
t.Run("no plugins already installed", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
cleanExistingBundles(t, th)
|
|
|
|
manifest, appErr := installPlugin(t, th, "valid", "0.0.1", installPluginLocallyOnlyIfNew)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, manifest)
|
|
|
|
assertBundleInfoManifests(t, th, []*model.Manifest{manifest})
|
|
})
|
|
|
|
t.Run("different plugin already installed", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
cleanExistingBundles(t, th)
|
|
|
|
otherManifest, appErr := installPlugin(t, th, "other", "0.0.1", installPluginLocallyOnlyIfNew)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, otherManifest)
|
|
|
|
manifest, appErr := installPlugin(t, th, "valid", "0.0.1", installPluginLocallyOnlyIfNew)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, manifest)
|
|
|
|
assertBundleInfoManifests(t, th, []*model.Manifest{otherManifest, manifest})
|
|
})
|
|
|
|
t.Run("same plugin already installed", func(t *testing.T) {
|
|
t.Run("install only if new", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
cleanExistingBundles(t, th)
|
|
|
|
existingManifest, appErr := installPlugin(t, th, "valid", "0.0.1", installPluginLocallyOnlyIfNew)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, existingManifest)
|
|
|
|
manifest, appErr := installPlugin(t, th, "valid", "0.0.1", installPluginLocallyOnlyIfNew)
|
|
require.NotNil(t, appErr)
|
|
require.Equal(t, "app.plugin.install_id.app_error", appErr.Id, appErr.Error())
|
|
require.Nil(t, manifest)
|
|
|
|
assertBundleInfoManifests(t, th, []*model.Manifest{existingManifest})
|
|
})
|
|
|
|
t.Run("install if upgrade, but older", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
cleanExistingBundles(t, th)
|
|
|
|
existingManifest, appErr := installPlugin(t, th, "valid", "0.0.2", installPluginLocallyOnlyIfNewOrUpgrade)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, existingManifest)
|
|
|
|
manifest, appErr := installPlugin(t, th, "valid", "0.0.1", installPluginLocallyOnlyIfNewOrUpgrade)
|
|
require.Nil(t, appErr)
|
|
require.Nil(t, manifest)
|
|
|
|
assertBundleInfoManifests(t, th, []*model.Manifest{existingManifest})
|
|
})
|
|
|
|
t.Run("install if upgrade, but same version", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
cleanExistingBundles(t, th)
|
|
|
|
existingManifest, appErr := installPlugin(t, th, "valid", "0.0.2", installPluginLocallyOnlyIfNewOrUpgrade)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, existingManifest)
|
|
|
|
manifest, appErr := installPlugin(t, th, "valid", "0.0.2", installPluginLocallyOnlyIfNewOrUpgrade)
|
|
require.Nil(t, appErr)
|
|
require.Nil(t, manifest)
|
|
|
|
assertBundleInfoManifests(t, th, []*model.Manifest{existingManifest})
|
|
})
|
|
|
|
t.Run("install if upgrade, newer version", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
cleanExistingBundles(t, th)
|
|
|
|
existingManifest, appErr := installPlugin(t, th, "valid", "0.0.2", installPluginLocallyOnlyIfNewOrUpgrade)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, existingManifest)
|
|
|
|
manifest, appErr := installPlugin(t, th, "valid", "0.0.3", installPluginLocallyOnlyIfNewOrUpgrade)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, manifest)
|
|
|
|
assertBundleInfoManifests(t, th, []*model.Manifest{manifest})
|
|
})
|
|
|
|
t.Run("install always, old version", func(t *testing.T) {
|
|
th := Setup(t)
|
|
defer th.TearDown()
|
|
cleanExistingBundles(t, th)
|
|
|
|
existingManifest, appErr := installPlugin(t, th, "valid", "0.0.2", installPluginLocallyAlways)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, existingManifest)
|
|
|
|
manifest, appErr := installPlugin(t, th, "valid", "0.0.1", installPluginLocallyAlways)
|
|
require.Nil(t, appErr)
|
|
require.NotNil(t, manifest)
|
|
|
|
assertBundleInfoManifests(t, th, []*model.Manifest{manifest})
|
|
})
|
|
})
|
|
}
|
|
|
|
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.NoError(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)
|
|
}
|