github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/app/enterprise_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package app 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/mock" 11 12 "github.com/mattermost/mattermost-server/v5/einterfaces" 13 "github.com/mattermost/mattermost-server/v5/einterfaces/mocks" 14 "github.com/mattermost/mattermost-server/v5/model" 15 storemocks "github.com/mattermost/mattermost-server/v5/store/storetest/mocks" 16 ) 17 18 func TestSAMLSettings(t *testing.T) { 19 tt := []struct { 20 name string 21 setNewInterface bool 22 useNewSAMLLibrary bool 23 isNil bool 24 metadata string 25 }{ 26 { 27 name: "No SAML Interfaces, default setting", 28 setNewInterface: false, 29 useNewSAMLLibrary: false, 30 isNil: true, 31 }, 32 { 33 name: "No SAML Interfaces, set config true", 34 setNewInterface: false, 35 useNewSAMLLibrary: true, 36 isNil: true, 37 }, 38 { 39 name: "Both SAML Interfaces, default setting", 40 setNewInterface: true, 41 useNewSAMLLibrary: false, 42 isNil: false, 43 metadata: "samlTwo", 44 }, 45 { 46 name: "Both SAML Interfaces, config true", 47 setNewInterface: true, 48 useNewSAMLLibrary: true, 49 isNil: false, 50 metadata: "samlTwo", 51 }, 52 } 53 54 for _, tc := range tt { 55 t.Run(tc.name, func(t *testing.T) { 56 saml2 := &mocks.SamlInterface{} 57 saml2.Mock.On("ConfigureSP").Return(nil) 58 saml2.Mock.On("GetMetadata").Return("samlTwo", nil) 59 if tc.setNewInterface { 60 RegisterNewSamlInterface(func(a *App) einterfaces.SamlInterface { 61 return saml2 62 }) 63 } else { 64 RegisterNewSamlInterface(nil) 65 } 66 67 th := SetupEnterpriseWithStoreMock(t) 68 defer th.TearDown() 69 70 mockStore := th.App.Srv().Store.(*storemocks.Store) 71 mockUserStore := storemocks.UserStore{} 72 mockUserStore.On("Count", mock.Anything).Return(int64(10), nil) 73 mockPostStore := storemocks.PostStore{} 74 mockPostStore.On("GetMaxPostSize").Return(65535, nil) 75 mockSystemStore := storemocks.SystemStore{} 76 mockSystemStore.On("GetByName", "UpgradedFromTE").Return(&model.System{Name: "UpgradedFromTE", Value: "false"}, nil) 77 mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil) 78 mockSystemStore.On("GetByName", "FirstServerRunTimestamp").Return(&model.System{Name: "FirstServerRunTimestamp", Value: "10"}, nil) 79 80 mockStore.On("User").Return(&mockUserStore) 81 mockStore.On("Post").Return(&mockPostStore) 82 mockStore.On("System").Return(&mockSystemStore) 83 84 if tc.useNewSAMLLibrary { 85 th.App.UpdateConfig(func(cfg *model.Config) { 86 *cfg.ExperimentalSettings.UseNewSAMLLibrary = tc.useNewSAMLLibrary 87 }) 88 } 89 90 th.Server.initEnterprise() 91 th.App.initEnterprise() 92 if tc.isNil { 93 assert.Nil(t, th.App.Srv().Saml) 94 } else { 95 assert.NotNil(t, th.App.Srv().Saml) 96 metadata, err := th.App.Srv().Saml.GetMetadata() 97 assert.Nil(t, err) 98 assert.Equal(t, tc.metadata, metadata) 99 } 100 }) 101 } 102 }