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 Nightly Race / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
251 lines
7.2 KiB
Go
251 lines
7.2 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/client"
|
|
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func (s *MmctlE2ETestSuite) TestGetBusyCmd() {
|
|
s.SetupEnterpriseTestHelper().InitBasic(s.T())
|
|
|
|
s.th.App.Srv().Platform().Busy.Set(time.Minute)
|
|
defer s.th.App.Srv().Platform().Busy.Clear()
|
|
|
|
s.Run("MM-T3979 Should fail when regular user attempts to get server busy status", func() {
|
|
printer.Clean()
|
|
|
|
err := getBusyCmdF(s.th.Client, &cobra.Command{}, nil)
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("MM-T3956 Get server busy status", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
err := getBusyCmdF(c, &cobra.Command{}, nil)
|
|
s.Require().NoError(err)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
state, ok := printer.GetLines()[0].(*model.ServerBusyState)
|
|
s.Require().True(ok, true)
|
|
s.Require().True(state.Busy, true)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestNukeUsersCmd() {
|
|
s.SetupTestHelper().InitBasic(s.T())
|
|
|
|
s.Run("Delete all users as unprivileged user should not work", func() {
|
|
printer.Clean()
|
|
|
|
cmd := &cobra.Command{}
|
|
confirm := true
|
|
cmd.Flags().BoolVar(&confirm, "confirm", confirm, "confirm")
|
|
|
|
err := nukeUsersCmdF(s.th.Client, cmd, []string{})
|
|
s.Require().NotNil(err)
|
|
s.Len(printer.GetLines(), 0)
|
|
s.Len(printer.GetErrorLines(), 0)
|
|
|
|
// expect users not deleted
|
|
users, err := s.th.App.GetUsersPage(&model.UserGetOptions{
|
|
Page: 0,
|
|
PerPage: 10,
|
|
}, true)
|
|
s.Require().Nil(err)
|
|
s.Require().NotZero(len(users))
|
|
})
|
|
|
|
s.Run("Delete all users as system admin through the port API should not work", func() {
|
|
printer.Clean()
|
|
|
|
cmd := &cobra.Command{}
|
|
confirm := true
|
|
cmd.Flags().BoolVar(&confirm, "confirm", confirm, "confirm")
|
|
|
|
err := nukeUsersCmdF(s.th.SystemAdminClient, cmd, []string{})
|
|
s.Require().NotNil(err)
|
|
s.Len(printer.GetLines(), 0)
|
|
s.Len(printer.GetErrorLines(), 0)
|
|
|
|
// expect users not deleted
|
|
users, err := s.th.App.GetUsersPage(&model.UserGetOptions{
|
|
Page: 0,
|
|
PerPage: 10,
|
|
}, true)
|
|
s.Require().Nil(err)
|
|
s.Require().NotZero(len(users))
|
|
})
|
|
|
|
s.Run("Delete all users through local mode should work correctly", func() {
|
|
printer.Clean()
|
|
|
|
// populate with some user
|
|
for range 10 {
|
|
userData := model.User{
|
|
Username: "fakeuser" + model.NewRandomString(10),
|
|
Password: model.NewTestPassword(),
|
|
Email: s.th.GenerateTestEmail(),
|
|
}
|
|
_, err := s.th.App.CreateUser(s.th.Context, &userData)
|
|
s.Require().Nil(err)
|
|
}
|
|
|
|
cmd := &cobra.Command{}
|
|
confirm := true
|
|
cmd.Flags().BoolVar(&confirm, "confirm", confirm, "confirm")
|
|
|
|
// delete all users only works on local mode
|
|
err := nukeUsersCmdF(s.th.LocalClient, cmd, []string{})
|
|
s.Require().Nil(err)
|
|
s.Len(printer.GetLines(), 1)
|
|
s.Len(printer.GetErrorLines(), 0)
|
|
s.Require().Equal(printer.GetLines()[0], "All users successfully deleted")
|
|
|
|
// expect users deleted
|
|
users, err := s.th.App.GetUsersPage(&model.UserGetOptions{
|
|
Page: 0,
|
|
PerPage: 10,
|
|
}, true)
|
|
s.Require().Nil(err)
|
|
s.Require().Zero(len(users))
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestSetBusyCmd() {
|
|
s.SetupEnterpriseTestHelper().InitBasic(s.T())
|
|
|
|
s.th.App.Srv().Platform().Busy.Clear()
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Uint("seconds", 60, "")
|
|
|
|
s.Run("MM-T3980 Should fail when regular user attempts to set server busy status", func() {
|
|
printer.Clean()
|
|
|
|
err := setBusyCmdF(s.th.Client, cmd, nil)
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("MM-T3957 Set server status to busy", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
err := setBusyCmdF(c, cmd, nil)
|
|
s.Require().NoError(err)
|
|
defer func() {
|
|
s.th.App.Srv().Platform().Busy.Clear()
|
|
s.Require().False(s.th.App.Srv().Platform().Busy.IsBusy())
|
|
}()
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Equal(printer.GetLines()[0], map[string]string{"status": "ok"})
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().True(s.th.App.Srv().Platform().Busy.IsBusy())
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestClearBusyCmd() {
|
|
s.SetupEnterpriseTestHelper().InitBasic(s.T())
|
|
|
|
s.th.App.Srv().Platform().Busy.Set(time.Minute)
|
|
defer s.th.App.Srv().Platform().Busy.Clear()
|
|
|
|
s.Run("MM-T3981 Should fail when regular user attempts to clear server busy status", func() {
|
|
printer.Clean()
|
|
|
|
err := clearBusyCmdF(s.th.Client, &cobra.Command{}, nil)
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
})
|
|
|
|
s.RunForSystemAdminAndLocal("MM-T3958 Clear server status to busy", func(c client.Client) {
|
|
printer.Clean()
|
|
|
|
err := clearBusyCmdF(c, &cobra.Command{}, nil)
|
|
s.Require().NoError(err)
|
|
defer func() {
|
|
s.th.App.Srv().Platform().Busy.Set(time.Minute)
|
|
s.Require().True(s.th.App.Srv().Platform().Busy.IsBusy())
|
|
}()
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Equal(printer.GetLines()[0], map[string]string{"status": "ok"})
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().False(s.th.App.Srv().Platform().Busy.IsBusy())
|
|
})
|
|
}
|
|
|
|
func (s *MmctlE2ETestSuite) TestSupportPacketCmdF() {
|
|
s.SetupEnterpriseTestHelper().InitBasic(s.T())
|
|
|
|
printer.SetFormat(printer.FormatPlain)
|
|
s.T().Cleanup(func() { printer.SetFormat(printer.FormatJSON) })
|
|
|
|
s.Run("Download Support Packet with default filename", func() {
|
|
printer.Clean()
|
|
|
|
err := systemSupportPacketCmdF(s.th.SystemAdminClient, SystemSupportPacketCmd, []string{})
|
|
s.Require().NoError(err)
|
|
s.Require().Len(printer.GetLines(), 2)
|
|
s.Require().Equal(printer.GetLines()[0], "Downloading Support Packet")
|
|
s.Require().Contains(printer.GetLines()[1], "Downloaded Support Packet to ")
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
|
|
var found bool
|
|
|
|
entries, err := os.ReadDir(".")
|
|
s.Require().NoError(err)
|
|
for _, e := range entries {
|
|
if strings.HasPrefix(e.Name(), "mm_support_packet_") && strings.HasSuffix(e.Name(), ".zip") {
|
|
b, err := os.ReadFile(e.Name())
|
|
s.NoError(err)
|
|
|
|
s.NotEmpty(b, b)
|
|
|
|
s.T().Cleanup(func() {
|
|
err = os.Remove(e.Name())
|
|
s.Require().NoError(err)
|
|
})
|
|
|
|
found = true
|
|
}
|
|
}
|
|
s.True(found)
|
|
})
|
|
|
|
s.Run("Download Support Packet with custom filename", func() {
|
|
printer.Clean()
|
|
|
|
systemSupportPacketCmd := &cobra.Command{}
|
|
systemSupportPacketCmd.Flags().StringP("output-file", "o", "", "Define the output file name")
|
|
err := systemSupportPacketCmd.ParseFlags([]string{"-o", "foo.zip"})
|
|
s.Require().NoError(err)
|
|
|
|
defer func() {
|
|
s.Require().NoError(os.Remove("foo.zip"))
|
|
}()
|
|
|
|
err = systemSupportPacketCmdF(s.th.SystemAdminClient, systemSupportPacketCmd, []string{})
|
|
s.Require().NoError(err)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Len(printer.GetLines(), 2)
|
|
s.Require().Equal(printer.GetLines()[0], "Downloading Support Packet")
|
|
s.Require().Equal(printer.GetLines()[1], "Downloaded Support Packet to foo.zip")
|
|
|
|
b, err := os.ReadFile("foo.zip")
|
|
s.Require().NoError(err)
|
|
s.NotNil(b, b)
|
|
})
|
|
}
|