config/envrionment: fix a panic where a setting is not defined in (#15819)
model.Config
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c67c46a684
Коммит
40371d8616
@@ -17,7 +17,10 @@ func removeEnvOverrides(cfg, cfgWithoutEnv *model.Config, envOverrides map[strin
|
||||
newCfg := cfg.Clone()
|
||||
for _, path := range paths {
|
||||
originalVal := getVal(cfgWithoutEnv, path)
|
||||
getVal(newCfg, path).Set(originalVal)
|
||||
newVal := getVal(newCfg, path)
|
||||
if newVal.CanSet() {
|
||||
newVal.Set(originalVal)
|
||||
}
|
||||
}
|
||||
return newCfg
|
||||
}
|
||||
|
||||
37
config/environment_test.go
Обычный файл
37
config/environment_test.go
Обычный файл
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRemoveEnvOverrides(t *testing.T) {
|
||||
defaultCfg := &model.Config{}
|
||||
defaultCfg.SetDefaults()
|
||||
|
||||
newCfg := defaultCfg.Clone()
|
||||
newCfg.EmailSettings.EnableSignUpWithEmail = model.NewBool(false)
|
||||
|
||||
envOverrides := map[string]interface{}{
|
||||
"EmailSettings": map[string]interface{}{
|
||||
"EnableSignUpWithEmail": false,
|
||||
},
|
||||
}
|
||||
|
||||
updatedCfg := removeEnvOverrides(newCfg, defaultCfg, envOverrides)
|
||||
require.NotNil(t, updatedCfg)
|
||||
require.True(t, *updatedCfg.EmailSettings.EnableSignUpWithEmail)
|
||||
|
||||
envOverrides["ServiceSettings"] = map[string]interface{}{
|
||||
"NonExistentConfig": true,
|
||||
}
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
_ = removeEnvOverrides(defaultCfg, defaultCfg, envOverrides)
|
||||
}, "invalid setting should not panic")
|
||||
}
|
||||
Ссылка в новой задаче
Block a user