Remove global app references (#7433)
* remove global app references * test fix * fix api4 test compilation
Этот коммит содержится в:
15
api/api.go
15
api/api.go
@@ -59,15 +59,16 @@ type Routes struct {
|
||||
|
||||
var BaseRoutes *Routes
|
||||
|
||||
func InitRouter() {
|
||||
app.Global().Srv.Router = mux.NewRouter()
|
||||
app.Global().Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404)
|
||||
func NewRouter() *mux.Router {
|
||||
ret := mux.NewRouter()
|
||||
ret.NotFoundHandler = http.HandlerFunc(Handle404)
|
||||
return ret
|
||||
}
|
||||
|
||||
func InitApi() {
|
||||
func InitApi(root *mux.Router) {
|
||||
BaseRoutes = &Routes{}
|
||||
BaseRoutes.Root = app.Global().Srv.Router
|
||||
BaseRoutes.ApiRoot = app.Global().Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter()
|
||||
BaseRoutes.Root = root
|
||||
BaseRoutes.ApiRoot = root.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter()
|
||||
BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter()
|
||||
BaseRoutes.NeedUser = BaseRoutes.Users.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter()
|
||||
BaseRoutes.Teams = BaseRoutes.ApiRoot.PathPrefix("/teams").Subrouter()
|
||||
@@ -111,7 +112,7 @@ func InitApi() {
|
||||
InitDeprecated()
|
||||
|
||||
// 404 on any api route before web.go has a chance to serve it
|
||||
app.Global().Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404))
|
||||
root.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404))
|
||||
|
||||
utils.InitHTML()
|
||||
|
||||
|
||||
@@ -33,35 +33,12 @@ type TestHelper struct {
|
||||
SystemAdminChannel *model.Channel
|
||||
}
|
||||
|
||||
func SetupEnterprise() *TestHelper {
|
||||
if app.Global().Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.DisableDebugLogForTest()
|
||||
utils.License().Features.SetDefaults()
|
||||
app.Global().NewServer()
|
||||
app.Global().InitStores()
|
||||
InitRouter()
|
||||
wsapi.InitRouter()
|
||||
app.Global().StartServer()
|
||||
utils.InitHTML()
|
||||
api4.InitApi(false)
|
||||
InitApi()
|
||||
wsapi.InitApi()
|
||||
utils.EnableDebugLogForTest()
|
||||
app.Global().Srv.Store.MarkSystemRanUnitTests()
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
func setupTestHelper(enterprise bool) *TestHelper {
|
||||
th := &TestHelper{
|
||||
App: app.Global(),
|
||||
}
|
||||
|
||||
return &TestHelper{}
|
||||
}
|
||||
|
||||
func Setup() *TestHelper {
|
||||
if app.Global().Srv == nil {
|
||||
if th.App.Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
@@ -69,21 +46,32 @@ func Setup() *TestHelper {
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.Cfg.EmailSettings.SendEmailNotifications = true
|
||||
utils.DisableDebugLogForTest()
|
||||
app.Global().NewServer()
|
||||
app.Global().InitStores()
|
||||
InitRouter()
|
||||
if enterprise {
|
||||
utils.License().Features.SetDefaults()
|
||||
}
|
||||
th.App.NewServer()
|
||||
th.App.InitStores()
|
||||
th.App.Srv.Router = NewRouter()
|
||||
wsapi.InitRouter()
|
||||
app.Global().StartServer()
|
||||
api4.InitApi(false)
|
||||
InitApi()
|
||||
th.App.StartServer()
|
||||
api4.InitApi(th.App.Srv.Router, false)
|
||||
InitApi(th.App.Srv.Router)
|
||||
wsapi.InitApi()
|
||||
utils.EnableDebugLogForTest()
|
||||
app.Global().Srv.Store.MarkSystemRanUnitTests()
|
||||
th.App.Srv.Store.MarkSystemRanUnitTests()
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
|
||||
return &TestHelper{}
|
||||
return th
|
||||
}
|
||||
|
||||
func SetupEnterprise() *TestHelper {
|
||||
return setupTestHelper(true)
|
||||
}
|
||||
|
||||
func Setup() *TestHelper {
|
||||
return setupTestHelper(false)
|
||||
}
|
||||
|
||||
func ReloadConfigForSetup() {
|
||||
@@ -96,7 +84,6 @@ func ReloadConfigForSetup() {
|
||||
}
|
||||
|
||||
func (me *TestHelper) InitBasic() *TestHelper {
|
||||
me.App = app.Global()
|
||||
me.BasicClient = me.CreateClient()
|
||||
me.BasicUser = me.CreateUser(me.BasicClient)
|
||||
me.LoginBasic()
|
||||
@@ -116,7 +103,6 @@ func (me *TestHelper) InitBasic() *TestHelper {
|
||||
}
|
||||
|
||||
func (me *TestHelper) InitSystemAdmin() *TestHelper {
|
||||
me.App = app.Global()
|
||||
me.SystemAdminClient = me.CreateClient()
|
||||
me.SystemAdminUser = me.CreateUser(me.SystemAdminClient)
|
||||
me.SystemAdminUser.Password = "Password1"
|
||||
@@ -166,7 +152,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
|
||||
utils.DisableDebugLogForTest()
|
||||
ruser := client.Must(client.CreateUser(user, "")).Data.(*model.User)
|
||||
ruser.Password = "Password1"
|
||||
store.Must(app.Global().Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
store.Must(me.App.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
utils.EnableDebugLogForTest()
|
||||
return ruser
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
}()
|
||||
*utils.Cfg.ServiceSettings.EnableCustomEmoji = false
|
||||
|
||||
emoji1 := createTestEmoji(t, &model.Emoji{
|
||||
emoji1 := createTestEmoji(t, th.App, &model.Emoji{
|
||||
CreatorId: th.BasicUser.Id,
|
||||
Name: model.NewId(),
|
||||
}, utils.CreateTestGif(t, 10, 10))
|
||||
@@ -247,7 +247,7 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
t.Fatal("shouldn't be able to delete an already-deleted emoji")
|
||||
}
|
||||
|
||||
emoji2 := createTestEmoji(t, &model.Emoji{
|
||||
emoji2 := createTestEmoji(t, th.App, &model.Emoji{
|
||||
CreatorId: th.BasicUser2.Id,
|
||||
Name: model.NewId(),
|
||||
}, utils.CreateTestGif(t, 10, 10))
|
||||
@@ -263,11 +263,11 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func createTestEmoji(t *testing.T, emoji *model.Emoji, imageData []byte) *model.Emoji {
|
||||
emoji = store.Must(app.Global().Srv.Store.Emoji().Save(emoji)).(*model.Emoji)
|
||||
func createTestEmoji(t *testing.T, a *app.App, emoji *model.Emoji, imageData []byte) *model.Emoji {
|
||||
emoji = store.Must(a.Srv.Store.Emoji().Save(emoji)).(*model.Emoji)
|
||||
|
||||
if err := utils.WriteFile(imageData, "emoji/"+emoji.Id+"/image"); err != nil {
|
||||
store.Must(app.Global().Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix()))
|
||||
store.Must(a.Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix()))
|
||||
t.Fatalf("failed to write image: %v", err.Error())
|
||||
}
|
||||
|
||||
|
||||
15
api4/api.go
15
api4/api.go
@@ -105,15 +105,16 @@ type Routes struct {
|
||||
|
||||
var BaseRoutes *Routes
|
||||
|
||||
func InitRouter() {
|
||||
app.Global().Srv.Router = mux.NewRouter()
|
||||
app.Global().Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404)
|
||||
func NewRouter() *mux.Router {
|
||||
ret := mux.NewRouter()
|
||||
ret.NotFoundHandler = http.HandlerFunc(Handle404)
|
||||
return ret
|
||||
}
|
||||
|
||||
func InitApi(full bool) {
|
||||
func InitApi(root *mux.Router, full bool) {
|
||||
BaseRoutes = &Routes{}
|
||||
BaseRoutes.Root = app.Global().Srv.Router
|
||||
BaseRoutes.ApiRoot = app.Global().Srv.Router.PathPrefix(model.API_URL_SUFFIX).Subrouter()
|
||||
BaseRoutes.Root = root
|
||||
BaseRoutes.ApiRoot = root.PathPrefix(model.API_URL_SUFFIX).Subrouter()
|
||||
|
||||
BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter()
|
||||
BaseRoutes.User = BaseRoutes.ApiRoot.PathPrefix("/users/{user_id:[A-Za-z0-9]+}").Subrouter()
|
||||
@@ -213,7 +214,7 @@ func InitApi(full bool) {
|
||||
InitOpenGraph()
|
||||
InitPlugin()
|
||||
|
||||
app.Global().Srv.Router.Handle("/api/v4/{anything:.*}", http.HandlerFunc(Handle404))
|
||||
root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(Handle404))
|
||||
|
||||
// REMOVE CONDITION WHEN APIv3 REMOVED
|
||||
if full {
|
||||
|
||||
@@ -45,8 +45,12 @@ type TestHelper struct {
|
||||
SystemAdminUser *model.User
|
||||
}
|
||||
|
||||
func SetupEnterprise() *TestHelper {
|
||||
if app.Global().Srv == nil {
|
||||
func setupTestHelper(enterprise bool) *TestHelper {
|
||||
th := &TestHelper{
|
||||
App: app.Global(),
|
||||
}
|
||||
|
||||
if th.App.Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
@@ -54,63 +58,37 @@ func SetupEnterprise() *TestHelper {
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.Cfg.EmailSettings.SendEmailNotifications = true
|
||||
utils.DisableDebugLogForTest()
|
||||
utils.License().Features.SetDefaults()
|
||||
app.Global().NewServer()
|
||||
app.Global().InitStores()
|
||||
InitRouter()
|
||||
if enterprise {
|
||||
utils.License().Features.SetDefaults()
|
||||
}
|
||||
th.App.NewServer()
|
||||
th.App.InitStores()
|
||||
th.App.Srv.Router = NewRouter()
|
||||
wsapi.InitRouter()
|
||||
app.Global().StartServer()
|
||||
utils.InitHTML()
|
||||
InitApi(true)
|
||||
th.App.StartServer()
|
||||
InitApi(th.App.Srv.Router, true)
|
||||
wsapi.InitApi()
|
||||
utils.EnableDebugLogForTest()
|
||||
app.Global().Srv.Store.MarkSystemRanUnitTests()
|
||||
th.App.Srv.Store.MarkSystemRanUnitTests()
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
|
||||
if jobs.Srv.Store == nil {
|
||||
jobs.Srv.Store = app.Global().Srv.Store
|
||||
jobs.Srv.Store = th.App.Srv.Store
|
||||
}
|
||||
|
||||
th := &TestHelper{}
|
||||
th.App = app.Global()
|
||||
th.Client = th.CreateClient()
|
||||
th.SystemAdminClient = th.CreateClient()
|
||||
return th
|
||||
}
|
||||
|
||||
func SetupEnterprise() *TestHelper {
|
||||
return setupTestHelper(true)
|
||||
}
|
||||
|
||||
func Setup() *TestHelper {
|
||||
if app.Global().Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.Cfg.EmailSettings.SendEmailNotifications = true
|
||||
utils.DisableDebugLogForTest()
|
||||
app.Global().NewServer()
|
||||
app.Global().InitStores()
|
||||
InitRouter()
|
||||
wsapi.InitRouter()
|
||||
app.Global().StartServer()
|
||||
InitApi(true)
|
||||
wsapi.InitApi()
|
||||
utils.EnableDebugLogForTest()
|
||||
app.Global().Srv.Store.MarkSystemRanUnitTests()
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
|
||||
if jobs.Srv.Store == nil {
|
||||
jobs.Srv.Store = app.Global().Srv.Store
|
||||
}
|
||||
|
||||
th := &TestHelper{}
|
||||
th.App = app.Global()
|
||||
th.Client = th.CreateClient()
|
||||
th.SystemAdminClient = th.CreateClient()
|
||||
return th
|
||||
return setupTestHelper(false)
|
||||
}
|
||||
|
||||
func StopServer() {
|
||||
@@ -389,7 +367,7 @@ func (me *TestHelper) LoginSystemAdminWithClient(client *model.Client4) {
|
||||
func (me *TestHelper) UpdateActiveUser(user *model.User, active bool) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
_, err := app.Global().UpdateActive(user, active)
|
||||
_, err := me.App.UpdateActive(user, active)
|
||||
if err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestPlugin(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer TearDown()
|
||||
|
||||
th.App.StartupPlugins(pluginDir, webappDir)
|
||||
th.App.InitPlugins(pluginDir, webappDir)
|
||||
|
||||
enablePlugins := *utils.Cfg.PluginSettings.Enable
|
||||
defer func() {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type TestHelper struct {
|
||||
App *App
|
||||
BasicTeam *model.Team
|
||||
BasicUser *model.User
|
||||
BasicUser2 *model.User
|
||||
@@ -20,55 +21,48 @@ type TestHelper struct {
|
||||
BasicPost *model.Post
|
||||
}
|
||||
|
||||
func (a *App) SetupEnterprise() *TestHelper {
|
||||
if a.Srv == nil {
|
||||
func setupTestHelper(enterprise bool) *TestHelper {
|
||||
th := &TestHelper{
|
||||
App: Global(),
|
||||
}
|
||||
|
||||
if th.App.Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.DisableDebugLogForTest()
|
||||
utils.License().Features.SetDefaults()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
a.StartServer()
|
||||
if enterprise {
|
||||
utils.License().Features.SetDefaults()
|
||||
}
|
||||
th.App.NewServer()
|
||||
th.App.InitStores()
|
||||
th.App.StartServer()
|
||||
utils.InitHTML()
|
||||
utils.EnableDebugLogForTest()
|
||||
a.Srv.Store.MarkSystemRanUnitTests()
|
||||
th.App.Srv.Store.MarkSystemRanUnitTests()
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
|
||||
return &TestHelper{}
|
||||
return th
|
||||
}
|
||||
|
||||
func (a *App) Setup() *TestHelper {
|
||||
if a.Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.DisableDebugLogForTest()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
a.StartServer()
|
||||
utils.InitHTML()
|
||||
utils.EnableDebugLogForTest()
|
||||
a.Srv.Store.MarkSystemRanUnitTests()
|
||||
func SetupEnterprise() *TestHelper {
|
||||
return setupTestHelper(true)
|
||||
}
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
|
||||
return &TestHelper{}
|
||||
func Setup() *TestHelper {
|
||||
return setupTestHelper(false)
|
||||
}
|
||||
|
||||
func (me *TestHelper) InitBasic() *TestHelper {
|
||||
me.BasicTeam = me.CreateTeam()
|
||||
me.BasicUser = me.CreateUser()
|
||||
Global().LinkUserToTeam(me.BasicUser, me.BasicTeam)
|
||||
me.App.LinkUserToTeam(me.BasicUser, me.BasicTeam)
|
||||
me.BasicUser2 = me.CreateUser()
|
||||
Global().LinkUserToTeam(me.BasicUser2, me.BasicTeam)
|
||||
me.App.LinkUserToTeam(me.BasicUser2, me.BasicTeam)
|
||||
me.BasicChannel = me.CreateChannel(me.BasicTeam)
|
||||
me.BasicPost = me.CreatePost(me.BasicChannel)
|
||||
|
||||
@@ -94,7 +88,7 @@ func (me *TestHelper) CreateTeam() *model.Team {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if team, err = Global().CreateTeam(team); err != nil {
|
||||
if team, err = me.App.CreateTeam(team); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -117,7 +111,7 @@ func (me *TestHelper) CreateUser() *model.User {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if user, err = Global().CreateUser(user); err != nil {
|
||||
if user, err = me.App.CreateUser(user); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -148,7 +142,7 @@ func (me *TestHelper) createChannel(team *model.Team, channelType string) *model
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if channel, err = Global().CreateChannel(channel, true); err != nil {
|
||||
if channel, err = me.App.CreateChannel(channel, true); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -169,7 +163,7 @@ func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if post, err = Global().CreatePost(post, channel, false); err != nil {
|
||||
if post, err = me.App.CreatePost(post, channel, false); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
|
||||
@@ -10,8 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCheckIfRolesGrantPermission(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
|
||||
cases := []struct {
|
||||
roles []string
|
||||
|
||||
@@ -8,8 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestPermanentDeleteChannel(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
incomingWasEnabled := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
|
||||
outgoingWasEnabled := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
|
||||
@@ -20,25 +19,25 @@ func TestPermanentDeleteChannel(t *testing.T) {
|
||||
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = outgoingWasEnabled
|
||||
}()
|
||||
|
||||
channel, err := a.CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
|
||||
channel, err := th.App.CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer func() {
|
||||
a.PermanentDeleteChannel(channel)
|
||||
th.App.PermanentDeleteChannel(channel)
|
||||
}()
|
||||
|
||||
incoming, err := a.CreateIncomingWebhookForChannel(th.BasicUser.Id, channel, &model.IncomingWebhook{ChannelId: channel.Id})
|
||||
incoming, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, channel, &model.IncomingWebhook{ChannelId: channel.Id})
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer a.DeleteIncomingWebhook(incoming.Id)
|
||||
defer th.App.DeleteIncomingWebhook(incoming.Id)
|
||||
|
||||
if incoming, err = a.GetIncomingWebhook(incoming.Id); incoming == nil || err != nil {
|
||||
if incoming, err = th.App.GetIncomingWebhook(incoming.Id); incoming == nil || err != nil {
|
||||
t.Fatal("unable to get new incoming webhook")
|
||||
}
|
||||
|
||||
outgoing, err := a.CreateOutgoingWebhook(&model.OutgoingWebhook{
|
||||
outgoing, err := th.App.CreateOutgoingWebhook(&model.OutgoingWebhook{
|
||||
ChannelId: channel.Id,
|
||||
TeamId: channel.TeamId,
|
||||
CreatorId: th.BasicUser.Id,
|
||||
@@ -47,65 +46,64 @@ func TestPermanentDeleteChannel(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer a.DeleteOutgoingWebhook(outgoing.Id)
|
||||
defer th.App.DeleteOutgoingWebhook(outgoing.Id)
|
||||
|
||||
if outgoing, err = a.GetOutgoingWebhook(outgoing.Id); outgoing == nil || err != nil {
|
||||
if outgoing, err = th.App.GetOutgoingWebhook(outgoing.Id); outgoing == nil || err != nil {
|
||||
t.Fatal("unable to get new outgoing webhook")
|
||||
}
|
||||
|
||||
if err := a.PermanentDeleteChannel(channel); err != nil {
|
||||
if err := th.App.PermanentDeleteChannel(channel); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if incoming, err = a.GetIncomingWebhook(incoming.Id); incoming != nil || err == nil {
|
||||
if incoming, err = th.App.GetIncomingWebhook(incoming.Id); incoming != nil || err == nil {
|
||||
t.Error("incoming webhook wasn't deleted")
|
||||
}
|
||||
|
||||
if outgoing, err = a.GetOutgoingWebhook(outgoing.Id); outgoing != nil || err == nil {
|
||||
if outgoing, err = th.App.GetOutgoingWebhook(outgoing.Id); outgoing != nil || err == nil {
|
||||
t.Error("outgoing webhook wasn't deleted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMoveChannel(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
sourceTeam := th.CreateTeam()
|
||||
targetTeam := th.CreateTeam()
|
||||
channel1 := th.CreateChannel(sourceTeam)
|
||||
defer func() {
|
||||
a.PermanentDeleteChannel(channel1)
|
||||
a.PermanentDeleteTeam(sourceTeam)
|
||||
a.PermanentDeleteTeam(targetTeam)
|
||||
th.App.PermanentDeleteChannel(channel1)
|
||||
th.App.PermanentDeleteTeam(sourceTeam)
|
||||
th.App.PermanentDeleteTeam(targetTeam)
|
||||
}()
|
||||
|
||||
if _, err := a.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := a.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := a.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := a.AddUserToChannel(th.BasicUser, channel1); err != nil {
|
||||
if _, err := th.App.AddUserToChannel(th.BasicUser, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := a.AddUserToChannel(th.BasicUser2, channel1); err != nil {
|
||||
if _, err := th.App.AddUserToChannel(th.BasicUser2, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.MoveChannel(targetTeam, channel1); err == nil {
|
||||
if err := th.App.MoveChannel(targetTeam, channel1); err == nil {
|
||||
t.Fatal("Should have failed due to mismatched members.")
|
||||
}
|
||||
|
||||
if _, err := a.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.MoveChannel(targetTeam, channel1); err != nil {
|
||||
if err := th.App.MoveChannel(targetTeam, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestClusterDiscoveryService(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
|
||||
ds := NewClusterDiscoveryService()
|
||||
ds.Type = model.CDS_TYPE_APP
|
||||
|
||||
@@ -8,8 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestRenameProviderDoCommand(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
rp := RenameProvider{}
|
||||
args := &model.CommandArgs{
|
||||
|
||||
@@ -47,8 +47,7 @@ func TestPluginSetting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDiagnostics(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
@@ -92,7 +91,7 @@ func TestDiagnostics(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("SendDailyDiagnostics", func(t *testing.T) {
|
||||
a.SendDailyDiagnostics()
|
||||
th.App.SendDailyDiagnostics()
|
||||
|
||||
info := ""
|
||||
// Collect the info sent.
|
||||
@@ -152,7 +151,7 @@ func TestDiagnostics(t *testing.T) {
|
||||
*utils.Cfg.LogSettings.EnableDiagnostics = oldSetting
|
||||
}()
|
||||
|
||||
a.SendDailyDiagnostics()
|
||||
th.App.SendDailyDiagnostics()
|
||||
|
||||
select {
|
||||
case <-data:
|
||||
|
||||
@@ -13,8 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestHandleNewNotifications(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
|
||||
id1 := model.NewId()
|
||||
id2 := model.NewId()
|
||||
@@ -94,8 +93,7 @@ func TestHandleNewNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckPendingNotifications(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
job := MakeEmailBatchingJob(128)
|
||||
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
|
||||
@@ -109,11 +107,11 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
channelMember := store.Must(a.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember := store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember.LastViewedAt = 9999999
|
||||
store.Must(a.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
store.Must(a.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
store.Must(th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
@@ -128,9 +126,9 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
// test that notifications are cleared if the user has acted
|
||||
channelMember = store.Must(a.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember = store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember.LastViewedAt = 10001000
|
||||
store.Must(a.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
job.checkPendingNotifications(time.Unix(10002, 0), func(string, []*batchedNotification) {})
|
||||
|
||||
@@ -202,14 +200,13 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
* Ensures that email batch interval defaults to 15 minutes for users that haven't explicitly set this preference
|
||||
*/
|
||||
func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
job := MakeEmailBatchingJob(128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember := store.Must(a.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember := store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
store.Must(a.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
|
||||
{
|
||||
@@ -239,17 +236,16 @@ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
|
||||
* Ensures that email batch interval defaults to 15 minutes if user preference is invalid
|
||||
*/
|
||||
func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
job := MakeEmailBatchingJob(128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember := store.Must(a.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember := store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
store.Must(a.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
// preference value is not an integer, so we'll fall back to the default 15min value
|
||||
store.Must(a.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
store.Must(th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
@@ -284,8 +280,7 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
|
||||
* Ensures that post contents are not included in notification email when email notification content type is set to generic
|
||||
*/
|
||||
func TestRenderBatchedPostGeneric(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
var post = &model.Post{}
|
||||
post.Message = "This is the message"
|
||||
var notification = &batchedNotification{}
|
||||
@@ -300,7 +295,7 @@ func TestRenderBatchedPostGeneric(t *testing.T) {
|
||||
return translationID
|
||||
}
|
||||
|
||||
var rendered = a.renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_GENERIC)
|
||||
var rendered = th.App.renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_GENERIC)
|
||||
if strings.Contains(rendered, post.Message) {
|
||||
t.Fatal("Rendered email should not contain post contents when email notification contents type is set to Generic.")
|
||||
}
|
||||
@@ -310,8 +305,7 @@ func TestRenderBatchedPostGeneric(t *testing.T) {
|
||||
* Ensures that post contents included in notification email when email notification content type is set to full
|
||||
*/
|
||||
func TestRenderBatchedPostFull(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
var post = &model.Post{}
|
||||
post.Message = "This is the message"
|
||||
var notification = &batchedNotification{}
|
||||
@@ -326,7 +320,7 @@ func TestRenderBatchedPostFull(t *testing.T) {
|
||||
return translationID
|
||||
}
|
||||
|
||||
var rendered = a.renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_FULL)
|
||||
var rendered = th.App.renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_FULL)
|
||||
if !strings.Contains(rendered, post.Message) {
|
||||
t.Fatal("Rendered email should contain post contents when email notification contents type is set to Full.")
|
||||
}
|
||||
|
||||
@@ -1,639 +0,0 @@
|
||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
/*func TestSendChangeUsernameEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var emailTo string = "test@example.com"
|
||||
var oldUsername string = "myoldusername"
|
||||
var newUsername string = "fancyusername"
|
||||
var locale string = "en"
|
||||
var siteURL string = ""
|
||||
var expectedPartialMessage string = "Your username for " + utils.Cfg.TeamSettings.SiteName + " has been changed to " + newUsername + "."
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your username has changed"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(emailTo)
|
||||
|
||||
if err := SendChangeUsernameEmail(oldUsername, newUsername, emailTo, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(emailTo)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], emailTo) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(emailTo, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendEmailChangeVerifyEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var newUserEmail string = "newtest@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://localhost:8065"
|
||||
var expectedPartialMessage string = "You updated your email"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Verify new email address"
|
||||
var token string = "TEST_TOKEN"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(newUserEmail)
|
||||
|
||||
if err := SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(newUserEmail)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], newUserEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(newUserEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(newUserEmail)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong new email in the message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendEmailChangeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var oldEmail string = "test@example.com"
|
||||
var newUserEmail string = "newtest@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = ""
|
||||
var expectedPartialMessage string = "Your email address for Mattermost has been changed to " + newUserEmail
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your email address has changed"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(oldEmail)
|
||||
|
||||
if err := SendEmailChangeEmail(oldEmail, newUserEmail, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(oldEmail)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], oldEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(oldEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendVerifyEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var userEmail string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://localhost:8605"
|
||||
var expectedPartialMessage string = "Please verify your email address by clicking below"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Email Verification"
|
||||
var token string = "TEST_TOKEN"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(userEmail)
|
||||
|
||||
if err := SendVerifyEmail(userEmail, locale, siteURL, token); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(userEmail)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], userEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(userEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(userEmail)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong new email in the message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendSignInChangeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var email string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = ""
|
||||
var method string = "AD/LDAP"
|
||||
var expectedPartialMessage string = "You updated your sign-in method on Mattermost to " + method + "."
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your sign-in method has been updated"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := SendSignInChangeEmail(email, method, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendWelcomeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var userId string = "32432nkjnijn432uj32"
|
||||
var email string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
var verified bool = true
|
||||
var expectedPartialMessage string = "Mattermost lets you share messages and files from your PC or phone, with instant search and archiving"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] You joined test.mattermost.io"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := a.SendWelcomeEmail(userId, email, verified, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
utils.DeleteMailBox(email)
|
||||
verified = false
|
||||
var expectedVerifyEmail string = "Please verify your email address by clicking below."
|
||||
|
||||
if err := a.SendWelcomeEmail(userId, email, verified, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedVerifyEmail) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(email)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong email in the message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendPasswordChangeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var email string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
var method string = "using a reset password link"
|
||||
var expectedPartialMessage string = "Your password has been updated for " + utils.Cfg.TeamSettings.SiteName + " on " + siteURL + " by " + method
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your password has been updated"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := SendPasswordChangeEmail(email, method, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendMfaChangeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var email string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
var activated bool = true
|
||||
var expectedPartialMessage string = "Multi-factor authentication has been added to your account on " + siteURL + "."
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your MFA has been updated"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := SendMfaChangeEmail(email, activated, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activated = false
|
||||
expectedPartialMessage = "Multi-factor authentication has been removed from your account on " + siteURL + "."
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := SendMfaChangeEmail(email, activated, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendInviteEmails(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
th := a.Setup().InitBasic()
|
||||
|
||||
var email1 string = "test1@example.com"
|
||||
var email2 string = "test2@example.com"
|
||||
var senderName string = "TheBoss"
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
invites := []string{email1, email2}
|
||||
var expectedPartialMessage string = "The team member *" + senderName + "* , has invited you to join *" + th.BasicTeam.DisplayName + "*"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] " + senderName + " invited you to join " + th.BasicTeam.DisplayName + " Team"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email1)
|
||||
utils.DeleteMailBox(email2)
|
||||
|
||||
SendInviteEmails(th.BasicTeam, senderName, invites, siteURL)
|
||||
|
||||
//Check if the email was send to the rigth email address to email1
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email1)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email1) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email1, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check if the email was send to the rigth email address to email2
|
||||
err = utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email2)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email2) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email2, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendPasswordReset(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
th := a.Setup().InitBasic()
|
||||
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
// var locale string = "en"
|
||||
var expectedPartialMessage string = "To change your password"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Reset your password"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(th.BasicUser.Email)
|
||||
|
||||
if _, err := a.SendPasswordReset(th.BasicUser.Email, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(th.BasicUser.Email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], th.BasicUser.Email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(th.BasicUser.Email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
loc := strings.Index(resultsEmail.Body.Text, "token=")
|
||||
if loc == -1 {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Code not found in email")
|
||||
}
|
||||
loc += 6
|
||||
recoveryTokenString := resultsEmail.Body.Text[loc : loc+model.TOKEN_SIZE]
|
||||
var recoveryToken *model.Token
|
||||
if result := <-a.Srv.Store.Token().GetByToken(recoveryTokenString); result.Err != nil {
|
||||
t.Log(recoveryTokenString)
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
recoveryToken = result.Data.(*model.Token)
|
||||
if !strings.Contains(resultsEmail.Body.Text, recoveryToken.Token) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Log(recoveryToken.Token)
|
||||
t.Fatal("Received wrong recovery code")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
@@ -36,8 +36,7 @@ func TestGeneratePublicLinkHash(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDoUploadFile(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
teamId := model.NewId()
|
||||
channelId := model.NewId()
|
||||
@@ -45,12 +44,12 @@ func TestDoUploadFile(t *testing.T) {
|
||||
filename := "test"
|
||||
data := []byte("abcd")
|
||||
|
||||
info1, err := a.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
defer func() {
|
||||
<-a.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
<-th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
utils.RemoveFile(info1.Path)
|
||||
}()
|
||||
}
|
||||
@@ -59,12 +58,12 @@ func TestDoUploadFile(t *testing.T) {
|
||||
t.Fatal("stored file at incorrect path", info1.Path)
|
||||
}
|
||||
|
||||
info2, err := a.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
info2, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
defer func() {
|
||||
<-a.Srv.Store.FileInfo().PermanentDelete(info2.Id)
|
||||
<-th.App.Srv.Store.FileInfo().PermanentDelete(info2.Id)
|
||||
utils.RemoveFile(info2.Path)
|
||||
}()
|
||||
}
|
||||
@@ -73,12 +72,12 @@ func TestDoUploadFile(t *testing.T) {
|
||||
t.Fatal("stored file at incorrect path", info2.Path)
|
||||
}
|
||||
|
||||
info3, err := a.DoUploadFile(time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
info3, err := th.App.DoUploadFile(time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
defer func() {
|
||||
<-a.Srv.Store.FileInfo().PermanentDelete(info3.Id)
|
||||
<-th.App.Srv.Store.FileInfo().PermanentDelete(info3.Id)
|
||||
utils.RemoveFile(info3.Path)
|
||||
}()
|
||||
}
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -11,20 +11,19 @@ import (
|
||||
)
|
||||
|
||||
func TestGetJob(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
status := &model.Job{
|
||||
Id: model.NewId(),
|
||||
Status: model.NewId(),
|
||||
}
|
||||
if result := <-a.Srv.Store.Job().Save(status); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.Job().Save(status); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
}
|
||||
|
||||
defer a.Srv.Store.Job().Delete(status.Id)
|
||||
defer th.App.Srv.Store.Job().Delete(status.Id)
|
||||
|
||||
if received, err := a.GetJob(status.Id); err != nil {
|
||||
if received, err := th.App.GetJob(status.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if received.Id != status.Id || received.Status != status.Status {
|
||||
t.Fatal("inccorrect job status received")
|
||||
@@ -32,8 +31,7 @@ func TestGetJob(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetJobByType(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
jobType := model.NewId()
|
||||
|
||||
@@ -56,11 +54,11 @@ func TestGetJobByType(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, status := range statuses {
|
||||
store.Must(a.Srv.Store.Job().Save(status))
|
||||
defer a.Srv.Store.Job().Delete(status.Id)
|
||||
store.Must(th.App.Srv.Store.Job().Save(status))
|
||||
defer th.App.Srv.Store.Job().Delete(status.Id)
|
||||
}
|
||||
|
||||
if received, err := a.GetJobsByType(jobType, 0, 2); err != nil {
|
||||
if received, err := th.App.GetJobsByType(jobType, 0, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 2 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
@@ -70,7 +68,7 @@ func TestGetJobByType(t *testing.T) {
|
||||
t.Fatal("should've received second newest job second")
|
||||
}
|
||||
|
||||
if received, err := a.GetJobsByType(jobType, 2, 2); err != nil {
|
||||
if received, err := th.App.GetJobsByType(jobType, 2, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 1 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
|
||||
@@ -11,31 +11,28 @@ import (
|
||||
)
|
||||
|
||||
func TestLoadLicense(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
a.LoadLicense()
|
||||
th.App.LoadLicense()
|
||||
if utils.IsLicensed() {
|
||||
t.Fatal("shouldn't have a valid license")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveLicense(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
b1 := []byte("junk")
|
||||
|
||||
if _, err := a.SaveLicense(b1); err == nil {
|
||||
if _, err := th.App.SaveLicense(b1); err == nil {
|
||||
t.Fatal("shouldn't have saved license")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLicense(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
if err := a.RemoveLicense(); err != nil {
|
||||
if err := th.App.RemoveLicense(); err != nil {
|
||||
t.Fatal("should have removed license")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,11 @@ import (
|
||||
)
|
||||
|
||||
func TestSendNotifications(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
a.AddUserToChannel(th.BasicUser2, th.BasicChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel)
|
||||
|
||||
post1, err := a.CreatePostMissingChannel(&model.Post{
|
||||
post1, err := th.App.CreatePostMissingChannel(&model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "@" + th.BasicUser2.Username,
|
||||
@@ -27,7 +26,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mentions, err := a.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil)
|
||||
mentions, err := th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if mentions == nil {
|
||||
@@ -38,12 +37,12 @@ func TestSendNotifications(t *testing.T) {
|
||||
t.Fatal("user should have been mentioned")
|
||||
}
|
||||
|
||||
dm, err := a.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
|
||||
dm, err := th.App.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
post2, err := a.CreatePostMissingChannel(&model.Post{
|
||||
post2, err := th.App.CreatePostMissingChannel(&model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: dm.Id,
|
||||
Message: "dm message",
|
||||
@@ -53,15 +52,15 @@ func TestSendNotifications(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = a.SendNotifications(post2, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
_, err = th.App.SendNotifications(post2, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a.UpdateActive(th.BasicUser2, false)
|
||||
a.InvalidateAllCaches()
|
||||
th.App.UpdateActive(th.BasicUser2, false)
|
||||
th.App.InvalidateAllCaches()
|
||||
|
||||
post3, err := a.CreatePostMissingChannel(&model.Post{
|
||||
post3, err := th.App.CreatePostMissingChannel(&model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: dm.Id,
|
||||
Message: "dm message",
|
||||
@@ -71,7 +70,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = a.SendNotifications(post3, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
_, err = th.App.SendNotifications(post3, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -409,8 +408,7 @@ func TestRemoveCodeFromMessage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMentionKeywords(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
// user with username or custom mentions enabled
|
||||
user1 := &model.User{
|
||||
Id: model.NewId(),
|
||||
@@ -835,8 +833,7 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
expectedPrefix := "[http://localhost:8065] New Direct Message from sender on"
|
||||
post := &model.Post{
|
||||
CreateAt: 1501804801000,
|
||||
@@ -849,8 +846,7 @@ func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailSubject(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
expectedPrefix := "[http://localhost:8065] Notification in team on"
|
||||
post := &model.Post{
|
||||
CreateAt: 1501804801000,
|
||||
@@ -863,8 +859,7 @@ func TestGetNotificationEmailSubject(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -879,7 +874,7 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification.") {
|
||||
t.Fatal("Expected email text 'You have a new notification. Got " + body)
|
||||
}
|
||||
@@ -898,8 +893,7 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -914,7 +908,7 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification.") {
|
||||
t.Fatal("Expected email text 'You have a new notification. Got " + body)
|
||||
}
|
||||
@@ -933,8 +927,7 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -949,7 +942,7 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification.") {
|
||||
t.Fatal("Expected email text 'You have a new notification. Got " + body)
|
||||
}
|
||||
@@ -968,8 +961,7 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -984,7 +976,7 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new direct message.") {
|
||||
t.Fatal("Expected email text 'You have a new direct message. Got " + body)
|
||||
}
|
||||
@@ -1001,8 +993,7 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
|
||||
|
||||
// from here
|
||||
func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -1017,7 +1008,7 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T)
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification from "+senderName) {
|
||||
t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
|
||||
}
|
||||
@@ -1033,8 +1024,7 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T)
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -1049,7 +1039,7 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification from "+senderName) {
|
||||
t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
|
||||
}
|
||||
@@ -1065,8 +1055,7 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -1081,7 +1070,7 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T)
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification from "+senderName) {
|
||||
t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
|
||||
}
|
||||
@@ -1097,8 +1086,7 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T)
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -1113,7 +1101,7 @@ func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T)
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new direct message from "+senderName) {
|
||||
t.Fatal("Expected email text 'You have a new direct message from " + senderName + "'. Got " + body)
|
||||
}
|
||||
|
||||
@@ -11,9 +11,8 @@ import (
|
||||
)
|
||||
|
||||
func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
if err := a.RevokeAccessToken(model.NewRandomString(16)); err == nil {
|
||||
th := Setup()
|
||||
if err := th.App.RevokeAccessToken(model.NewRandomString(16)); err == nil {
|
||||
t.Fatal("Should have failed bad token")
|
||||
}
|
||||
|
||||
@@ -24,8 +23,8 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
session.Roles = model.ROLE_SYSTEM_USER.Id
|
||||
session.SetExpireInDays(1)
|
||||
|
||||
session, _ = a.CreateSession(session)
|
||||
if err := a.RevokeAccessToken(session.Token); err == nil {
|
||||
session, _ = th.App.CreateSession(session)
|
||||
if err := th.App.RevokeAccessToken(session.Token); err == nil {
|
||||
t.Fatal("Should have failed does not have an access token")
|
||||
}
|
||||
|
||||
@@ -36,18 +35,17 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
accessData.ClientId = model.NewId()
|
||||
accessData.ExpiresAt = session.ExpiresAt
|
||||
|
||||
if result := <-a.Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
}
|
||||
|
||||
if err := a.RevokeAccessToken(accessData.Token); err != nil {
|
||||
if err := th.App.RevokeAccessToken(accessData.Token); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOAuthDeleteApp(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
oldSetting := utils.Cfg.ServiceSettings.EnableOAuthServiceProvider
|
||||
defer func() {
|
||||
@@ -62,7 +60,7 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
a1.Homepage = "https://nowhere.com"
|
||||
|
||||
var err *model.AppError
|
||||
a1, err = a.CreateOAuthApp(a1)
|
||||
a1, err = th.App.CreateOAuthApp(a1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -75,7 +73,7 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
session.IsOAuth = true
|
||||
session.SetExpireInDays(1)
|
||||
|
||||
session, _ = a.CreateSession(session)
|
||||
session, _ = th.App.CreateSession(session)
|
||||
|
||||
accessData := &model.AccessData{}
|
||||
accessData.Token = session.Token
|
||||
@@ -84,15 +82,15 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
accessData.ClientId = a1.Id
|
||||
accessData.ExpiresAt = session.ExpiresAt
|
||||
|
||||
if result := <-a.Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
}
|
||||
|
||||
if err := a.DeleteOAuthApp(a1.Id); err != nil {
|
||||
if err := th.App.DeleteOAuthApp(a1.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := a.GetSession(session.Token); err == nil {
|
||||
if _, err := th.App.GetSession(session.Token); err == nil {
|
||||
t.Fatal("should not get session from cache or db")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,13 @@ import (
|
||||
)
|
||||
|
||||
func TestUpdatePostEditAt(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
post := &model.Post{}
|
||||
*post = *th.BasicPost
|
||||
|
||||
post.IsPinned = true
|
||||
if saved, err := a.UpdatePost(post, true); err != nil {
|
||||
if saved, err := th.App.UpdatePost(post, true); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if saved.EditAt != post.EditAt {
|
||||
t.Fatal("shouldn't have updated post.EditAt when pinning post")
|
||||
@@ -37,7 +36,7 @@ func TestUpdatePostEditAt(t *testing.T) {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
||||
post.Message = model.NewId()
|
||||
if saved, err := a.UpdatePost(post, true); err != nil {
|
||||
if saved, err := th.App.UpdatePost(post, true); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if saved.EditAt == post.EditAt {
|
||||
t.Fatal("should have updated post.EditAt when updating post message")
|
||||
@@ -45,21 +44,20 @@ func TestUpdatePostEditAt(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
||||
a := Global()
|
||||
// This test ensures that when replying to a root post made by a user who has since left the channel, the reply
|
||||
// post completes successfully. This is a regression test for PLT-6523.
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
channel := th.BasicChannel
|
||||
userInChannel := th.BasicUser2
|
||||
userNotInChannel := th.BasicUser
|
||||
rootPost := th.BasicPost
|
||||
|
||||
if _, err := a.AddUserToChannel(userInChannel, channel); err != nil {
|
||||
if _, err := th.App.AddUserToChannel(userInChannel, channel); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.RemoveUserFromChannel(userNotInChannel.Id, "", channel); err != nil {
|
||||
if err := th.App.RemoveUserFromChannel(userNotInChannel.Id, "", channel); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -73,14 +71,13 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
if _, err := a.CreatePostAsUser(&replyPost); err != nil {
|
||||
if _, err := th.App.CreatePostAsUser(&replyPost); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostAction(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
|
||||
defer func() {
|
||||
@@ -125,7 +122,7 @@ func TestPostAction(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := a.CreatePostAsUser(&interactivePost)
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost)
|
||||
require.Nil(t, err)
|
||||
|
||||
attachments, ok := post.Props["attachments"].([]*model.SlackAttachment)
|
||||
@@ -134,10 +131,10 @@ func TestPostAction(t *testing.T) {
|
||||
require.NotEmpty(t, attachments[0].Actions)
|
||||
require.NotEmpty(t, attachments[0].Actions[0].Id)
|
||||
|
||||
err = a.DoPostAction(post.Id, "notavalidid", th.BasicUser.Id)
|
||||
err = th.App.DoPostAction(post.Id, "notavalidid", th.BasicUser.Id)
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, http.StatusNotFound, err.StatusCode)
|
||||
|
||||
err = a.DoPostAction(post.Id, attachments[0].Actions[0].Id, th.BasicUser.Id)
|
||||
err = th.App.DoPostAction(post.Id, attachments[0].Actions[0].Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCreateTeam(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
id := model.NewId()
|
||||
team := &model.Team{
|
||||
@@ -22,19 +21,18 @@ func TestCreateTeam(t *testing.T) {
|
||||
Type: model.TEAM_OPEN,
|
||||
}
|
||||
|
||||
if _, err := a.CreateTeam(team); err != nil {
|
||||
if _, err := th.App.CreateTeam(team); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should create a new team")
|
||||
}
|
||||
|
||||
if _, err := a.CreateTeam(th.BasicTeam); err == nil {
|
||||
if _, err := th.App.CreateTeam(th.BasicTeam); err == nil {
|
||||
t.Fatal("Should not create a new team - team already exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateTeamWithUser(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
id := model.NewId()
|
||||
team := &model.Team{
|
||||
@@ -44,17 +42,17 @@ func TestCreateTeamWithUser(t *testing.T) {
|
||||
Type: model.TEAM_OPEN,
|
||||
}
|
||||
|
||||
if _, err := a.CreateTeamWithUser(team, th.BasicUser.Id); err != nil {
|
||||
if _, err := th.App.CreateTeamWithUser(team, th.BasicUser.Id); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should create a new team with existing user")
|
||||
}
|
||||
|
||||
if _, err := a.CreateTeamWithUser(team, model.NewId()); err == nil {
|
||||
if _, err := th.App.CreateTeamWithUser(team, model.NewId()); err == nil {
|
||||
t.Fatal("Should not create a new team - user does not exist")
|
||||
}
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ := a.CreateUser(&user)
|
||||
ruser, _ := th.App.CreateUser(&user)
|
||||
|
||||
id = model.NewId()
|
||||
team2 := &model.Team{
|
||||
@@ -65,7 +63,7 @@ func TestCreateTeamWithUser(t *testing.T) {
|
||||
}
|
||||
|
||||
//Fail to create a team with user when user has set email without domain
|
||||
if _, err := a.CreateTeamWithUser(team2, ruser.Id); err == nil {
|
||||
if _, err := th.App.CreateTeamWithUser(team2, ruser.Id); err == nil {
|
||||
t.Log(err.Message)
|
||||
t.Fatal("Should not create a team with user when user has set email without domain")
|
||||
} else {
|
||||
@@ -77,12 +75,11 @@ func TestCreateTeamWithUser(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateTeam(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
th.BasicTeam.DisplayName = "Testing 123"
|
||||
|
||||
if updatedTeam, err := a.UpdateTeam(th.BasicTeam); err != nil {
|
||||
if updatedTeam, err := th.App.UpdateTeam(th.BasicTeam); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should update the team")
|
||||
} else {
|
||||
@@ -93,36 +90,33 @@ func TestUpdateTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddUserToTeam(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ := a.CreateUser(&user)
|
||||
ruser, _ := th.App.CreateUser(&user)
|
||||
|
||||
if _, err := a.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should add user to the team")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddUserToTeamByTeamId(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ := a.CreateUser(&user)
|
||||
ruser, _ := th.App.CreateUser(&user)
|
||||
|
||||
if err := a.AddUserToTeamByTeamId(th.BasicTeam.Id, ruser); err != nil {
|
||||
if err := th.App.AddUserToTeamByTeamId(th.BasicTeam.Id, ruser); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should add user to the team")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPermanentDeleteTeam(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
team, err := a.CreateTeam(&model.Team{
|
||||
team, err := th.App.CreateTeam(&model.Team{
|
||||
DisplayName: "deletion-test",
|
||||
Name: "deletion-test",
|
||||
Email: "foo@foo.com",
|
||||
@@ -132,10 +126,10 @@ func TestPermanentDeleteTeam(t *testing.T) {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer func() {
|
||||
a.PermanentDeleteTeam(team)
|
||||
th.App.PermanentDeleteTeam(team)
|
||||
}()
|
||||
|
||||
command, err := a.CreateCommand(&model.Command{
|
||||
command, err := th.App.CreateCommand(&model.Command{
|
||||
CreatorId: th.BasicUser.Id,
|
||||
TeamId: team.Id,
|
||||
Trigger: "foo",
|
||||
@@ -145,37 +139,37 @@ func TestPermanentDeleteTeam(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer a.DeleteCommand(command.Id)
|
||||
defer th.App.DeleteCommand(command.Id)
|
||||
|
||||
if command, err = a.GetCommand(command.Id); command == nil || err != nil {
|
||||
if command, err = th.App.GetCommand(command.Id); command == nil || err != nil {
|
||||
t.Fatal("unable to get new command")
|
||||
}
|
||||
|
||||
if err := a.PermanentDeleteTeam(team); err != nil {
|
||||
if err := th.App.PermanentDeleteTeam(team); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if command, err = a.GetCommand(command.Id); command != nil || err == nil {
|
||||
if command, err = th.App.GetCommand(command.Id); command != nil || err == nil {
|
||||
t.Fatal("command wasn't deleted")
|
||||
}
|
||||
|
||||
// Test deleting a team with no channels.
|
||||
team = th.CreateTeam()
|
||||
defer func() {
|
||||
a.PermanentDeleteTeam(team)
|
||||
th.App.PermanentDeleteTeam(team)
|
||||
}()
|
||||
|
||||
if channels, err := a.GetPublicChannelsForTeam(team.Id, 0, 1000); err != nil {
|
||||
if channels, err := th.App.GetPublicChannelsForTeam(team.Id, 0, 1000); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
for _, channel := range *channels {
|
||||
if err2 := a.PermanentDeleteChannel(channel); err2 != nil {
|
||||
if err2 := th.App.PermanentDeleteChannel(channel); err2 != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.PermanentDeleteTeam(team); err != nil {
|
||||
if err := th.App.PermanentDeleteTeam(team); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,9 @@ import (
|
||||
)
|
||||
|
||||
func TestIsUsernameTaken(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
user := th.BasicUser
|
||||
taken := a.IsUsernameTaken(user.Username)
|
||||
taken := th.App.IsUsernameTaken(user.Username)
|
||||
|
||||
if !taken {
|
||||
t.Logf("the username '%v' should be taken", user.Username)
|
||||
@@ -31,7 +30,7 @@ func TestIsUsernameTaken(t *testing.T) {
|
||||
}
|
||||
|
||||
newUsername := "randomUsername"
|
||||
taken = a.IsUsernameTaken(newUsername)
|
||||
taken = th.App.IsUsernameTaken(newUsername)
|
||||
|
||||
if taken {
|
||||
t.Logf("the username '%v' should not be taken", newUsername)
|
||||
@@ -40,8 +39,7 @@ func TestIsUsernameTaken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckUserDomain(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
user := th.BasicUser
|
||||
|
||||
cases := []struct {
|
||||
@@ -67,13 +65,12 @@ func TestCheckUserDomain(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateOAuthUser(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
glUser := oauthgitlab.GitLabUser{Id: int64(r.Intn(1000)) + 1, Username: "o" + model.NewId(), Email: model.NewId() + "@simulator.amazonses.com", Name: "Joram Wilander"}
|
||||
|
||||
json := glUser.ToJson()
|
||||
user, err := a.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
user, err := th.App.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -82,7 +79,7 @@ func TestCreateOAuthUser(t *testing.T) {
|
||||
t.Fatal("usernames didn't match")
|
||||
}
|
||||
|
||||
a.PermanentDeleteUser(user)
|
||||
th.App.PermanentDeleteUser(user)
|
||||
|
||||
userCreation := utils.Cfg.TeamSettings.EnableUserCreation
|
||||
defer func() {
|
||||
@@ -90,7 +87,7 @@ func TestCreateOAuthUser(t *testing.T) {
|
||||
}()
|
||||
utils.Cfg.TeamSettings.EnableUserCreation = false
|
||||
|
||||
_, err = a.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
_, err = th.App.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
if err == nil {
|
||||
t.Fatal("should have failed - user creation disabled")
|
||||
}
|
||||
@@ -118,8 +115,7 @@ func TestCreateProfileImage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
id := model.NewId()
|
||||
id2 := model.NewId()
|
||||
gitlabProvider := einterfaces.GetOauthProvider("gitlab")
|
||||
@@ -142,7 +138,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.Username != gitlabUserObj.Username {
|
||||
@@ -157,7 +153,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.Username == gitlabUserObj.Username {
|
||||
@@ -173,7 +169,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.Email != gitlabUserObj.Email {
|
||||
@@ -192,7 +188,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.Email == gitlabUserObj.Email {
|
||||
@@ -207,7 +203,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.FirstName != "Updated" {
|
||||
@@ -221,7 +217,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.LastName != "Lastname" {
|
||||
|
||||
@@ -11,9 +11,8 @@ import (
|
||||
)
|
||||
|
||||
func TestCreateWebhookPost(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
defer a.TearDown()
|
||||
th := Setup().InitBasic()
|
||||
defer th.App.TearDown()
|
||||
|
||||
enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
|
||||
defer func() {
|
||||
@@ -23,13 +22,13 @@ func TestCreateWebhookPost(t *testing.T) {
|
||||
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
|
||||
utils.SetDefaultRolesBasedOnConfig()
|
||||
|
||||
hook, err := a.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
||||
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer a.DeleteIncomingWebhook(hook.Id)
|
||||
defer th.App.DeleteIncomingWebhook(hook.Id)
|
||||
|
||||
post, err := a.CreateWebhookPost(hook.UserId, th.BasicChannel, "foo", "user", "http://iconurl", model.StringInterface{
|
||||
post, err := th.App.CreateWebhookPost(hook.UserId, th.BasicChannel, "foo", "user", "http://iconurl", model.StringInterface{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
&model.SlackAttachment{
|
||||
Text: "text",
|
||||
|
||||
@@ -126,7 +126,8 @@ func init() {
|
||||
}
|
||||
|
||||
func createChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -170,7 +171,7 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
CreatorId: "",
|
||||
}
|
||||
|
||||
if _, err := app.Global().CreateChannel(channel, false); err != nil {
|
||||
if _, err := a.CreateChannel(channel, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -178,7 +179,8 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func removeChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -197,24 +199,25 @@ func removeChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
users := getUsersFromUserArgs(args[1:])
|
||||
for i, user := range users {
|
||||
removeUserFromChannel(channel, user, args[i+1])
|
||||
removeUserFromChannel(a, channel, user, args[i+1])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeUserFromChannel(channel *model.Channel, user *model.User, userArg string) {
|
||||
func removeUserFromChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
|
||||
if user == nil {
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := app.Global().RemoveUserFromChannel(user.Id, "", channel); err != nil {
|
||||
if err := a.RemoveUserFromChannel(user.Id, "", channel); err != nil {
|
||||
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func addChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -233,24 +236,25 @@ func addChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
users := getUsersFromUserArgs(args[1:])
|
||||
for i, user := range users {
|
||||
addUserToChannel(channel, user, args[i+1])
|
||||
addUserToChannel(a, channel, user, args[i+1])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func addUserToChannel(channel *model.Channel, user *model.User, userArg string) {
|
||||
func addUserToChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
|
||||
if user == nil {
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if _, err := app.Global().AddUserToChannel(user, channel); err != nil {
|
||||
if _, err := a.AddUserToChannel(user, channel); err != nil {
|
||||
CommandPrintErrorln("Unable to add '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func archiveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -264,7 +268,7 @@ func archiveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if result := <-app.Global().Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil {
|
||||
CommandPrintErrorln("Unable to archive channel '" + channel.Name + "' error: " + result.Err.Error())
|
||||
}
|
||||
}
|
||||
@@ -273,7 +277,8 @@ func archiveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -297,7 +302,7 @@ func deleteChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if err := deleteChannel(channel); err != nil {
|
||||
if err := deleteChannel(a, channel); err != nil {
|
||||
CommandPrintErrorln("Unable to delete channel '" + channel.Name + "' error: " + err.Error())
|
||||
} else {
|
||||
CommandPrettyPrintln("Deleted channel '" + channel.Name + "'")
|
||||
@@ -307,12 +312,13 @@ func deleteChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteChannel(channel *model.Channel) *model.AppError {
|
||||
return app.Global().PermanentDeleteChannel(channel)
|
||||
func deleteChannel(a *app.App, channel *model.Channel) *model.AppError {
|
||||
return a.PermanentDeleteChannel(channel)
|
||||
}
|
||||
|
||||
func moveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -331,7 +337,7 @@ func moveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if err := moveChannel(team, channel); err != nil {
|
||||
if err := moveChannel(a, team, channel); err != nil {
|
||||
CommandPrintErrorln("Unable to move channel '" + channel.Name + "' error: " + err.Error())
|
||||
} else {
|
||||
CommandPrettyPrintln("Moved channel '" + channel.Name + "'")
|
||||
@@ -341,33 +347,33 @@ func moveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveChannel(team *model.Team, channel *model.Channel) *model.AppError {
|
||||
func moveChannel(a *app.App, team *model.Team, channel *model.Channel) *model.AppError {
|
||||
oldTeamId := channel.TeamId
|
||||
|
||||
if err := app.Global().MoveChannel(team, channel); err != nil {
|
||||
if err := a.MoveChannel(team, channel); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if incomingWebhooks, err := app.Global().GetIncomingWebhooksForTeamPage(oldTeamId, 0, 10000000); err != nil {
|
||||
if incomingWebhooks, err := a.GetIncomingWebhooksForTeamPage(oldTeamId, 0, 10000000); err != nil {
|
||||
return err
|
||||
} else {
|
||||
for _, webhook := range incomingWebhooks {
|
||||
if webhook.ChannelId == channel.Id {
|
||||
webhook.TeamId = team.Id
|
||||
if result := <-app.Global().Srv.Store.Webhook().UpdateIncoming(webhook); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().UpdateIncoming(webhook); result.Err != nil {
|
||||
CommandPrintErrorln("Failed to move incoming webhook '" + webhook.Id + "' to new team.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if outgoingWebhooks, err := app.Global().GetOutgoingWebhooksForTeamPage(oldTeamId, 0, 10000000); err != nil {
|
||||
if outgoingWebhooks, err := a.GetOutgoingWebhooksForTeamPage(oldTeamId, 0, 10000000); err != nil {
|
||||
return err
|
||||
} else {
|
||||
for _, webhook := range outgoingWebhooks {
|
||||
if webhook.ChannelId == channel.Id {
|
||||
webhook.TeamId = team.Id
|
||||
if result := <-app.Global().Srv.Store.Webhook().UpdateOutgoing(webhook); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().UpdateOutgoing(webhook); result.Err != nil {
|
||||
CommandPrintErrorln("Failed to move outgoing webhook '" + webhook.Id + "' to new team.")
|
||||
}
|
||||
}
|
||||
@@ -378,7 +384,8 @@ func moveChannel(team *model.Team, channel *model.Channel) *model.AppError {
|
||||
}
|
||||
|
||||
func listChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -396,7 +403,7 @@ func listChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if result := <-app.Global().Srv.Store.Channel().GetAll(team.Id); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Channel().GetAll(team.Id); result.Err != nil {
|
||||
CommandPrintErrorln("Unable to list channels for '" + args[i] + "'")
|
||||
} else {
|
||||
channels := result.Data.([]*model.Channel)
|
||||
@@ -415,7 +422,8 @@ func listChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -433,7 +441,7 @@ func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if result := <-app.Global().Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil {
|
||||
CommandPrintErrorln("Unable to restore channel '" + args[i] + "'")
|
||||
}
|
||||
}
|
||||
@@ -442,7 +450,8 @@ func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func modifyChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -475,7 +484,7 @@ func modifyChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
channel.Type = model.CHANNEL_PRIVATE
|
||||
}
|
||||
|
||||
if _, err := app.Global().UpdateChannel(channel); err != nil {
|
||||
if _, err := a.UpdateChannel(channel); err != nil {
|
||||
return errors.New("Failed to update channel '" + args[0] + "' - " + err.Error())
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -45,7 +44,8 @@ func init() {
|
||||
}
|
||||
|
||||
func slackImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func slackImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")
|
||||
|
||||
app.Global().SlackImport(fileReader, fileInfo.Size(), team.Id)
|
||||
a.SlackImport(fileReader, fileInfo.Size(), team.Id)
|
||||
|
||||
CommandPrettyPrintln("Finished Slack Import.")
|
||||
|
||||
@@ -79,7 +79,8 @@ func slackImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func bulkImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@ func bulkImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
CommandPrettyPrintln("")
|
||||
|
||||
if err, lineNumber := app.Global().BulkImport(fileReader, !apply, workers); err != nil {
|
||||
if err, lineNumber := a.BulkImport(fileReader, !apply, workers); err != nil {
|
||||
CommandPrettyPrintln(err.Error())
|
||||
if lineNumber != 0 {
|
||||
CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
|
||||
|
||||
@@ -7,32 +7,34 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func initDBCommandContextCobra(cmd *cobra.Command) error {
|
||||
func initDBCommandContextCobra(cmd *cobra.Command) (*app.App, error) {
|
||||
config, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := initDBCommandContext(config); err != nil {
|
||||
a, err := initDBCommandContext(config)
|
||||
if err != nil {
|
||||
// Returning an error just prints the usage message, so actually panic
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func initDBCommandContext(configFileLocation string) error {
|
||||
func initDBCommandContext(configFileLocation string) (*app.App, error) {
|
||||
if err := utils.InitAndLoadConfig(configFileLocation); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
utils.ConfigureCmdLineLog()
|
||||
|
||||
app.Global().NewServer()
|
||||
app.Global().InitStores()
|
||||
a := app.Global()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
if model.BuildEnterpriseReady == "true" {
|
||||
app.Global().LoadLicense()
|
||||
a.LoadLicense()
|
||||
}
|
||||
|
||||
return nil
|
||||
return a, nil
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func init() {
|
||||
}
|
||||
|
||||
func ldapSyncCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
if _, err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -28,7 +27,8 @@ func init() {
|
||||
}
|
||||
|
||||
func uploadLicenseCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -37,12 +37,11 @@ func uploadLicenseCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
var fileBytes []byte
|
||||
var err error
|
||||
if fileBytes, err = ioutil.ReadFile(args[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := app.Global().SaveLicense(fileBytes); err != nil {
|
||||
if _, err := a.SaveLicense(fileBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
// Plugins
|
||||
@@ -59,7 +58,8 @@ var resetCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func resetCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func resetCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
app.Global().Srv.Store.DropAllTables()
|
||||
a.Srv.Store.DropAllTables()
|
||||
CommandPrettyPrintln("Database sucessfully reset")
|
||||
|
||||
return nil
|
||||
|
||||
@@ -5,7 +5,6 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -38,7 +37,8 @@ func init() {
|
||||
}
|
||||
|
||||
func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if _, err := app.Global().UpdateUserRoles(user.Id, "system_admin system_user"); err != nil {
|
||||
if _, err := a.UpdateUserRoles(user.Id, "system_admin system_user"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,8 @@ func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func makeMemberCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ func makeMemberCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if _, err := app.Global().UpdateUserRoles(user.Id, "system_user"); err != nil {
|
||||
if _, err := a.UpdateUserRoles(user.Id, "system_user"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func runServer(configFileLocation string) {
|
||||
a := app.Global()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
api.InitRouter()
|
||||
a.Srv.Router = api.NewRouter()
|
||||
|
||||
if model.BuildEnterpriseReady == "true" {
|
||||
a.LoadLicense()
|
||||
@@ -82,8 +82,8 @@ func runServer(configFileLocation string) {
|
||||
a.InitPlugins("plugins", "webapp/dist")
|
||||
|
||||
wsapi.InitRouter()
|
||||
api4.InitApi(false)
|
||||
api.InitApi()
|
||||
api4.InitApi(a.Srv.Router, false)
|
||||
api.InitApi(a.Srv.Router)
|
||||
wsapi.InitApi()
|
||||
web.InitWeb()
|
||||
|
||||
@@ -98,7 +98,7 @@ func runServer(configFileLocation string) {
|
||||
|
||||
app.ReloadConfig()
|
||||
|
||||
resetStatuses()
|
||||
resetStatuses(a)
|
||||
|
||||
a.StartServer()
|
||||
|
||||
@@ -107,13 +107,13 @@ func runServer(configFileLocation string) {
|
||||
manualtesting.InitManualTesting()
|
||||
}
|
||||
|
||||
setDiagnosticId()
|
||||
setDiagnosticId(a)
|
||||
utils.RegenerateClientConfig()
|
||||
go runSecurityJob()
|
||||
go runDiagnosticsJob()
|
||||
go runSecurityJob(a)
|
||||
go runDiagnosticsJob(a)
|
||||
|
||||
go runTokenCleanupJob()
|
||||
go runCommandWebhookCleanupJob()
|
||||
go runTokenCleanupJob(a)
|
||||
go runCommandWebhookCleanupJob(a)
|
||||
|
||||
if complianceI := einterfaces.GetComplianceInterface(); complianceI != nil {
|
||||
complianceI.StartComplianceDailyJob()
|
||||
@@ -162,61 +162,69 @@ func runServer(configFileLocation string) {
|
||||
a.StopServer()
|
||||
}
|
||||
|
||||
func runSecurityJob() {
|
||||
doSecurity()
|
||||
model.CreateRecurringTask("Security", doSecurity, time.Hour*4)
|
||||
func runSecurityJob(a *app.App) {
|
||||
doSecurity(a)
|
||||
model.CreateRecurringTask("Security", func() {
|
||||
doSecurity(a)
|
||||
}, time.Hour*4)
|
||||
}
|
||||
|
||||
func runDiagnosticsJob() {
|
||||
doDiagnostics()
|
||||
model.CreateRecurringTask("Diagnostics", doDiagnostics, time.Hour*24)
|
||||
func runDiagnosticsJob(a *app.App) {
|
||||
doDiagnostics(a)
|
||||
model.CreateRecurringTask("Diagnostics", func() {
|
||||
doDiagnostics(a)
|
||||
}, time.Hour*24)
|
||||
}
|
||||
|
||||
func runTokenCleanupJob() {
|
||||
doTokenCleanup()
|
||||
model.CreateRecurringTask("Token Cleanup", doTokenCleanup, time.Hour*1)
|
||||
func runTokenCleanupJob(a *app.App) {
|
||||
doTokenCleanup(a)
|
||||
model.CreateRecurringTask("Token Cleanup", func() {
|
||||
doTokenCleanup(a)
|
||||
}, time.Hour*1)
|
||||
}
|
||||
|
||||
func runCommandWebhookCleanupJob() {
|
||||
doCommandWebhookCleanup()
|
||||
model.CreateRecurringTask("Command Hook Cleanup", doCommandWebhookCleanup, time.Hour*1)
|
||||
func runCommandWebhookCleanupJob(a *app.App) {
|
||||
doCommandWebhookCleanup(a)
|
||||
model.CreateRecurringTask("Command Hook Cleanup", func() {
|
||||
doCommandWebhookCleanup(a)
|
||||
}, time.Hour*1)
|
||||
}
|
||||
|
||||
func resetStatuses() {
|
||||
if result := <-app.Global().Srv.Store.Status().ResetAll(); result.Err != nil {
|
||||
func resetStatuses(a *app.App) {
|
||||
if result := <-a.Srv.Store.Status().ResetAll(); result.Err != nil {
|
||||
l4g.Error(utils.T("mattermost.reset_status.error"), result.Err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func setDiagnosticId() {
|
||||
if result := <-app.Global().Srv.Store.System().Get(); result.Err == nil {
|
||||
func setDiagnosticId(a *app.App) {
|
||||
if result := <-a.Srv.Store.System().Get(); result.Err == nil {
|
||||
props := result.Data.(model.StringMap)
|
||||
|
||||
id := props[model.SYSTEM_DIAGNOSTIC_ID]
|
||||
if len(id) == 0 {
|
||||
id = model.NewId()
|
||||
systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
|
||||
<-app.Global().Srv.Store.System().Save(systemId)
|
||||
<-a.Srv.Store.System().Save(systemId)
|
||||
}
|
||||
|
||||
utils.CfgDiagnosticId = id
|
||||
}
|
||||
}
|
||||
|
||||
func doSecurity() {
|
||||
app.Global().DoSecurityUpdateCheck()
|
||||
func doSecurity(a *app.App) {
|
||||
a.DoSecurityUpdateCheck()
|
||||
}
|
||||
|
||||
func doDiagnostics() {
|
||||
func doDiagnostics(a *app.App) {
|
||||
if *utils.Cfg.LogSettings.EnableDiagnostics {
|
||||
app.Global().SendDailyDiagnostics()
|
||||
a.SendDailyDiagnostics()
|
||||
}
|
||||
}
|
||||
|
||||
func doTokenCleanup() {
|
||||
app.Global().Srv.Store.Token().Cleanup()
|
||||
func doTokenCleanup(a *app.App) {
|
||||
a.Srv.Store.Token().Cleanup()
|
||||
}
|
||||
|
||||
func doCommandWebhookCleanup() {
|
||||
app.Global().Srv.Store.CommandWebhook().Cleanup()
|
||||
func doCommandWebhookCleanup(a *app.App) {
|
||||
a.Srv.Store.CommandWebhook().Cleanup()
|
||||
}
|
||||
|
||||
@@ -67,7 +67,8 @@ func init() {
|
||||
}
|
||||
|
||||
func createTeamCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -94,7 +95,7 @@ func createTeamCmdF(cmd *cobra.Command, args []string) error {
|
||||
Type: teamType,
|
||||
}
|
||||
|
||||
if _, err := app.Global().CreateTeam(team); err != nil {
|
||||
if _, err := a.CreateTeam(team); err != nil {
|
||||
return errors.New("Team creation failed: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -102,7 +103,8 @@ func createTeamCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func removeUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -117,24 +119,25 @@ func removeUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
users := getUsersFromUserArgs(args[1:])
|
||||
for i, user := range users {
|
||||
removeUserFromTeam(team, user, args[i+1])
|
||||
removeUserFromTeam(a, team, user, args[i+1])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeUserFromTeam(team *model.Team, user *model.User, userArg string) {
|
||||
func removeUserFromTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
|
||||
if user == nil {
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := app.Global().LeaveTeam(team, user); err != nil {
|
||||
if err := a.LeaveTeam(team, user); err != nil {
|
||||
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + team.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func addUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -149,24 +152,25 @@ func addUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
users := getUsersFromUserArgs(args[1:])
|
||||
for i, user := range users {
|
||||
addUserToTeam(team, user, args[i+1])
|
||||
addUserToTeam(a, team, user, args[i+1])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func addUserToTeam(team *model.Team, user *model.User, userArg string) {
|
||||
func addUserToTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
|
||||
if user == nil {
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := app.Global().JoinUserToTeam(team, user, ""); err != nil {
|
||||
if err := a.JoinUserToTeam(team, user, ""); err != nil {
|
||||
CommandPrintErrorln("Unable to add '" + userArg + "' to " + team.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func deleteTeamsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -196,7 +200,7 @@ func deleteTeamsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if err := deleteTeam(team); err != nil {
|
||||
if err := deleteTeam(a, team); err != nil {
|
||||
CommandPrintErrorln("Unable to delete team '" + team.Name + "' error: " + err.Error())
|
||||
} else {
|
||||
CommandPrettyPrintln("Deleted team '" + team.Name + "'")
|
||||
@@ -206,6 +210,6 @@ func deleteTeamsCmdF(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteTeam(team *model.Team) *model.AppError {
|
||||
return app.Global().PermanentDeleteTeam(team)
|
||||
func deleteTeam(a *app.App, team *model.Team) *model.AppError {
|
||||
return a.PermanentDeleteTeam(team)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mattermost/mattermost-server/wsapi"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -46,43 +45,45 @@ func init() {
|
||||
}
|
||||
|
||||
func webClientTestsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
api.InitRouter()
|
||||
a.Srv.Router = api.NewRouter()
|
||||
wsapi.InitRouter()
|
||||
api4.InitApi(false)
|
||||
api.InitApi()
|
||||
api4.InitApi(a.Srv.Router, false)
|
||||
api.InitApi(a.Srv.Router)
|
||||
wsapi.InitApi()
|
||||
setupClientTests()
|
||||
app.Global().StartServer()
|
||||
a.StartServer()
|
||||
runWebClientTests()
|
||||
app.Global().StopServer()
|
||||
a.StopServer()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func serverForWebClientTestsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
api.InitRouter()
|
||||
a.Srv.Router = api.NewRouter()
|
||||
wsapi.InitRouter()
|
||||
api4.InitApi(false)
|
||||
api.InitApi()
|
||||
api4.InitApi(a.Srv.Router, false)
|
||||
api.InitApi(a.Srv.Router)
|
||||
wsapi.InitApi()
|
||||
setupClientTests()
|
||||
app.Global().StartServer()
|
||||
a.StartServer()
|
||||
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-c
|
||||
|
||||
app.Global().StopServer()
|
||||
a.StopServer()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -158,7 +158,8 @@ func init() {
|
||||
}
|
||||
|
||||
func userActivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -166,14 +167,14 @@ func userActivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Expected at least one argument. See help text for details.")
|
||||
}
|
||||
|
||||
changeUsersActiveStatus(args, true)
|
||||
changeUsersActiveStatus(a, args, true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func changeUsersActiveStatus(userArgs []string, active bool) {
|
||||
func changeUsersActiveStatus(a *app.App, userArgs []string, active bool) {
|
||||
users := getUsersFromUserArgs(userArgs)
|
||||
for i, user := range users {
|
||||
err := changeUserActiveStatus(user, userArgs[i], active)
|
||||
err := changeUserActiveStatus(a, user, userArgs[i], active)
|
||||
|
||||
if err != nil {
|
||||
CommandPrintErrorln(err.Error())
|
||||
@@ -181,14 +182,14 @@ func changeUsersActiveStatus(userArgs []string, active bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func changeUserActiveStatus(user *model.User, userArg string, activate bool) error {
|
||||
func changeUserActiveStatus(a *app.App, user *model.User, userArg string, activate bool) error {
|
||||
if user == nil {
|
||||
return fmt.Errorf("Can't find user '%v'", userArg)
|
||||
}
|
||||
if user.IsLDAPUser() {
|
||||
return errors.New("You can not modify the activation status of AD/LDAP accounts. Please modify through the AD/LDAP server.")
|
||||
}
|
||||
if _, err := app.Global().UpdateActive(user, activate); err != nil {
|
||||
if _, err := a.UpdateActive(user, activate); err != nil {
|
||||
return fmt.Errorf("Unable to change activation status of user: %v", userArg)
|
||||
}
|
||||
|
||||
@@ -196,7 +197,8 @@ func changeUserActiveStatus(user *model.User, userArg string, activate bool) err
|
||||
}
|
||||
|
||||
func userDeactivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -204,12 +206,13 @@ func userDeactivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Expected at least one argument. See help text for details.")
|
||||
}
|
||||
|
||||
changeUsersActiveStatus(args, false)
|
||||
changeUsersActiveStatus(a, args, false)
|
||||
return nil
|
||||
}
|
||||
|
||||
func userCreateCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -241,13 +244,10 @@ func userCreateCmdF(cmd *cobra.Command, args []string) error {
|
||||
Locale: locale,
|
||||
}
|
||||
|
||||
ruser, err := app.Global().CreateUser(user)
|
||||
if err != nil {
|
||||
if ruser, err := a.CreateUser(user); err != nil {
|
||||
return errors.New("Unable to create user. Error: " + err.Error())
|
||||
}
|
||||
|
||||
if systemAdmin {
|
||||
app.Global().UpdateUserRoles(ruser.Id, "system_user system_admin")
|
||||
} else if systemAdmin {
|
||||
a.UpdateUserRoles(ruser.Id, "system_user system_admin")
|
||||
}
|
||||
|
||||
CommandPrettyPrintln("Created User")
|
||||
@@ -256,7 +256,8 @@ func userCreateCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func userInviteCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -296,7 +297,8 @@ func inviteUser(email string, team *model.Team, teamArg string) error {
|
||||
}
|
||||
|
||||
func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -310,7 +312,7 @@ func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
password := args[1]
|
||||
|
||||
if result := <-app.Global().Srv.Store.User().UpdatePassword(user.Id, model.HashPassword(password)); result.Err != nil {
|
||||
if result := <-a.Srv.Store.User().UpdatePassword(user.Id, model.HashPassword(password)); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
@@ -318,7 +320,8 @@ func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func resetUserMfaCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -342,7 +345,8 @@ func resetUserMfaCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -373,7 +377,7 @@ func deleteUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if err := app.Global().PermanentDeleteUser(user); err != nil {
|
||||
if err := a.PermanentDeleteUser(user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -382,7 +386,8 @@ func deleteUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -406,7 +411,7 @@ func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := app.Global().PermanentDeleteAllUsers(); err != nil {
|
||||
if err := a.PermanentDeleteAllUsers(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -415,7 +420,8 @@ func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func migrateAuthCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -458,7 +464,8 @@ func migrateAuthCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func verifyUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -473,7 +480,7 @@ func verifyUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find user '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if cresult := <-app.Global().Srv.Store.User().VerifyEmail(user.Id); cresult.Err != nil {
|
||||
if cresult := <-a.Srv.Store.User().VerifyEmail(user.Id); cresult.Err != nil {
|
||||
CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + cresult.Err.Error())
|
||||
}
|
||||
}
|
||||
@@ -482,7 +489,8 @@ func verifyUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func searchUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -16,20 +16,21 @@ var versionCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func versionCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printVersion()
|
||||
printVersion(a)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printVersion() {
|
||||
func printVersion(a *app.App) {
|
||||
CommandPrintln("Version: " + model.CurrentVersion)
|
||||
CommandPrintln("Build Number: " + model.BuildNumber)
|
||||
CommandPrintln("Build Date: " + model.BuildDate)
|
||||
CommandPrintln("Build Hash: " + model.BuildHash)
|
||||
CommandPrintln("Build Enterprise Ready: " + model.BuildEnterpriseReady)
|
||||
CommandPrintln("DB Version: " + app.Global().Srv.Store.(*store.LayeredStore).DatabaseLayer.GetCurrentSchemaVersion())
|
||||
CommandPrintln("DB Version: " + a.Srv.Store.(*store.LayeredStore).DatabaseLayer.GetCurrentSchemaVersion())
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package web
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
@@ -19,30 +18,32 @@ import (
|
||||
var ApiClient *model.Client
|
||||
var URL string
|
||||
|
||||
func Setup() {
|
||||
if app.Global().Srv == nil {
|
||||
func Setup() *app.App {
|
||||
a := app.Global()
|
||||
if a.Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
app.Global().NewServer()
|
||||
app.Global().InitStores()
|
||||
api.InitRouter()
|
||||
app.Global().StartServer()
|
||||
api4.InitApi(false)
|
||||
api.InitApi()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
a.Srv.Router = api.NewRouter()
|
||||
a.StartServer()
|
||||
api4.InitApi(a.Srv.Router, false)
|
||||
api.InitApi(a.Srv.Router)
|
||||
InitWeb()
|
||||
URL = "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress
|
||||
ApiClient = model.NewClient(URL)
|
||||
|
||||
app.Global().Srv.Store.MarkSystemRanUnitTests()
|
||||
a.Srv.Store.MarkSystemRanUnitTests()
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func TearDown() {
|
||||
if app.Global().Srv != nil {
|
||||
app.Global().StopServer()
|
||||
func TearDown(a *app.App) {
|
||||
if a.Srv != nil {
|
||||
a.StopServer()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,20 +65,21 @@ func TestStatic(t *testing.T) {
|
||||
*/
|
||||
|
||||
func TestIncomingWebhook(t *testing.T) {
|
||||
Setup()
|
||||
a := Setup()
|
||||
defer TearDown(a)
|
||||
|
||||
user := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = ApiClient.Must(ApiClient.CreateUser(user, "")).Data.(*model.User)
|
||||
store.Must(app.Global().Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(a.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
ApiClient.Login(user.Email, "passwd1")
|
||||
|
||||
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
team = ApiClient.Must(ApiClient.CreateTeam(team)).Data.(*model.Team)
|
||||
|
||||
app.Global().JoinUserToTeam(team, user, "")
|
||||
a.JoinUserToTeam(team, user, "")
|
||||
|
||||
app.Global().UpdateUserRoles(user.Id, model.ROLE_SYSTEM_ADMIN.Id)
|
||||
a.UpdateUserRoles(user.Id, model.ROLE_SYSTEM_ADMIN.Id)
|
||||
ApiClient.SetTeamId(team.Id)
|
||||
|
||||
channel1 := &model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
||||
@@ -113,15 +115,6 @@ func TestIncomingWebhook(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestZZWebTearDown(t *testing.T) {
|
||||
// *IMPORTANT*
|
||||
// This should be the last function in any test file
|
||||
// that calls Setup()
|
||||
// Should be in the last file too sorted by name
|
||||
time.Sleep(2 * time.Second)
|
||||
TearDown()
|
||||
}
|
||||
|
||||
func TestCheckBrowserCompatability(t *testing.T) {
|
||||
|
||||
//test should fail browser compatibility check with Mozilla FF 40.1
|
||||
|
||||
Ссылка в новой задаче
Block a user