From 758402311a97a053a5276049db6dce4f8f8dcfbc Mon Sep 17 00:00:00 2001 From: enahum Date: Tue, 28 Feb 2017 06:07:02 -0300 Subject: PLT-5548 Prevent server start if defaultLocate is not available (#5532) * PLT-5548 Prevent server start if defaultLocate is not available * Add validation for supported locales --- utils/config.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'utils/config.go') diff --git a/utils/config.go b/utils/config.go index 0908f2297..fd1597132 100644 --- a/utils/config.go +++ b/utils/config.go @@ -196,6 +196,10 @@ func LoadConfig(fileName string) { } } + if err := ValidateLocales(&config); err != nil { + panic(T(err.Id)) + } + if err := ValidateLdapFilter(&config); err != nil { panic(T(err.Id)) } @@ -387,6 +391,29 @@ func ValidateLdapFilter(cfg *model.Config) *model.AppError { return nil } +func ValidateLocales(cfg *model.Config) *model.AppError { + locales := GetSupportedLocales() + if _, ok := locales[*cfg.LocalizationSettings.DefaultServerLocale]; !ok { + return model.NewLocAppError("ValidateLocales", "utils.config.supported_server_locale.app_error", nil, "") + } + + if _, ok := locales[*cfg.LocalizationSettings.DefaultClientLocale]; !ok { + return model.NewLocAppError("ValidateLocales", "utils.config.supported_client_locale.app_error", nil, "") + } + + if len(*cfg.LocalizationSettings.AvailableLocales) > 0 { + for _, word := range strings.Split(*cfg.LocalizationSettings.AvailableLocales, ",") { + if word == *cfg.LocalizationSettings.DefaultClientLocale { + return nil + } + } + + return model.NewLocAppError("ValidateLocales", "utils.config.validate_locale.app_error", nil, "") + } + + return nil +} + func Desanitize(cfg *model.Config) { if cfg.LdapSettings.BindPassword != nil && *cfg.LdapSettings.BindPassword == model.FAKE_SETTING { *cfg.LdapSettings.BindPassword = *Cfg.LdapSettings.BindPassword -- cgit v1.2.3-1-g7c22