github.com/mad-app/mattermost-server@v5.11.1+incompatible/api4/elasticsearch_test.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package api4
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/mattermost/mattermost-server/model"
    10  )
    11  
    12  func TestElasticsearchTest(t *testing.T) {
    13  	th := Setup().InitBasic()
    14  	defer th.TearDown()
    15  
    16  	t.Run("as system user", func(t *testing.T) {
    17  		_, resp := th.Client.TestElasticsearch()
    18  		CheckForbiddenStatus(t, resp)
    19  	})
    20  
    21  	t.Run("as system admin", func(t *testing.T) {
    22  		_, resp := th.SystemAdminClient.TestElasticsearch()
    23  		CheckNotImplementedStatus(t, resp)
    24  	})
    25  
    26  	t.Run("as restricted system admin", func(t *testing.T) {
    27  		th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
    28  
    29  		_, resp := th.SystemAdminClient.TestElasticsearch()
    30  		CheckForbiddenStatus(t, resp)
    31  	})
    32  }
    33  
    34  func TestElasticsearchPurgeIndexes(t *testing.T) {
    35  	th := Setup().InitBasic()
    36  	defer th.TearDown()
    37  
    38  	t.Run("as system user", func(t *testing.T) {
    39  		_, resp := th.Client.PurgeElasticsearchIndexes()
    40  		CheckForbiddenStatus(t, resp)
    41  	})
    42  
    43  	t.Run("as system admin", func(t *testing.T) {
    44  		_, resp := th.SystemAdminClient.PurgeElasticsearchIndexes()
    45  		CheckNotImplementedStatus(t, resp)
    46  	})
    47  
    48  	t.Run("as restricted system admin", func(t *testing.T) {
    49  		th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
    50  
    51  		_, resp := th.SystemAdminClient.PurgeElasticsearchIndexes()
    52  		CheckForbiddenStatus(t, resp)
    53  	})
    54  }