Files
upstream-mattermost/server/cmd/mmctl/commands/plugin_e2e_test.go
upstream-mirror 240db4e2a7
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 00:29:55 +05:00

610 lines
21 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package commands
import (
"fmt"
"net/http"
"net/http/httptest"
"path/filepath"
"github.com/hashicorp/go-multierror"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/v8"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/client"
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
)
func (s *MmctlE2ETestSuite) TestPluginAddCmd() {
s.SetupTestHelper().InitBasic(s.T())
pluginPath := filepath.Join(server.GetPackagePath(), "tests", "testplugin.tar.gz")
s.RunForSystemAdminAndLocal("add an already installed plugin without force", func(c client.Client) {
printer.Clean()
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
*cfg.PluginSettings.EnableUploads = true
})
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = false
*cfg.PluginSettings.EnableUploads = false
})
err := pluginAddCmdF(c, &cobra.Command{}, []string{pluginPath})
s.Require().Nil(err)
s.Require().Equal(1, len(printer.GetLines()))
s.Require().Contains(printer.GetLines()[0], "Added plugin: ")
printer.Clean()
err = pluginAddCmdF(c, &cobra.Command{}, []string{pluginPath})
s.Require().ErrorContains(err, "Unable to install plugin. A plugin with the same ID is already installed.")
s.Require().Equal(0, len(printer.GetLines()))
s.Require().Equal(1, len(printer.GetErrorLines()))
s.Require().Contains(printer.GetErrorLines()[0], "Unable to install plugin. A plugin with the same ID is already installed.")
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
// teardown
pInfo := plugins.Inactive[0]
err = pluginDeleteCmdF(c, &cobra.Command{}, []string{pInfo.Id})
s.Require().Nil(err)
})
s.RunForSystemAdminAndLocal("add an already installed plugin with force", func(c client.Client) {
printer.Clean()
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
*cfg.PluginSettings.EnableUploads = true
})
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = false
*cfg.PluginSettings.EnableUploads = false
})
err := pluginAddCmdF(c, &cobra.Command{}, []string{pluginPath})
s.Require().Nil(err)
s.Require().Equal(1, len(printer.GetLines()))
s.Require().Contains(printer.GetLines()[0], "Added plugin: ")
printer.Clean()
cmd := &cobra.Command{}
cmd.Flags().Bool("force", true, "")
err = pluginAddCmdF(c, cmd, []string{pluginPath})
s.Require().Nil(err)
s.Require().Equal(1, len(printer.GetLines()))
s.Require().Equal(0, len(printer.GetErrorLines()))
s.Require().Contains(printer.GetLines()[0], "Added plugin: ")
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
// teardown
pInfo := plugins.Inactive[0]
err = pluginDeleteCmdF(c, &cobra.Command{}, []string{pInfo.Id})
s.Require().Nil(err)
})
s.RunForSystemAdminAndLocal("admin and local can't add plugins if the config doesn't allow it", func(c client.Client) {
printer.Clean()
err := pluginAddCmdF(c, &cobra.Command{}, []string{pluginPath})
s.Require().ErrorContains(err, "Plugins and/or plugin uploads have been disabled.")
s.Require().Equal(1, len(printer.GetErrorLines()))
s.Require().Contains(printer.GetErrorLines()[0], "Plugins and/or plugin uploads have been disabled.")
})
s.RunForSystemAdminAndLocal("admin and local can add a plugin if the config allows it", func(c client.Client) {
printer.Clean()
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
*cfg.PluginSettings.EnableUploads = true
})
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = false
*cfg.PluginSettings.EnableUploads = false
})
err := pluginAddCmdF(c, &cobra.Command{}, []string{pluginPath})
s.Require().Nil(err)
s.Require().Equal(1, len(printer.GetLines()))
s.Require().Contains(printer.GetLines()[0], "Added plugin: ")
res, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Equal(1, len(res.Inactive))
// teardown
pInfo := res.Inactive[0]
err = pluginDeleteCmdF(c, &cobra.Command{}, []string{pInfo.Id})
s.Require().Nil(err)
})
s.Run("normal user can't add plugin", func() {
printer.Clean()
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
*cfg.PluginSettings.EnableUploads = true
})
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = false
*cfg.PluginSettings.EnableUploads = false
})
err := pluginAddCmdF(s.th.Client, &cobra.Command{}, []string{pluginPath})
s.Require().ErrorContains(err, "You do not have the appropriate permissions")
s.Require().Equal(1, len(printer.GetErrorLines()))
s.Require().Contains(printer.GetErrorLines()[0], "You do not have the appropriate permissions")
})
}
func (s *MmctlE2ETestSuite) TestPluginInstallURLCmd() {
s.SetupTestHelper().InitBasic(s.T())
testsDir := filepath.Join(server.GetPackagePath(), "tests")
fileServer := httptest.NewServer(http.FileServer(http.Dir(testsDir)))
defer fileServer.Close()
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
*cfg.PluginSettings.EnableUploads = true
*cfg.PluginSettings.AllowInsecureDownloadURL = true
})
const (
plugin1ID = "testplugin"
plugin2ID = "testplugin2"
)
plugin1URL := fileServer.URL + "/testplugin.tar.gz"
plugin2URL := fileServer.URL + "/testplugin2.tar.gz"
s.RunForSystemAdminAndLocal("install new plugins", func(c client.Client) {
printer.Clean()
defer removePluginIfInstalled(c, s, plugin1ID)
defer removePluginIfInstalled(c, s, plugin2ID)
err := pluginInstallURLCmdF(c, &cobra.Command{}, []string{plugin1URL, plugin2URL})
s.Require().Nil(err)
s.Require().Len(printer.GetLines(), 2)
s.Require().Len(printer.GetErrorLines(), 0)
s.Require().Equal(plugin1ID, printer.GetLines()[0].(*model.Manifest).Id)
s.Require().Equal(plugin2ID, printer.GetLines()[1].(*model.Manifest).Id)
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 2)
})
s.Run("install a plugin without permissions", func() {
printer.Clean()
defer removePluginIfInstalled(s.th.Client, s, plugin1ID)
var expected error
expected = multierror.Append(expected, errors.New("You do not have the appropriate permissions.")) //nolint:revive
err := pluginInstallURLCmdF(s.th.Client, &cobra.Command{}, []string{plugin1URL})
s.Require().ErrorContains(err, expected.Error())
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Contains(printer.GetErrorLines()[0], fmt.Sprintf("Unable to install plugin from URL \"%s\".", plugin1URL))
s.Require().Contains(printer.GetErrorLines()[0], "You do not have the appropriate permissions.")
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 0)
})
s.RunForSystemAdminAndLocal("install a nonexistent plugin", func(c client.Client) {
printer.Clean()
nonexistentURL := fileServer.URL + "/nonexistent-plugin.tar.gz"
var expected error
expected = multierror.Append(expected, errors.New("An error occurred while downloading the plugin.")) //nolint:revive
err := pluginInstallURLCmdF(c, &cobra.Command{}, []string{nonexistentURL})
s.Require().ErrorContains(err, expected.Error())
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Contains(printer.GetErrorLines()[0], fmt.Sprintf("Unable to install plugin from URL \"%s\".", nonexistentURL))
s.Require().Contains(printer.GetErrorLines()[0], "An error occurred while downloading the plugin.")
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 0)
})
s.RunForSystemAdminAndLocal("install an already installed plugin without force", func(c client.Client) {
printer.Clean()
defer removePluginIfInstalled(c, s, plugin1ID)
err := pluginInstallURLCmdF(c, &cobra.Command{}, []string{plugin1URL})
s.Require().Nil(err)
s.Require().Len(printer.GetLines(), 1)
s.Require().Len(printer.GetErrorLines(), 0)
s.Require().Equal(plugin1ID, printer.GetLines()[0].(*model.Manifest).Id)
err = pluginInstallURLCmdF(c, &cobra.Command{}, []string{plugin1URL})
s.Require().ErrorContains(err, "Unable to install plugin. A plugin with the same ID is already installed.")
s.Require().Len(printer.GetLines(), 1)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Contains(printer.GetErrorLines()[0], fmt.Sprintf("Unable to install plugin from URL \"%s\".", plugin1URL))
s.Require().Contains(printer.GetErrorLines()[0], "Unable to install plugin. A plugin with the same ID is already installed.")
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
})
s.RunForSystemAdminAndLocal("install an already installed plugin with force", func(c client.Client) {
printer.Clean()
defer removePluginIfInstalled(c, s, plugin1ID)
err := pluginInstallURLCmdF(c, &cobra.Command{}, []string{plugin1URL})
s.Require().Nil(err)
s.Require().Len(printer.GetLines(), 1)
s.Require().Len(printer.GetErrorLines(), 0)
s.Require().Equal(plugin1ID, printer.GetLines()[0].(*model.Manifest).Id)
cmd := &cobra.Command{}
cmd.Flags().Bool("force", true, "")
err = pluginInstallURLCmdF(c, cmd, []string{plugin1URL})
s.Require().Nil(err)
s.Require().Len(printer.GetLines(), 2)
s.Require().Len(printer.GetErrorLines(), 0)
s.Require().Equal(plugin1ID, printer.GetLines()[1].(*model.Manifest).Id)
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
})
}
func (s *MmctlE2ETestSuite) TestPluginDeleteCmd() {
s.SetupTestHelper().InitBasic(s.T())
testsDir := filepath.Join(server.GetPackagePath(), "tests")
fileServer := httptest.NewServer(http.FileServer(http.Dir(testsDir)))
defer fileServer.Close()
const (
pluginID = "testplugin"
dummyPluginID = "randompluginxz"
)
pluginURL := fileServer.URL + "/testplugin.tar.gz"
s.RunForSystemAdminAndLocal("Delete Plugin", func(c client.Client) {
printer.Clean()
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
*cfg.PluginSettings.EnableUploads = true
*cfg.PluginSettings.AllowInsecureDownloadURL = true
})
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = false
*cfg.PluginSettings.EnableUploads = false
*cfg.PluginSettings.AllowInsecureDownloadURL = false
})
errInstall := pluginInstallURLCmdF(c, &cobra.Command{}, []string{pluginURL})
s.Require().Nil(errInstall)
s.Require().Len(printer.GetLines(), 1)
s.Require().Len(printer.GetErrorLines(), 0)
s.Require().Equal(pluginID, printer.GetLines()[0].(*model.Manifest).Id)
pluginsAvail, appErrInstall := s.th.App.GetPlugins()
s.Require().Nil(appErrInstall)
s.Require().Len(pluginsAvail.Active, 0)
s.Require().Len(pluginsAvail.Inactive, 1)
err := pluginDeleteCmdF(c, &cobra.Command{}, []string{pluginID})
s.Require().Nil(err)
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 0)
})
s.RunForSystemAdminAndLocal("Delete Unknown Plugin", func(c client.Client) {
printer.Clean()
err := pluginDeleteCmdF(c, &cobra.Command{}, []string{dummyPluginID})
s.Require().ErrorContains(err, "Plugins have been disabled.")
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Contains(printer.GetErrorLines()[0], fmt.Sprintf("Unable to delete plugin: %s.", dummyPluginID))
s.Require().Contains(printer.GetErrorLines()[0], "Plugins have been disabled.")
})
s.Run("Delete a Plugin without permissions", func() {
printer.Clean()
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
*cfg.PluginSettings.EnableUploads = true
*cfg.PluginSettings.AllowInsecureDownloadURL = true
})
defer func() {
errDelete := pluginDeleteCmdF(s.th.SystemAdminClient, &cobra.Command{}, []string{pluginID})
s.Require().Nil(errDelete)
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = false
*cfg.PluginSettings.EnableUploads = false
*cfg.PluginSettings.AllowInsecureDownloadURL = false
})
}()
errInstall := pluginInstallURLCmdF(s.th.SystemAdminClient, &cobra.Command{}, []string{pluginURL})
s.Require().Nil(errInstall)
s.Require().Len(printer.GetLines(), 1)
s.Require().Len(printer.GetErrorLines(), 0)
s.Require().Equal(pluginID, printer.GetLines()[0].(*model.Manifest).Id)
pluginsAvail, appErrInstall := s.th.App.GetPlugins()
s.Require().Nil(appErrInstall)
s.Require().Len(pluginsAvail.Active, 0)
s.Require().Len(pluginsAvail.Inactive, 1)
err := pluginDeleteCmdF(s.th.Client, &cobra.Command{}, []string{pluginID})
s.Require().ErrorContains(err, "You do not have the appropriate permissions.")
s.Require().Len(printer.GetLines(), 1)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Contains(printer.GetErrorLines()[0], fmt.Sprintf("Unable to delete plugin: %s.", pluginID))
s.Require().Contains(printer.GetErrorLines()[0], "You do not have the appropriate permissions.")
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
})
}
func (s *MmctlE2ETestSuite) TestPluginListCmdF() {
s.SetupTestHelper().InitBasic(s.T())
s.Run("Error when appropriate permissions are not available", func() {
printer.Clean()
enablePlugin := *s.th.App.Config().PluginSettings.Enable
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
})
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = enablePlugin
})
cmd := &cobra.Command{}
err := pluginListCmdF(s.th.Client, cmd, []string{})
s.Require().Error(err)
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 0)
s.Equal("Unable to list plugins. Error: You do not have the appropriate permissions.", err.Error())
})
s.RunForSystemAdminAndLocal("Error when plugins are disabled", func(c client.Client) {
printer.Clean()
enablePlugin := *s.th.App.Config().PluginSettings.Enable
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = false
})
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = enablePlugin
})
cmd := &cobra.Command{}
err := pluginListCmdF(c, cmd, []string{})
s.Require().Error(err)
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 0)
s.Equal("Unable to list plugins. Error: Plugins have been disabled. Please check your logs for details.", err.Error())
})
s.RunForSystemAdminAndLocal("Success when appropriate permissions are available", func(c client.Client) {
printer.Clean()
enablePlugin := *s.th.App.Config().PluginSettings.Enable
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
})
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = enablePlugin
})
cmd := &cobra.Command{}
err := pluginListCmdF(c, cmd, []string{})
s.Require().Nil(err)
s.Require().Len(printer.GetLines(), 3)
s.Require().Len(printer.GetErrorLines(), 0)
})
s.RunForSystemAdminAndLocal("Success when appropriate permissions are available but prints json plugins", func(c client.Client) {
printer.Clean()
enablePlugin := *s.th.App.Config().PluginSettings.Enable
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
})
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = enablePlugin
})
cmd := &cobra.Command{}
cmd.Flags().String("format", "json", "")
err := pluginListCmdF(c, cmd, []string{})
s.Require().Nil(err)
s.Require().Len(printer.GetLines(), 1)
s.Require().Len(printer.GetErrorLines(), 0)
})
}
func (s *MmctlE2ETestSuite) TestPluginDisableCmd() {
s.SetupTestHelper().InitBasic(s.T())
pluginID := "testplugin"
pluginURL := filepath.Join(server.GetPackagePath(), "tests", "testplugin.tar.gz")
nonExistentPluginID := "nonExistentPluginID"
enablePlugin := *s.th.App.Config().PluginSettings.Enable
enableUploads := *s.th.App.Config().PluginSettings.EnableUploads
defer func() {
appErr := s.th.App.Channels().RemovePlugin(pluginID)
if appErr != nil {
s.Require().Contains(appErr.Error(), "Plugin is not installed.")
}
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 0)
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = enablePlugin
*cfg.PluginSettings.EnableUploads = enableUploads
})
}()
// Enable plugin uploads
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
*cfg.PluginSettings.EnableUploads = true
})
// Install plugin first
err := pluginAddCmdF(s.th.SystemAdminClient, &cobra.Command{}, []string{pluginURL})
s.Require().Nil(err)
s.RunForSystemAdminAndLocal("Successful disable plugin", func(c client.Client) {
printer.Clean()
appErr := s.th.App.EnablePlugin(pluginID)
s.Require().Nil(appErr)
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 1)
s.Require().Len(plugins.Inactive, 0)
cmd := &cobra.Command{}
err := pluginDisableCmdF(c, cmd, []string{pluginID})
s.Require().Nil(err)
plugins, appErr = s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
s.Require().Len(printer.GetLines(), 1)
s.Require().Equal(printer.GetLines()[0], "Disabled plugin: "+pluginID)
})
s.Run("error for disable plugin due insufficient permissions", func() {
printer.Clean()
appErr := s.th.App.EnablePlugin(pluginID)
s.Require().Nil(appErr)
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 1)
s.Require().Len(plugins.Inactive, 0)
cmd := &cobra.Command{}
err := pluginDisableCmdF(s.th.Client, cmd, []string{pluginID})
s.Require().NotNil(err)
s.Require().ErrorContains(err, "You do not have the appropriate permissions.")
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Equal(printer.GetErrorLines()[0], "Unable to disable plugin: "+pluginID+". Error: You do not have the appropriate permissions.")
plugins, appErr = s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 1)
s.Require().Len(plugins.Inactive, 0)
appErr = s.th.App.DisablePlugin(pluginID)
s.Require().Nil(appErr)
})
s.RunForSystemAdminAndLocal("error for disabling non existent plugin", func(c client.Client) {
printer.Clean()
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
cmd := &cobra.Command{}
err := pluginDisableCmdF(c, cmd, []string{nonExistentPluginID})
s.Require().NotNil(err)
s.Require().ErrorContains(err, "Plugin is not installed.")
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Equal(printer.GetErrorLines()[0], "Unable to disable plugin: "+nonExistentPluginID+". Error: Plugin is not installed.")
plugins, appErr = s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
})
s.RunForSystemAdminAndLocal("error when plugin configs are disabled", func(c client.Client) {
printer.Clean()
appErr := s.th.App.EnablePlugin(pluginID)
s.Require().Nil(appErr)
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 1)
s.Require().Len(plugins.Inactive, 0)
enablePlugin2 := *s.th.App.Config().PluginSettings.Enable
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = enablePlugin2
})
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = false
})
cmd := &cobra.Command{}
err := pluginDisableCmdF(c, cmd, []string{pluginID})
s.Require().NotNil(err)
s.Require().ErrorContains(err, "Plugins have been disabled. Please check your logs for details.")
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Equal(printer.GetErrorLines()[0], "Unable to disable plugin: "+pluginID+". Error: Plugins have been disabled. Please check your logs for details.")
})
}