From 651dd33b29b7b8b296cc5a12479684fa836867b1 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Thu, 31 Aug 2017 01:54:16 +0800 Subject: set to default value with config is missing (#7320) --- api/admin_test.go | 4 ++-- api/apitestlib.go | 10 +++++----- api/command_test.go | 4 ++-- api/emoji.go | 6 +++--- api/file.go | 4 ++-- api/file_test.go | 28 ++++++++++++++-------------- api/user.go | 2 +- api/user_test.go | 18 +++++++++--------- api/websocket_test.go | 4 ++-- 9 files changed, 40 insertions(+), 40 deletions(-) (limited to 'api') diff --git a/api/admin_test.go b/api/admin_test.go index d5f24b715..bfc678adc 100644 --- a/api/admin_test.go +++ b/api/admin_test.go @@ -91,7 +91,7 @@ func TestGetConfig(t *testing.T) { if cfg.GitLabSettings.Secret != model.FAKE_SETTING && len(cfg.GitLabSettings.Secret) != 0 { t.Fatal("did not sanitize properly") } - if cfg.SqlSettings.DataSource != model.FAKE_SETTING { + if *cfg.SqlSettings.DataSource != model.FAKE_SETTING { t.Fatal("did not sanitize properly") } if cfg.SqlSettings.AtRestEncryptKey != model.FAKE_SETTING { @@ -114,7 +114,7 @@ func TestReloadConfig(t *testing.T) { t.Fatal(err) } - utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 + *utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 *utils.Cfg.TeamSettings.EnableOpenServer = true } diff --git a/api/apitestlib.go b/api/apitestlib.go index 94cd5a926..9aaf62e2b 100644 --- a/api/apitestlib.go +++ b/api/apitestlib.go @@ -36,7 +36,7 @@ func SetupEnterprise() *TestHelper { utils.TranslationsPreInit() utils.LoadConfig("config.json") utils.InitTranslations(utils.Cfg.LocalizationSettings) - utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 + *utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 *utils.Cfg.RateLimitSettings.Enable = false utils.DisableDebugLogForTest() utils.License().Features.SetDefaults() @@ -63,7 +63,7 @@ func Setup() *TestHelper { utils.TranslationsPreInit() utils.LoadConfig("config.json") utils.InitTranslations(utils.Cfg.LocalizationSettings) - utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 + *utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 *utils.Cfg.RateLimitSettings.Enable = false utils.Cfg.EmailSettings.SendEmailNotifications = true utils.Cfg.EmailSettings.SMTPServer = "dockerhost" @@ -90,7 +90,7 @@ func Setup() *TestHelper { func ReloadConfigForSetup() { utils.LoadConfig("config.json") utils.InitTranslations(utils.Cfg.LocalizationSettings) - utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 + *utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 *utils.Cfg.RateLimitSettings.Enable = false utils.Cfg.EmailSettings.SendEmailNotifications = true utils.Cfg.EmailSettings.SMTPServer = "dockerhost" @@ -133,11 +133,11 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper { } func (me *TestHelper) CreateClient() *model.Client { - return model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress) + return model.NewClient("http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress) } func (me *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, *model.AppError) { - return model.NewWebSocketClient("ws://localhost"+utils.Cfg.ServiceSettings.ListenAddress, me.BasicClient.AuthToken) + return model.NewWebSocketClient("ws://localhost"+*utils.Cfg.ServiceSettings.ListenAddress, me.BasicClient.AuthToken) } func (me *TestHelper) CreateTeam(client *model.Client) *model.Team { diff --git a/api/command_test.go b/api/command_test.go index dd4180b16..bc8aca6aa 100644 --- a/api/command_test.go +++ b/api/command_test.go @@ -242,7 +242,7 @@ func TestTestCommand(t *testing.T) { *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost" cmd1 := &model.Command{ - URL: "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V3 + "/teams/command_test", + URL: "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V3 + "/teams/command_test", Method: model.COMMAND_METHOD_POST, Trigger: "testcommand", } @@ -262,7 +262,7 @@ func TestTestCommand(t *testing.T) { } cmd2 := &model.Command{ - URL: "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V3 + "/teams/command_test", + URL: "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V3 + "/teams/command_test", Method: model.COMMAND_METHOD_GET, Trigger: "test2", } diff --git a/api/emoji.go b/api/emoji.go index 337cfe6f5..296e3afa3 100644 --- a/api/emoji.go +++ b/api/emoji.go @@ -59,7 +59,7 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) { return } - if len(utils.Cfg.FileSettings.DriverName) == 0 { + if len(*utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewLocAppError("createEmoji", "api.emoji.storage.app_error", nil, "") c.Err.StatusCode = http.StatusNotImplemented return @@ -137,7 +137,7 @@ func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) { return } - if len(utils.Cfg.FileSettings.DriverName) == 0 { + if len(*utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewLocAppError("deleteImage", "api.emoji.storage.app_error", nil, "") c.Err.StatusCode = http.StatusNotImplemented return @@ -179,7 +179,7 @@ func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) { return } - if len(utils.Cfg.FileSettings.DriverName) == 0 { + if len(*utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewLocAppError("getEmojiImage", "api.emoji.storage.app_error", nil, "") c.Err.StatusCode = http.StatusNotImplemented return diff --git a/api/file.go b/api/file.go index 1eab30e76..43814d8f4 100644 --- a/api/file.go +++ b/api/file.go @@ -200,7 +200,7 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) { } func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool) (*model.FileInfo, *model.AppError) { - if len(utils.Cfg.FileSettings.DriverName) == 0 { + if len(*utils.Cfg.FileSettings.DriverName) == 0 { return nil, model.NewAppError("getFileInfoForRequest", "api.file.get_info_for_request.storage.app_error", nil, "", http.StatusNotImplemented) } @@ -236,7 +236,7 @@ func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool) } func getPublicFileOld(c *Context, w http.ResponseWriter, r *http.Request) { - if len(utils.Cfg.FileSettings.DriverName) == 0 { + if len(*utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewLocAppError("getPublicFile", "api.file.get_public_file_old.storage.app_error", nil, "") c.Err.StatusCode = http.StatusNotImplemented return diff --git a/api/file_test.go b/api/file_test.go index 282cff2ec..0d64608c3 100644 --- a/api/file_test.go +++ b/api/file_test.go @@ -26,7 +26,7 @@ import ( func TestUploadFile(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Logf("skipping because no file driver is enabled") return } @@ -125,7 +125,7 @@ func TestUploadFile(t *testing.T) { func TestGetFileInfo(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -194,7 +194,7 @@ func TestGetFileInfo(t *testing.T) { func TestGetFile(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -276,7 +276,7 @@ func TestGetFile(t *testing.T) { func TestGetFileThumbnail(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -332,7 +332,7 @@ func TestGetFileThumbnail(t *testing.T) { func TestGetFilePreview(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -388,7 +388,7 @@ func TestGetFilePreview(t *testing.T) { func TestGetPublicFile(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -455,7 +455,7 @@ func TestGetPublicFile(t *testing.T) { func TestGetPublicFileOld(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -493,7 +493,7 @@ func TestGetPublicFileOld(t *testing.T) { // reconstruct old style of link siteURL := *utils.Cfg.ServiceSettings.SiteURL if siteURL == "" { - siteURL = "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress + siteURL = "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress } link := generatePublicLinkOld(siteURL, th.BasicTeam.Id, channel.Id, th.BasicUser.Id, fileId+"/test.png") @@ -539,7 +539,7 @@ func generatePublicLinkOld(siteURL, teamId, channelId, userId, filename string) func TestGetPublicLink(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -608,7 +608,7 @@ func TestGetPublicLink(t *testing.T) { func TestMigrateFilenamesToFileInfos(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -720,7 +720,7 @@ func uploadFileOld(t *testing.T, data []byte, dest string, filename string) { func TestFindTeamIdForFilename(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -786,7 +786,7 @@ func TestFindTeamIdForFilename(t *testing.T) { func TestGetInfoForFilename(t *testing.T) { th := Setup().InitBasic() - if utils.Cfg.FileSettings.DriverName == "" { + if *utils.Cfg.FileSettings.DriverName == "" { t.Skip("skipping because no file driver is enabled") } @@ -874,7 +874,7 @@ func s3New(endpoint, accessKey, secretKey string, secure bool, signV2 bool, regi } func cleanupTestFile(info *model.FileInfo) error { - if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if *utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { endpoint := utils.Cfg.FileSettings.AmazonS3Endpoint accessKey := utils.Cfg.FileSettings.AmazonS3AccessKeyId secretKey := utils.Cfg.FileSettings.AmazonS3SecretAccessKey @@ -901,7 +901,7 @@ func cleanupTestFile(info *model.FileInfo) error { return err } } - } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + } else if *utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { if err := os.Remove(utils.Cfg.FileSettings.Directory + info.Path); err != nil { return err } diff --git a/api/user.go b/api/user.go index 8843a3730..5ab72032e 100644 --- a/api/user.go +++ b/api/user.go @@ -580,7 +580,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { } func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { - if len(utils.Cfg.FileSettings.DriverName) == 0 { + if len(*utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.storage.app_error", nil, "") c.Err.StatusCode = http.StatusNotImplemented return diff --git a/api/user_test.go b/api/user_test.go index 8669a7bbe..e11391434 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -263,13 +263,13 @@ func TestPasswordGuessLockout(t *testing.T) { Client.Must(Client.Logout()) enableSignInWithEmail := *utils.Cfg.EmailSettings.EnableSignInWithEmail - passwordAttempts := utils.Cfg.ServiceSettings.MaximumLoginAttempts + passwordAttempts := *utils.Cfg.ServiceSettings.MaximumLoginAttempts defer func() { *utils.Cfg.EmailSettings.EnableSignInWithEmail = enableSignInWithEmail - utils.Cfg.ServiceSettings.MaximumLoginAttempts = passwordAttempts + *utils.Cfg.ServiceSettings.MaximumLoginAttempts = passwordAttempts }() *utils.Cfg.EmailSettings.EnableSignInWithEmail = true - utils.Cfg.ServiceSettings.MaximumLoginAttempts = 2 + *utils.Cfg.ServiceSettings.MaximumLoginAttempts = 2 // OK to log in if _, err := Client.Login(user.Username, user.Password); err != nil { @@ -689,7 +689,7 @@ func TestUserCreateImage(t *testing.T) { } } - if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if *utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { endpoint := utils.Cfg.FileSettings.AmazonS3Endpoint accessKey := utils.Cfg.FileSettings.AmazonS3AccessKeyId secretKey := utils.Cfg.FileSettings.AmazonS3SecretAccessKey @@ -726,7 +726,7 @@ func TestUserUploadProfileImage(t *testing.T) { LinkUserToTeam(user, team) store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) - if utils.Cfg.FileSettings.DriverName != "" { + if *utils.Cfg.FileSettings.DriverName != "" { body := &bytes.Buffer{} writer := multipart.NewWriter(body) @@ -795,7 +795,7 @@ func TestUserUploadProfileImage(t *testing.T) { Client.DoApiGet("/users/"+user.Id+"/image", "", "") - if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { + if *utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { endpoint := utils.Cfg.FileSettings.AmazonS3Endpoint accessKey := utils.Cfg.FileSettings.AmazonS3AccessKeyId secretKey := utils.Cfg.FileSettings.AmazonS3SecretAccessKey @@ -934,11 +934,11 @@ func TestUserUpdatePassword(t *testing.T) { } // Test lockout - passwordAttempts := utils.Cfg.ServiceSettings.MaximumLoginAttempts + passwordAttempts := *utils.Cfg.ServiceSettings.MaximumLoginAttempts defer func() { - utils.Cfg.ServiceSettings.MaximumLoginAttempts = passwordAttempts + *utils.Cfg.ServiceSettings.MaximumLoginAttempts = passwordAttempts }() - utils.Cfg.ServiceSettings.MaximumLoginAttempts = 2 + *utils.Cfg.ServiceSettings.MaximumLoginAttempts = 2 // Fail twice if _, err := Client.UpdateUserPassword(user.Id, "badpwd", "newpwd"); err == nil { diff --git a/api/websocket_test.go b/api/websocket_test.go index 18e1a6426..739b661ba 100644 --- a/api/websocket_test.go +++ b/api/websocket_test.go @@ -317,7 +317,7 @@ func TestCreateDirectChannelWithSocket(t *testing.T) { func TestWebsocketOriginSecurity(t *testing.T) { Setup().InitBasic() - url := "ws://localhost" + utils.Cfg.ServiceSettings.ListenAddress + url := "ws://localhost" + *utils.Cfg.ServiceSettings.ListenAddress // Should fail because origin doesn't match _, _, err := websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX_V3+"/users/websocket", http.Header{ @@ -329,7 +329,7 @@ func TestWebsocketOriginSecurity(t *testing.T) { // We are not a browser so we can spoof this just fine _, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX_V3+"/users/websocket", http.Header{ - "Origin": []string{"http://localhost" + utils.Cfg.ServiceSettings.ListenAddress}, + "Origin": []string{"http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress}, }) if err != nil { t.Fatal(err) -- cgit v1.2.3-1-g7c22