MM-21976: Include cache layer to be tested (#13749)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c9a0418a32
Коммит
b162cf92cd
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
"github.com/mattermost/mattermost-server/v5/store"
|
"github.com/mattermost/mattermost-server/v5/store"
|
||||||
|
"github.com/mattermost/mattermost-server/v5/store/localcachelayer"
|
||||||
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
||||||
"github.com/mattermost/mattermost-server/v5/testlib"
|
"github.com/mattermost/mattermost-server/v5/testlib"
|
||||||
"github.com/mattermost/mattermost-server/v5/utils"
|
"github.com/mattermost/mattermost-server/v5/utils"
|
||||||
@@ -52,11 +53,13 @@ type TestHelper struct {
|
|||||||
SystemAdminClient *model.Client4
|
SystemAdminClient *model.Client4
|
||||||
SystemAdminUser *model.User
|
SystemAdminUser *model.User
|
||||||
tempWorkspace string
|
tempWorkspace string
|
||||||
|
|
||||||
|
IncludeCacheLayer bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var mainHelper *testlib.MainHelper
|
var mainHelper *testlib.MainHelper
|
||||||
|
|
||||||
func setupTestHelper(dbStore store.Store, enterprise bool, updateConfig func(*model.Config)) *TestHelper {
|
func setupTestHelper(dbStore store.Store, enterprise bool, includeCache bool, updateConfig func(*model.Config)) *TestHelper {
|
||||||
tempWorkspace, err := ioutil.TempDir("", "apptest")
|
tempWorkspace, err := ioutil.TempDir("", "apptest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -83,11 +86,16 @@ func setupTestHelper(dbStore store.Store, enterprise bool, updateConfig func(*mo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
if includeCache {
|
||||||
|
// Adds the cache layer to the test store
|
||||||
|
s.Store = localcachelayer.NewLocalCacheLayer(s.Store, s.Metrics, s.Cluster, s.CacheProvider)
|
||||||
|
}
|
||||||
|
|
||||||
th := &TestHelper{
|
th := &TestHelper{
|
||||||
App: s.FakeApp(),
|
App: s.FakeApp(),
|
||||||
Server: s,
|
Server: s,
|
||||||
ConfigStore: memoryStore,
|
ConfigStore: memoryStore,
|
||||||
|
IncludeCacheLayer: includeCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
@@ -151,7 +159,7 @@ func SetupEnterprise(tb testing.TB) *TestHelper {
|
|||||||
dbStore := mainHelper.GetStore()
|
dbStore := mainHelper.GetStore()
|
||||||
dbStore.DropAllTables()
|
dbStore.DropAllTables()
|
||||||
dbStore.MarkSystemRanUnitTests()
|
dbStore.MarkSystemRanUnitTests()
|
||||||
return setupTestHelper(dbStore, true, nil)
|
return setupTestHelper(dbStore, true, true, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(tb testing.TB) *TestHelper {
|
func Setup(tb testing.TB) *TestHelper {
|
||||||
@@ -166,7 +174,7 @@ func Setup(tb testing.TB) *TestHelper {
|
|||||||
dbStore := mainHelper.GetStore()
|
dbStore := mainHelper.GetStore()
|
||||||
dbStore.DropAllTables()
|
dbStore.DropAllTables()
|
||||||
dbStore.MarkSystemRanUnitTests()
|
dbStore.MarkSystemRanUnitTests()
|
||||||
return setupTestHelper(dbStore, false, nil)
|
return setupTestHelper(dbStore, false, true, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper {
|
func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper {
|
||||||
@@ -181,11 +189,11 @@ func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelpe
|
|||||||
dbStore := mainHelper.GetStore()
|
dbStore := mainHelper.GetStore()
|
||||||
dbStore.DropAllTables()
|
dbStore.DropAllTables()
|
||||||
dbStore.MarkSystemRanUnitTests()
|
dbStore.MarkSystemRanUnitTests()
|
||||||
return setupTestHelper(dbStore, false, updateConfig)
|
return setupTestHelper(dbStore, false, true, updateConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper {
|
func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper {
|
||||||
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), false, updateConfig)
|
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), false, false, updateConfig)
|
||||||
emptyMockStore := mocks.Store{}
|
emptyMockStore := mocks.Store{}
|
||||||
emptyMockStore.On("Close").Return(nil)
|
emptyMockStore.On("Close").Return(nil)
|
||||||
th.App.Srv().Store = &emptyMockStore
|
th.App.Srv().Store = &emptyMockStore
|
||||||
@@ -193,7 +201,7 @@ func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
||||||
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), false, nil)
|
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), false, false, nil)
|
||||||
emptyMockStore := mocks.Store{}
|
emptyMockStore := mocks.Store{}
|
||||||
emptyMockStore.On("Close").Return(nil)
|
emptyMockStore.On("Close").Return(nil)
|
||||||
th.App.Srv().Store = &emptyMockStore
|
th.App.Srv().Store = &emptyMockStore
|
||||||
@@ -201,7 +209,7 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
|
func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
|
||||||
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), true, nil)
|
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), true, false, nil)
|
||||||
emptyMockStore := mocks.Store{}
|
emptyMockStore := mocks.Store{}
|
||||||
emptyMockStore.On("Close").Return(nil)
|
emptyMockStore.On("Close").Return(nil)
|
||||||
th.App.Srv().Store = &emptyMockStore
|
th.App.Srv().Store = &emptyMockStore
|
||||||
@@ -226,6 +234,10 @@ func (me *TestHelper) ShutdownApp() {
|
|||||||
|
|
||||||
func (me *TestHelper) TearDown() {
|
func (me *TestHelper) TearDown() {
|
||||||
utils.DisableDebugLogForTest()
|
utils.DisableDebugLogForTest()
|
||||||
|
if me.IncludeCacheLayer {
|
||||||
|
// Clean all the caches
|
||||||
|
me.App.InvalidateAllCaches()
|
||||||
|
}
|
||||||
|
|
||||||
me.ShutdownApp()
|
me.ShutdownApp()
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/app"
|
"github.com/mattermost/mattermost-server/v5/app"
|
||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
"github.com/mattermost/mattermost-server/v5/services/mailservice"
|
"github.com/mattermost/mattermost-server/v5/services/mailservice"
|
||||||
"github.com/mattermost/mattermost-server/v5/store/localcachelayer"
|
|
||||||
"github.com/mattermost/mattermost-server/v5/utils/testutils"
|
"github.com/mattermost/mattermost-server/v5/utils/testutils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -4365,8 +4364,6 @@ func TestLoginLockout(t *testing.T) {
|
|||||||
func TestDemoteUserToGuest(t *testing.T) {
|
func TestDemoteUserToGuest(t *testing.T) {
|
||||||
t.Run("websocket update user event", func(t *testing.T) {
|
t.Run("websocket update user event", func(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
th.Server.Store = localcachelayer.NewLocalCacheLayer(th.Server.Store,
|
|
||||||
th.Server.Metrics, th.Server.Cluster, th.Server.CacheProvider)
|
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
user := th.BasicUser
|
user := th.BasicUser
|
||||||
@@ -4413,15 +4410,12 @@ func TestDemoteUserToGuest(t *testing.T) {
|
|||||||
require.True(t, ok, "expected user")
|
require.True(t, ok, "expected user")
|
||||||
assert.Equal(t, "system_guest", eventUser.Roles)
|
assert.Equal(t, "system_guest", eventUser.Roles)
|
||||||
})
|
})
|
||||||
th.App.InvalidateAllCaches()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPromoteGuestToUser(t *testing.T) {
|
func TestPromoteGuestToUser(t *testing.T) {
|
||||||
t.Run("websocket update user event", func(t *testing.T) {
|
t.Run("websocket update user event", func(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
th.Server.Store = localcachelayer.NewLocalCacheLayer(th.Server.Store,
|
|
||||||
th.Server.Metrics, th.Server.Cluster, th.Server.CacheProvider)
|
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
user := th.BasicUser
|
user := th.BasicUser
|
||||||
@@ -4469,6 +4463,5 @@ func TestPromoteGuestToUser(t *testing.T) {
|
|||||||
require.True(t, ok, "expected user")
|
require.True(t, ok, "expected user")
|
||||||
assert.Equal(t, "system_user", eventUser.Roles)
|
assert.Equal(t, "system_user", eventUser.Roles)
|
||||||
})
|
})
|
||||||
th.App.InvalidateAllCaches()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa
|
|||||||
if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||||
return passErr
|
return passErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.InvalidateCacheForUser(user.Id)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +68,9 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa
|
|||||||
return passErr
|
return passErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.InvalidateCacheForUser(user.Id)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +78,8 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa
|
|||||||
return passErr
|
return passErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.InvalidateCacheForUser(user.Id)
|
||||||
|
|
||||||
if err := a.CheckUserPostflightAuthenticationCriteria(user); err != nil {
|
if err := a.CheckUserPostflightAuthenticationCriteria(user); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -89,6 +97,9 @@ func (a *App) DoubleCheckPassword(user *model.User, password string) *model.AppE
|
|||||||
if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||||
return passErr
|
return passErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.InvalidateCacheForUser(user.Id)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +107,8 @@ func (a *App) DoubleCheckPassword(user *model.User, password string) *model.AppE
|
|||||||
return passErr
|
return passErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.InvalidateCacheForUser(user.Id)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
|
"github.com/mattermost/mattermost-server/v5/store/localcachelayer"
|
||||||
"github.com/mattermost/mattermost-server/v5/store/sqlstore"
|
"github.com/mattermost/mattermost-server/v5/store/sqlstore"
|
||||||
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
||||||
"github.com/mattermost/mattermost-server/v5/utils"
|
"github.com/mattermost/mattermost-server/v5/utils"
|
||||||
@@ -125,7 +126,7 @@ func TestEnsureInstallationDate(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range tt {
|
for _, tc := range tt {
|
||||||
t.Run(tc.Name, func(t *testing.T) {
|
t.Run(tc.Name, func(t *testing.T) {
|
||||||
sqlStore := th.App.Srv().Store.User().(*sqlstore.SqlUserStore)
|
sqlStore := th.App.Srv().Store.User().(localcachelayer.LocalCacheUserStore).UserStore.(*sqlstore.SqlUserStore)
|
||||||
sqlStore.GetMaster().Exec("DELETE FROM Users")
|
sqlStore.GetMaster().Exec("DELETE FROM Users")
|
||||||
|
|
||||||
for _, createAt := range tc.UsersCreationDates {
|
for _, createAt := range tc.UsersCreationDates {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
"github.com/mattermost/mattermost-server/v5/store"
|
"github.com/mattermost/mattermost-server/v5/store"
|
||||||
|
"github.com/mattermost/mattermost-server/v5/store/localcachelayer"
|
||||||
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
||||||
"github.com/mattermost/mattermost-server/v5/testlib"
|
"github.com/mattermost/mattermost-server/v5/testlib"
|
||||||
"github.com/mattermost/mattermost-server/v5/utils"
|
"github.com/mattermost/mattermost-server/v5/utils"
|
||||||
@@ -35,9 +36,11 @@ type TestHelper struct {
|
|||||||
SystemAdminUser *model.User
|
SystemAdminUser *model.User
|
||||||
|
|
||||||
tempWorkspace string
|
tempWorkspace string
|
||||||
|
|
||||||
|
IncludeCacheLayer bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupTestHelper(dbStore store.Store, enterprise bool, tb testing.TB, configSet func(*model.Config)) *TestHelper {
|
func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer bool, tb testing.TB, configSet func(*model.Config)) *TestHelper {
|
||||||
tempWorkspace, err := ioutil.TempDir("", "apptest")
|
tempWorkspace, err := ioutil.TempDir("", "apptest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -66,9 +69,15 @@ func setupTestHelper(dbStore store.Store, enterprise bool, tb testing.TB, config
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if includeCacheLayer {
|
||||||
|
// Adds the cache layer to the test store
|
||||||
|
s.Store = localcachelayer.NewLocalCacheLayer(s.Store, s.Metrics, s.Cluster, s.CacheProvider)
|
||||||
|
}
|
||||||
|
|
||||||
th := &TestHelper{
|
th := &TestHelper{
|
||||||
App: s.FakeApp(),
|
App: s.FakeApp(),
|
||||||
Server: s,
|
Server: s,
|
||||||
|
IncludeCacheLayer: includeCacheLayer,
|
||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
|
||||||
@@ -113,7 +122,7 @@ func SetupEnterprise(tb testing.TB) *TestHelper {
|
|||||||
dbStore.DropAllTables()
|
dbStore.DropAllTables()
|
||||||
dbStore.MarkSystemRanUnitTests()
|
dbStore.MarkSystemRanUnitTests()
|
||||||
|
|
||||||
return setupTestHelper(dbStore, true, tb, nil)
|
return setupTestHelper(dbStore, true, true, tb, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(tb testing.TB) *TestHelper {
|
func Setup(tb testing.TB) *TestHelper {
|
||||||
@@ -124,12 +133,12 @@ func Setup(tb testing.TB) *TestHelper {
|
|||||||
dbStore.DropAllTables()
|
dbStore.DropAllTables()
|
||||||
dbStore.MarkSystemRanUnitTests()
|
dbStore.MarkSystemRanUnitTests()
|
||||||
|
|
||||||
return setupTestHelper(dbStore, false, tb, nil)
|
return setupTestHelper(dbStore, false, true, tb, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
||||||
mockStore := testlib.GetMockStoreForSetupFunctions()
|
mockStore := testlib.GetMockStoreForSetupFunctions()
|
||||||
th := setupTestHelper(mockStore, false, tb, nil)
|
th := setupTestHelper(mockStore, false, false, tb, nil)
|
||||||
emptyMockStore := mocks.Store{}
|
emptyMockStore := mocks.Store{}
|
||||||
emptyMockStore.On("Close").Return(nil)
|
emptyMockStore.On("Close").Return(nil)
|
||||||
th.App.Srv().Store = &emptyMockStore
|
th.App.Srv().Store = &emptyMockStore
|
||||||
@@ -138,7 +147,7 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
|||||||
|
|
||||||
func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
|
func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
|
||||||
mockStore := testlib.GetMockStoreForSetupFunctions()
|
mockStore := testlib.GetMockStoreForSetupFunctions()
|
||||||
th := setupTestHelper(mockStore, true, tb, nil)
|
th := setupTestHelper(mockStore, true, false, tb, nil)
|
||||||
emptyMockStore := mocks.Store{}
|
emptyMockStore := mocks.Store{}
|
||||||
emptyMockStore.On("Close").Return(nil)
|
emptyMockStore.On("Close").Return(nil)
|
||||||
th.App.Srv().Store = &emptyMockStore
|
th.App.Srv().Store = &emptyMockStore
|
||||||
@@ -153,7 +162,7 @@ func SetupWithCustomConfig(tb testing.TB, configSet func(*model.Config)) *TestHe
|
|||||||
dbStore.DropAllTables()
|
dbStore.DropAllTables()
|
||||||
dbStore.MarkSystemRanUnitTests()
|
dbStore.MarkSystemRanUnitTests()
|
||||||
|
|
||||||
return setupTestHelper(dbStore, false, tb, configSet)
|
return setupTestHelper(dbStore, false, true, tb, configSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
var initBasicOnce sync.Once
|
var initBasicOnce sync.Once
|
||||||
@@ -543,6 +552,10 @@ func (me *TestHelper) ShutdownApp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *TestHelper) TearDown() {
|
func (me *TestHelper) TearDown() {
|
||||||
|
if me.IncludeCacheLayer {
|
||||||
|
// Clean all the caches
|
||||||
|
me.App.InvalidateAllCaches()
|
||||||
|
}
|
||||||
me.ShutdownApp()
|
me.ShutdownApp()
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -298,6 +298,7 @@ func TestAddUserToTeamByToken(t *testing.T) {
|
|||||||
guestEmail := rguest.Email
|
guestEmail := rguest.Email
|
||||||
rguest.Email = "test@restricted.com"
|
rguest.Email = "test@restricted.com"
|
||||||
_, err := th.App.Srv().Store.User().Update(rguest, false)
|
_, err := th.App.Srv().Store.User().Update(rguest, false)
|
||||||
|
th.App.InvalidateCacheForUser(rguest.Id)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||||
_, err = th.App.AddUserToTeamByToken(rguest.Id, token.Token)
|
_, err = th.App.AddUserToTeamByToken(rguest.Id, token.Token)
|
||||||
|
|||||||
@@ -1279,6 +1279,8 @@ func (a *App) UpdatePassword(user *model.User, newPassword string) *model.AppErr
|
|||||||
return model.NewAppError("UpdatePassword", "api.user.update_password.failed.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("UpdatePassword", "api.user.update_password.failed.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.InvalidateCacheForUser(user.Id)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1681,11 +1683,12 @@ func (a *App) GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) VerifyUserEmail(userId, email string) *model.AppError {
|
func (a *App) VerifyUserEmail(userId, email string) *model.AppError {
|
||||||
_, err := a.Srv().Store.User().VerifyEmail(userId, email)
|
if _, err := a.Srv().Store.User().VerifyEmail(userId, email); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.InvalidateCacheForUser(userId)
|
||||||
|
|
||||||
user, err := a.GetUser(userId)
|
user, err := a.GetUser(userId)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/config"
|
"github.com/mattermost/mattermost-server/v5/config"
|
||||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
|
"github.com/mattermost/mattermost-server/v5/store/localcachelayer"
|
||||||
"github.com/mattermost/mattermost-server/v5/utils"
|
"github.com/mattermost/mattermost-server/v5/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,6 +46,8 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
// Adds the cache layer to the test store
|
||||||
|
s.Store = localcachelayer.NewLocalCacheLayer(s.Store, s.Metrics, s.Cluster, s.CacheProvider)
|
||||||
|
|
||||||
th := &TestHelper{
|
th := &TestHelper{
|
||||||
App: s.FakeApp(),
|
App: s.FakeApp(),
|
||||||
@@ -244,6 +247,8 @@ func (me *TestHelper) AddUserToChannel(user *model.User, channel *model.Channel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (me *TestHelper) TearDown() {
|
func (me *TestHelper) TearDown() {
|
||||||
|
// Clean all the caches
|
||||||
|
me.App.InvalidateAllCaches()
|
||||||
me.Server.Shutdown()
|
me.Server.Shutdown()
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
"github.com/mattermost/mattermost-server/v5/plugin"
|
"github.com/mattermost/mattermost-server/v5/plugin"
|
||||||
"github.com/mattermost/mattermost-server/v5/store"
|
"github.com/mattermost/mattermost-server/v5/store"
|
||||||
|
"github.com/mattermost/mattermost-server/v5/store/localcachelayer"
|
||||||
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
|
||||||
"github.com/mattermost/mattermost-server/v5/testlib"
|
"github.com/mattermost/mattermost-server/v5/testlib"
|
||||||
"github.com/mattermost/mattermost-server/v5/utils"
|
"github.com/mattermost/mattermost-server/v5/utils"
|
||||||
@@ -40,6 +41,8 @@ type TestHelper struct {
|
|||||||
SystemAdminUser *model.User
|
SystemAdminUser *model.User
|
||||||
|
|
||||||
tempWorkspace string
|
tempWorkspace string
|
||||||
|
|
||||||
|
IncludeCacheLayer bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
||||||
@@ -47,7 +50,7 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper {
|
|||||||
tb.SkipNow()
|
tb.SkipNow()
|
||||||
}
|
}
|
||||||
store := testlib.GetMockStoreForSetupFunctions()
|
store := testlib.GetMockStoreForSetupFunctions()
|
||||||
th := setupTestHelper(tb, store)
|
th := setupTestHelper(tb, store, false)
|
||||||
emptyMockStore := mocks.Store{}
|
emptyMockStore := mocks.Store{}
|
||||||
emptyMockStore.On("Close").Return(nil)
|
emptyMockStore.On("Close").Return(nil)
|
||||||
th.App.Srv().Store = &emptyMockStore
|
th.App.Srv().Store = &emptyMockStore
|
||||||
@@ -60,10 +63,10 @@ func Setup(tb testing.TB) *TestHelper {
|
|||||||
}
|
}
|
||||||
store := mainHelper.GetStore()
|
store := mainHelper.GetStore()
|
||||||
store.DropAllTables()
|
store.DropAllTables()
|
||||||
return setupTestHelper(tb, store)
|
return setupTestHelper(tb, store, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupTestHelper(t testing.TB, store store.Store) *TestHelper {
|
func setupTestHelper(t testing.TB, store store.Store, includeCacheLayer bool) *TestHelper {
|
||||||
memoryStore, err := config.NewMemoryStoreWithOptions(&config.MemoryStoreOptions{IgnoreEnvironmentOverrides: true})
|
memoryStore, err := config.NewMemoryStoreWithOptions(&config.MemoryStoreOptions{IgnoreEnvironmentOverrides: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("failed to initialize memory store: " + err.Error())
|
panic("failed to initialize memory store: " + err.Error())
|
||||||
@@ -77,6 +80,11 @@ func setupTestHelper(t testing.TB, store store.Store) *TestHelper {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
if includeCacheLayer {
|
||||||
|
// Adds the cache layer to the test store
|
||||||
|
s.Store = localcachelayer.NewLocalCacheLayer(s.Store, s.Metrics, s.Cluster, s.CacheProvider)
|
||||||
|
}
|
||||||
|
|
||||||
a := s.FakeApp()
|
a := s.FakeApp()
|
||||||
prevListenAddress := *a.Config().ServiceSettings.ListenAddress
|
prevListenAddress := *a.Config().ServiceSettings.ListenAddress
|
||||||
a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
|
a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
|
||||||
@@ -108,9 +116,10 @@ func setupTestHelper(t testing.TB, store store.Store) *TestHelper {
|
|||||||
})
|
})
|
||||||
|
|
||||||
th := &TestHelper{
|
th := &TestHelper{
|
||||||
App: a,
|
App: a,
|
||||||
Server: s,
|
Server: s,
|
||||||
Web: web,
|
Web: web,
|
||||||
|
IncludeCacheLayer: includeCacheLayer,
|
||||||
}
|
}
|
||||||
|
|
||||||
return th
|
return th
|
||||||
@@ -144,6 +153,10 @@ func (th *TestHelper) InitBasic() *TestHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (th *TestHelper) TearDown() {
|
func (th *TestHelper) TearDown() {
|
||||||
|
if th.IncludeCacheLayer {
|
||||||
|
// Clean all the caches
|
||||||
|
th.App.InvalidateAllCaches()
|
||||||
|
}
|
||||||
th.Server.Shutdown()
|
th.Server.Shutdown()
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user