2019-11-29 06:59:40 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
2017-03-13 12:49:19 -04:00
|
|
|
|
|
|
|
|
package api4
|
|
|
|
|
|
|
|
|
|
import (
|
2023-06-06 17:29:29 -04:00
|
|
|
"context"
|
2017-03-13 12:49:19 -04:00
|
|
|
"testing"
|
2019-03-08 13:15:28 -05:00
|
|
|
|
2019-11-03 10:13:23 -05:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-01-07 12:12:43 -05:00
|
|
|
|
2023-06-11 01:24:35 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
2017-03-13 12:49:19 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetClusterStatus(t *testing.T) {
|
2025-05-30 07:58:26 -04:00
|
|
|
mainHelper.Parallel(t)
|
2020-07-22 04:20:33 -04:00
|
|
|
th := Setup(t)
|
2017-03-13 12:49:19 -04:00
|
|
|
|
2019-03-08 13:15:28 -05:00
|
|
|
t.Run("as system user", func(t *testing.T) {
|
2023-06-06 17:29:29 -04:00
|
|
|
_, resp, err := th.Client.GetClusterStatus(context.Background())
|
2021-08-13 07:12:16 -04:00
|
|
|
require.Error(t, err)
|
2019-03-08 13:15:28 -05:00
|
|
|
CheckForbiddenStatus(t, resp)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("as system admin", func(t *testing.T) {
|
2023-06-06 17:29:29 -04:00
|
|
|
infos, _, err := th.SystemAdminClient.GetClusterStatus(context.Background())
|
2021-08-13 07:12:16 -04:00
|
|
|
require.NoError(t, err)
|
2019-03-08 13:15:28 -05:00
|
|
|
|
2019-11-03 10:13:23 -05:00
|
|
|
require.NotNil(t, infos, "cluster status should not be nil")
|
2019-03-08 13:15:28 -05:00
|
|
|
})
|
2017-03-13 12:49:19 -04:00
|
|
|
|
2019-03-08 13:15:28 -05:00
|
|
|
t.Run("as restricted system admin", func(t *testing.T) {
|
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
2017-03-13 12:49:19 -04:00
|
|
|
|
2023-06-06 17:29:29 -04:00
|
|
|
_, resp, err := th.SystemAdminClient.GetClusterStatus(context.Background())
|
2021-08-13 07:12:16 -04:00
|
|
|
require.Error(t, err)
|
2019-03-08 13:15:28 -05:00
|
|
|
CheckForbiddenStatus(t, resp)
|
|
|
|
|
})
|
2017-03-13 12:49:19 -04:00
|
|
|
}
|