Files
mattermost/app/enterprise_test.go
Jesús Espino 7fe6c94eda Adding Upgrade to Enterprise version feature (#14539)
* Adding Upgrade to Enterprise version feature

* Addressing PR review comments, and adding some minor improvements

* Add tests file

* Addressing PR comments

* fix linter checks

* Storing and exposing the upgraded from TE info

* Fix showing errors on mac

* A more appropiate status code for not-supported upgrade

* Fixing tests

* Handling permissions errors

* More server logging around upgrade failures

* Apply text changes suggested from code review

Co-authored-by: Eric Sadur <57730300+esadur@users.noreply.github.com>

* Address PR review comments

* Only allow to restart the system after an upgrade

* Verify file signature before upgrade

* Adding limit to the downloaded file

* Simplifying the upgrade binary process with backup in memory

* Fixing backup/restore mechanism for the binary file

* Improve file permissions handling

* Askin the permissions for the right place (the parent directory)

* Fixing tests

* Addressing PR review comments

* Fix license headers

* Fixing retry layer

* Making it work on windows builds

* Adding license header

* Fixing 2 tests

* Fixing tests that need UpgradeFromTE System key mock

* Extracting i18n translation

* Apply suggestions from code review

Co-authored-by: Eric Sadur <57730300+esadur@users.noreply.github.com>

* Improving how the errors are written

* Fixing another error text

* Removing unneeded translation

* Fixing upgrade status strings

* Update i18n/en.json

Co-authored-by: Eric Sadur <57730300+esadur@users.noreply.github.com>

* Fixing tests

Co-authored-by: Eric Sadur <57730300+esadur@users.noreply.github.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-08-21 20:23:04 +02:00

134 lines
3.9 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"testing"
"github.com/mattermost/mattermost-server/v5/einterfaces"
"github.com/mattermost/mattermost-server/v5/einterfaces/mocks"
"github.com/mattermost/mattermost-server/v5/model"
storemocks "github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestSAMLSettings(t *testing.T) {
tt := []struct {
name string
setSAMLInterface bool
setNewInterface bool
useNewSAMLLibrary bool
isNil bool
metadata string
}{
{
name: "No SAML Interfaces, default setting",
setSAMLInterface: false,
setNewInterface: false,
useNewSAMLLibrary: false,
isNil: true,
},
{
name: "No SAML Interfaces, set config true",
setSAMLInterface: false,
setNewInterface: false,
useNewSAMLLibrary: true,
isNil: true,
},
{
name: "Orignal SAML Interface, default setting",
setSAMLInterface: true,
setNewInterface: false,
useNewSAMLLibrary: false,
isNil: false,
metadata: "samlOne",
},
{
name: "Orignal SAML Interface, config true",
setSAMLInterface: true,
setNewInterface: false,
useNewSAMLLibrary: true,
isNil: false,
metadata: "samlOne",
},
{
name: "Both SAML Interfaces, default setting",
setSAMLInterface: true,
setNewInterface: true,
useNewSAMLLibrary: false,
isNil: false,
metadata: "samlOne",
},
{
name: "Both SAML Interfaces, config true",
setSAMLInterface: true,
setNewInterface: true,
useNewSAMLLibrary: true,
isNil: false,
metadata: "samlTwo",
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
saml := &mocks.SamlInterface{}
saml.Mock.On("ConfigureSP").Return(nil)
saml.Mock.On("GetMetadata").Return("samlOne", nil)
if tc.setSAMLInterface {
RegisterSamlInterface(func(a *App) einterfaces.SamlInterface {
return saml
})
} else {
RegisterSamlInterface(nil)
}
saml2 := &mocks.SamlInterface{}
saml2.Mock.On("ConfigureSP").Return(nil)
saml2.Mock.On("GetMetadata").Return("samlTwo", nil)
if tc.setNewInterface {
RegisterNewSamlInterface(func(a *App) einterfaces.SamlInterface {
return saml2
})
} else {
RegisterNewSamlInterface(nil)
}
th := SetupEnterpriseWithStoreMock(t)
defer th.TearDown()
mockStore := th.App.Srv().Store.(*storemocks.Store)
mockUserStore := storemocks.UserStore{}
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
mockPostStore := storemocks.PostStore{}
mockPostStore.On("GetMaxPostSize").Return(65535, nil)
mockSystemStore := storemocks.SystemStore{}
mockSystemStore.On("GetByName", "UpgradedFromTE").Return(&model.System{Name: "UpgradedFromTE", Value: "false"}, nil)
mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil)
mockSystemStore.On("GetByName", "FirstServerRunTimestamp").Return(&model.System{Name: "FirstServerRunTimestamp", Value: "10"}, nil)
mockStore.On("User").Return(&mockUserStore)
mockStore.On("Post").Return(&mockPostStore)
mockStore.On("System").Return(&mockSystemStore)
if tc.useNewSAMLLibrary {
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ExperimentalSettings.UseNewSAMLLibrary = tc.useNewSAMLLibrary
})
}
th.Server.initEnterprise()
th.App.initEnterprise()
if tc.isNil {
assert.Nil(t, th.App.Srv().Saml)
} else {
assert.NotNil(t, th.App.Srv().Saml)
metadata, err := th.App.Srv().Saml.GetMetadata()
assert.Nil(t, err)
assert.Equal(t, tc.metadata, metadata)
}
})
}
}