diff --git a/i18n/en.json b/i18n/en.json index 51bf9f6baa..36c75567be 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -4398,6 +4398,10 @@ "id": "model.config.is_valid.sitename_length.app_error", "translation": "Site name must be less than or equal to {{.MaxLength}} characters." }, + { + "id": "model.config.is_valid.sitename_empty.app_error", + "translation": "Site name cannot be empty." + }, { "id": "model.config.is_valid.sql_conn_max_lifetime_milliseconds.app_error", "translation": "Invalid connection maximum lifetime for SQL settings. Must be a non-negative number." diff --git a/model/config.go b/model/config.go index ae71805951..e081ad93a5 100644 --- a/model/config.go +++ b/model/config.go @@ -1394,7 +1394,7 @@ type TeamSettings struct { func (s *TeamSettings) SetDefaults() { - if s.SiteName == nil { + if s.SiteName == nil || *s.SiteName == "" { s.SiteName = NewString(TEAM_SETTINGS_DEFAULT_SITE_NAME) } @@ -2395,6 +2395,10 @@ func (ts *TeamSettings) isValid() *AppError { return NewAppError("Config.IsValid", "model.config.is_valid.teammate_name_display.app_error", nil, "", http.StatusBadRequest) } + if len(*ts.SiteName) == 0 { + return NewAppError("Config.IsValid", "model.config.is_valid.sitename_empty.app_error", nil, "", http.StatusBadRequest) + } + if len(*ts.SiteName) > SITENAME_MAX_LENGTH { return NewAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "", http.StatusBadRequest) } diff --git a/model/config_test.go b/model/config_test.go index 0330988ddc..731e7070b8 100644 --- a/model/config_test.go +++ b/model/config_test.go @@ -55,6 +55,19 @@ func TestConfigDefaults(t *testing.T) { }) } +func TestConfigEmptySiteName(t *testing.T) { + c1 := Config{ + TeamSettings: TeamSettings{ + SiteName: NewString(""), + }, + } + c1.SetDefaults() + + if *c1.TeamSettings.SiteName != TEAM_SETTINGS_DEFAULT_SITE_NAME { + t.Fatal("TeamSettings.SiteName should default to " + TEAM_SETTINGS_DEFAULT_SITE_NAME) + } +} + func TestConfigDefaultFileSettingsDirectory(t *testing.T) { c1 := Config{} c1.SetDefaults() @@ -114,6 +127,18 @@ func TestConfigDefaultServiceSettingsExperimentalGroupUnreadChannels(t *testing. } } +func TestTeamSettingsIsValidSiteNameEmpty(t *testing.T) { + c1 := Config{} + c1.SetDefaults() + c1.TeamSettings.SiteName = NewString("") + + // should fail fast because ts.SiteName is not set + err := c1.TeamSettings.isValid() + if err == nil { + t.Fatal("TeamSettings validation should fail with an empty SiteName") + } +} + func TestMessageExportSettingsIsValidEnableExportNotSet(t *testing.T) { fs := &FileSettings{} mes := &MessageExportSettings{}