Commit 4e6cc846 authored by Chris's avatar Chris Committed by Harrison Healey

Finally remove utils.Cfg (#8113)

* finally remove utils.Cfg

* fix compile error

* another test compilation fix
parent dce06163
......@@ -5,6 +5,8 @@ package api
import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
......@@ -24,7 +26,7 @@ import (
type TestHelper struct {
App *app.App
originalConfig *model.Config
tempConfigPath string
BasicClient *model.Client
BasicTeam *model.Team
......@@ -64,7 +66,22 @@ func StopTestStore() {
}
func setupTestHelper(enterprise bool) *TestHelper {
options := []app.Option{app.DisableConfigWatch}
permConfig, err := os.Open(utils.FindConfigFile("config.json"))
if err != nil {
panic(err)
}
defer permConfig.Close()
tempConfig, err := ioutil.TempFile("", "")
if err != nil {
panic(err)
}
_, err = io.Copy(tempConfig, permConfig)
tempConfig.Close()
if err != nil {
panic(err)
}
options := []app.Option{app.ConfigFile(tempConfig.Name()), app.DisableConfigWatch}
if testStore != nil {
options = append(options, app.StoreOverride(testStore))
}
......@@ -75,9 +92,9 @@ func setupTestHelper(enterprise bool) *TestHelper {
}
th := &TestHelper{
App: a,
App: a,
tempConfigPath: tempConfig.Name(),
}
th.originalConfig = th.App.Config().Clone()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.MaxUsersPerTeam = 50
......@@ -176,7 +193,7 @@ func (me *TestHelper) CreateTeam(client *model.Client) *model.Team {
team := &model.Team{
DisplayName: "dn_" + id,
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Type: model.TEAM_OPEN,
}
......@@ -190,7 +207,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
id := model.NewId()
user := &model.User{
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
......@@ -353,8 +370,8 @@ func (me *TestHelper) LoginSystemAdmin() {
utils.EnableDebugLogForTest()
}
func GenerateTestEmail() string {
if utils.Cfg.EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
func (me *TestHelper) GenerateTestEmail() string {
if me.App.Config().EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com")
}
return strings.ToLower(model.NewId() + "@dockerhost")
......@@ -365,11 +382,8 @@ func GenerateTestTeamName() string {
}
func (me *TestHelper) TearDown() {
me.App.UpdateConfig(func(cfg *model.Config) {
*cfg = *me.originalConfig
})
me.App.Shutdown()
os.Remove(me.tempConfigPath)
if err := recover(); err != nil {
StopTestStore()
panic(err)
......
......@@ -88,8 +88,6 @@ func TestOAuthRegisterApp(t *testing.T) {
t.Fatal("should have failed. not enough permissions")
}
adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
th.LoginBasic()
......@@ -741,9 +739,6 @@ func TestOAuthComplete(t *testing.T) {
// We are going to use mattermost as the provider emulating gitlab
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
oauthApp := &model.OAuthApp{
......
......@@ -66,7 +66,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
......@@ -84,7 +84,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
......@@ -304,7 +304,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......@@ -317,7 +317,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
if res, err := th.SystemAdminClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......@@ -418,7 +418,7 @@ func TestGetAllTeamListingsSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
......@@ -432,7 +432,7 @@ func TestGetAllTeamListingsSanitization(t *testing.T) {
if res, err := th.SystemAdminClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
......@@ -665,7 +665,7 @@ func TestUpdateTeamSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......@@ -772,7 +772,7 @@ func TestGetMyTeamSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......@@ -1192,7 +1192,7 @@ func TestGetTeamByNameSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
......
......@@ -7,6 +7,7 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
......@@ -33,7 +34,7 @@ import (
type TestHelper struct {
App *app.App
originalConfig *model.Config
tempConfigPath string
Client *model.Client4
BasicUser *model.User
......@@ -73,7 +74,22 @@ func StopTestStore() {
}
func setupTestHelper(enterprise bool) *TestHelper {
options := []app.Option{app.DisableConfigWatch}
permConfig, err := os.Open(utils.FindConfigFile("config.json"))
if err != nil {
panic(err)
}
defer permConfig.Close()
tempConfig, err := ioutil.TempFile("", "")
if err != nil {
panic(err)
}
_, err = io.Copy(tempConfig, permConfig)
tempConfig.Close()
if err != nil {
panic(err)
}
options := []app.Option{app.ConfigFile(tempConfig.Name()), app.DisableConfigWatch}
if testStore != nil {
options = append(options, app.StoreOverride(testStore))
}
......@@ -84,9 +100,9 @@ func setupTestHelper(enterprise bool) *TestHelper {
}
th := &TestHelper{
App: a,
App: a,
tempConfigPath: tempConfig.Name(),
}
th.originalConfig = th.App.Config().Clone()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.MaxUsersPerTeam = 50
......@@ -178,11 +194,8 @@ func (me *TestHelper) TearDown() {
wg.Wait()
me.App.UpdateConfig(func(cfg *model.Config) {
*cfg = *me.originalConfig
})
me.App.Shutdown()
os.Remove(me.tempConfigPath)
utils.EnableDebugLogForTest()
......@@ -262,7 +275,7 @@ func (me *TestHelper) CreateTeamWithClient(client *model.Client4) *model.Team {
team := &model.Team{
DisplayName: "dn_" + id,
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Type: model.TEAM_OPEN,
}
......@@ -276,7 +289,7 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
id := model.NewId()
user := &model.User{
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Username: GenerateTestUsername(),
Nickname: "nn_" + id,
FirstName: "f_" + id,
......@@ -451,8 +464,8 @@ func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) {
utils.EnableDebugLogForTest()
}
func GenerateTestEmail() string {
if utils.Cfg.EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
func (me *TestHelper) GenerateTestEmail() string {
if me.App.Config().EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com")
}
return strings.ToLower(model.NewId() + "@dockerhost")
......
......@@ -323,7 +323,7 @@ func TestCreatePostPublic(t *testing.T) {
post := &model.Post{ChannelId: th.BasicChannel.Id, Message: "#hashtag a" + model.NewId() + "a"}
user := model.User{Email: GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_USER_ROLE_ID}
ruser, resp := Client.CreateUser(&user)
CheckNoError(t, resp)
......@@ -368,7 +368,7 @@ func TestCreatePostAll(t *testing.T) {
post := &model.Post{ChannelId: th.BasicChannel.Id, Message: "#hashtag a" + model.NewId() + "a"}
user := model.User{Email: GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_USER_ROLE_ID}
directChannel, _ := th.App.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
......
......@@ -91,7 +91,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
......@@ -109,7 +109,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
......@@ -148,10 +148,10 @@ func TestGetTeam(t *testing.T) {
th.LoginTeamAdmin()
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
rteam2, _ := Client.CreateTeam(team2)
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
rteam3, _ := Client.CreateTeam(team3)
th.LoginBasic()
......@@ -178,7 +178,7 @@ func TestGetTeamSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -359,7 +359,7 @@ func TestUpdateTeamSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -458,7 +458,7 @@ func TestPatchTeamSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -492,7 +492,7 @@ func TestSoftDeleteTeam(t *testing.T) {
defer th.TearDown()
Client := th.Client
team := &model.Team{DisplayName: "DisplayName", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN}
team := &model.Team{DisplayName: "DisplayName", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN}
team, _ = Client.CreateTeam(team)
ok, resp := Client.SoftDeleteTeam(team.Id)
......@@ -534,7 +534,7 @@ func TestPermanentDeleteTeam(t *testing.T) {
defer th.TearDown()
Client := th.Client
team := &model.Team{DisplayName: "DisplayName", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN}
team := &model.Team{DisplayName: "DisplayName", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN}
team, _ = Client.CreateTeam(team)
ok, resp := Client.PermanentDeleteTeam(team.Id)
......@@ -567,7 +567,7 @@ func TestGetAllTeams(t *testing.T) {
defer th.TearDown()
Client := th.Client
team := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: true}
team := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: true}
_, resp := Client.CreateTeam(team)
CheckNoError(t, resp)
......@@ -627,7 +627,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
......@@ -636,7 +636,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
team2, resp := th.SystemAdminClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
......@@ -722,10 +722,10 @@ func TestGetTeamByName(t *testing.T) {
th.LoginTeamAdmin()
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_OPEN, AllowOpenInvite: false}
rteam2, _ := Client.CreateTeam(team2)
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
team3 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_INVITE, AllowOpenInvite: true}
rteam3, _ := Client.CreateTeam(team3)
th.LoginBasic()
......@@ -745,7 +745,7 @@ func TestGetTeamByNameSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -800,7 +800,7 @@ func TestSearchAllTeams(t *testing.T) {
oTeam.UpdateAt = updatedTeam.UpdateAt
}
pTeam := &model.Team{DisplayName: "PName", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE}
pTeam := &model.Team{DisplayName: "PName", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_INVITE}
Client.CreateTeam(pTeam)
rteams, resp := Client.SearchTeams(&model.TeamSearch{Term: oTeam.Name})
......@@ -876,7 +876,7 @@ func TestSearchAllTeamsSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -884,7 +884,7 @@ func TestSearchAllTeamsSanitization(t *testing.T) {
team2, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -954,7 +954,7 @@ func TestGetTeamsForUser(t *testing.T) {
defer th.TearDown()
Client := th.Client
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE}
team2 := &model.Team{DisplayName: "Name", Name: GenerateTestTeamName(), Email: th.GenerateTestEmail(), Type: model.TEAM_INVITE}
rteam2, _ := Client.CreateTeam(team2)
teams, resp := Client.GetTeamsForUser(th.BasicUser.Id, "")
......@@ -998,7 +998,7 @@ func TestGetTeamsForUserSanitization(t *testing.T) {
team, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -1006,7 +1006,7 @@ func TestGetTeamsForUserSanitization(t *testing.T) {
team2, resp := th.Client.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
})
......@@ -1881,8 +1881,8 @@ func TestInviteUsersToTeam(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()
user1 := GenerateTestEmail()
user2 := GenerateTestEmail()
user1 := th.GenerateTestEmail()
user2 := th.GenerateTestEmail()
emailList := []string{user1, user2}
......
......@@ -23,7 +23,7 @@ func TestCreateUser(t *testing.T) {
Client := th.Client
AdminClient := th.SystemAdminClient
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
ruser, resp := Client.CreateUser(&user)
CheckNoError(t, resp)
......@@ -52,7 +52,7 @@ func TestCreateUser(t *testing.T) {
CheckErrorMessage(t, resp, "store.sql_user.save.email_exists.app_error")
CheckBadRequestStatus(t, resp)
ruser.Email = GenerateTestEmail()
ruser.Email = th.GenerateTestEmail()
ruser.Username = user.Username
_, resp = Client.CreateUser(ruser)
CheckErrorMessage(t, resp, "store.sql_user.save.username_exists.app_error")
......@@ -66,7 +66,7 @@ func TestCreateUser(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = false })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableUserCreation = false })
user2 := &model.User{Email: GenerateTestEmail(), Password: "Password1", Username: GenerateTestUsername()}
user2 := &model.User{Email: th.GenerateTestEmail(), Password: "Password1", Username: GenerateTestUsername()}
_, resp = AdminClient.CreateUser(user2)
CheckNoError(t, resp)
......@@ -87,7 +87,7 @@ func TestCreateUserWithHash(t *testing.T) {
Client := th.Client
t.Run("CreateWithHashHappyPath", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
props := make(map[string]string)
props["email"] = user.Email
props["id"] = th.BasicTeam.Id
......@@ -113,7 +113,7 @@ func TestCreateUserWithHash(t *testing.T) {
})
t.Run("NoHashAndNoData", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
props := make(map[string]string)
props["email"] = user.Email
props["id"] = th.BasicTeam.Id
......@@ -133,7 +133,7 @@ func TestCreateUserWithHash(t *testing.T) {
})
t.Run("HashExpired", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
timeNow := time.Now()
past49Hours := timeNow.Add(-49*time.Hour).UnixNano() / int64(time.Millisecond)
......@@ -152,7 +152,7 @@ func TestCreateUserWithHash(t *testing.T) {
})
t.Run("WrongHash", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
props := make(map[string]string)
props["email"] = user.Email
props["id"] = th.BasicTeam.Id
......@@ -168,7 +168,7 @@ func TestCreateUserWithHash(t *testing.T) {
})
t.Run("EnableUserCreationDisable", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
props := make(map[string]string)
props["email"] = user.Email
......@@ -189,7 +189,7 @@ func TestCreateUserWithHash(t *testing.T) {
})
t.Run("EnableOpenServerDisable", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
props := make(map[string]string)
props["email"] = user.Email
......@@ -225,7 +225,7 @@ func TestCreateUserWithInviteId(t *testing.T) {
AdminClient := th.SystemAdminClient
t.Run("CreateWithInviteIdHappyPath", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
inviteId := th.BasicTeam.InviteId
......@@ -245,7 +245,7 @@ func TestCreateUserWithInviteId(t *testing.T) {
})
t.Run("WrongInviteId", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
inviteId := model.NewId()
......@@ -255,7 +255,7 @@ func TestCreateUserWithInviteId(t *testing.T) {
})
t.Run("NoInviteId", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
_, resp := Client.CreateUserWithInviteId(&user, "")
CheckBadRequestStatus(t, resp)
......@@ -263,7 +263,7 @@ func TestCreateUserWithInviteId(t *testing.T) {
})
t.Run("ExpiredInviteId", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
inviteId := th.BasicTeam.InviteId
......@@ -277,7 +277,7 @@ func TestCreateUserWithInviteId(t *testing.T) {
})
t.Run("EnableUserCreationDisable", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableUserCreation = false })
......@@ -291,7 +291,7 @@ func TestCreateUserWithInviteId(t *testing.T) {
})
t.Run("EnableOpenServerDisable", func(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = false })
......@@ -471,7 +471,7 @@ func TestGetUserByEmail(t *testing.T) {
_, resp = Client.GetUserByEmail(GenerateTestUsername(), "")
CheckBadRequestStatus(t, resp)
_, resp = Client.GetUserByEmail(GenerateTestEmail(), "")
_, resp = Client.GetUserByEmail(th.GenerateTestEmail(), "")
CheckNotFoundStatus(t, resp)
// Check against privacy config settings
......@@ -964,7 +964,7 @@ func TestUpdateUser(t *testing.T) {
th.App.AddSessionToCache(session)
ruser.Id = user.Id
ruser.Email = GenerateTestEmail()
ruser.Email = th.GenerateTestEmail()
_, resp = Client.UpdateUser(ruser)
CheckForbiddenStatus(t, resp)
......@@ -1047,7 +1047,7 @@ func TestPatchUser(t *testing.T) {
session.IsOAuth = true
th.App.AddSessionToCache(session)
patch.Email = model.NewString(GenerateTestEmail())
patch.Email = model.NewString(th.GenerateTestEmail())
_, resp = Client.PatchUser(user.Id, patch)
CheckForbiddenStatus(t, resp)
......@@ -2070,7 +2070,7 @@ func TestVerifyUserEmail(t *testing.T) {
defer th.TearDown()
Client := th.Client
user := model.User{Email: GenerateTestEmail(), Nickname: "Darth Vader", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Darth Vader", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
ruser, resp := Client.CreateUser(&user)
......@@ -2105,7 +2105,7 @@ func TestSendVerificationEmail(t *testing.T) {
CheckBadRequestStatus(t, resp)
// Even non-existent emails should return 200 OK
_, resp = Client.SendVerificationEmail(GenerateTestEmail())
_, resp = Client.SendVerificationEmail(th.GenerateTestEmail())
CheckNoError(t, resp)
Client.Logout()
......@@ -2450,20 +2450,20 @@ func TestGetUserAccessToken(t *testing.T) {
if len(rtokens) != 2 {
t.Fatal("should have 2 tokens")
}
_, resp = Client.GetUserAccessTokens(0,100)
_, resp = Client.GetUserAccessTokens(0, 100)
CheckForbiddenStatus(t, resp)
rtokens, resp = AdminClient.GetUserAccessTokens(1,1)
rtokens, resp = AdminClient.GetUserAccessTokens(1, 1)
CheckNoError(t, resp)
if