fix(configuration): mail address decode hook func (#2790)
This fixes an issue with the mail address decode hook func which previously would attempt to decode any struct type to a mail address.pull/2802/head
parent
73b7900fee
commit
fe4bfc1c75
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
// StringToMailAddressFunc decodes a string into a mail.Address.
|
||||
func StringToMailAddressFunc() mapstructure.DecodeHookFunc {
|
||||
return func(f reflect.Kind, t reflect.Kind, data interface{}) (value interface{}, err error) {
|
||||
if f != reflect.String || t != reflect.TypeOf(mail.Address{}).Kind() {
|
||||
return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) {
|
||||
if f.Kind() != reflect.String || t != reflect.TypeOf(mail.Address{}) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -254,6 +254,47 @@ func TestShouldHandleErrInvalidatorWhenSMTPSenderBlank(t *testing.T) {
|
|||
|
||||
assert.Equal(t, "", config.Notifier.SMTP.Sender.Name)
|
||||
assert.Equal(t, "", config.Notifier.SMTP.Sender.Address)
|
||||
|
||||
validator.ValidateNotifier(config.Notifier, val)
|
||||
|
||||
require.Len(t, val.Errors(), 1)
|
||||
assert.Len(t, val.Warnings(), 0)
|
||||
|
||||
assert.EqualError(t, val.Errors()[0], "smtp notifier: the 'sender' must be configured")
|
||||
}
|
||||
|
||||
func TestShouldDecodeSMTPSenderWithoutName(t *testing.T) {
|
||||
testReset()
|
||||
|
||||
val := schema.NewStructValidator()
|
||||
keys, config, err := Load(val, NewDefaultSources([]string{"./test_resources/config.yml"}, DefaultEnvPrefix, DefaultEnvDelimiter)...)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
validator.ValidateKeys(keys, DefaultEnvPrefix, val)
|
||||
|
||||
assert.Len(t, val.Errors(), 0)
|
||||
assert.Len(t, val.Warnings(), 0)
|
||||
|
||||
assert.Equal(t, "", config.Notifier.SMTP.Sender.Name)
|
||||
assert.Equal(t, "admin@example.com", config.Notifier.SMTP.Sender.Address)
|
||||
}
|
||||
|
||||
func TestShouldDecodeSMTPSenderWithName(t *testing.T) {
|
||||
testReset()
|
||||
|
||||
val := schema.NewStructValidator()
|
||||
keys, config, err := Load(val, NewDefaultSources([]string{"./test_resources/config_alt.yml"}, DefaultEnvPrefix, DefaultEnvDelimiter)...)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
validator.ValidateKeys(keys, DefaultEnvPrefix, val)
|
||||
|
||||
assert.Len(t, val.Errors(), 0)
|
||||
assert.Len(t, val.Warnings(), 0)
|
||||
|
||||
assert.Equal(t, "Admin", config.Notifier.SMTP.Sender.Name)
|
||||
assert.Equal(t, "admin@example.com", config.Notifier.SMTP.Sender.Address)
|
||||
}
|
||||
|
||||
func TestShouldNotReadConfigurationOnFSAccessDenied(t *testing.T) {
|
||||
|
|
|
@ -119,6 +119,6 @@ notifier:
|
|||
username: test
|
||||
host: 127.0.0.1
|
||||
port: 1025
|
||||
sender: admin@example.com
|
||||
sender: Admin <admin@example.com>
|
||||
disable_require_tls: true
|
||||
...
|
||||
|
|
Loading…
Reference in New Issue