diff --git a/config/config_test.go b/config/config_test.go index 7631d37c..7aba475f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -200,7 +200,7 @@ receivers: func TestTimeIntervalHasName(t *testing.T) { in := ` time_intervals: -- name: +- name: time_intervals: - times: - start_time: '09:00' diff --git a/config/notifiers_test.go b/config/notifiers_test.go index 199d1ce3..de1bb5f9 100644 --- a/config/notifiers_test.go +++ b/config/notifiers_test.go @@ -15,6 +15,8 @@ package config import ( "errors" + "net/mail" + "reflect" "strings" "testing" @@ -60,6 +62,47 @@ headers: } } +func TestEmailToAllowsMultipleAdresses(t *testing.T) { + in := ` +to: 'a@example.com, ,b@example.com,c@example.com' +` + var cfg EmailConfig + err := yaml.UnmarshalStrict([]byte(in), &cfg) + if err != nil { + t.Fatal(err) + } + + expected := []*mail.Address{ + {Address: "a@example.com"}, + {Address: "b@example.com"}, + {Address: "c@example.com"}, + } + + res, err := mail.ParseAddressList(cfg.To) + if err != nil { + t.Fatal(err) + } + + if !reflect.DeepEqual(res, expected) { + t.Fatalf("expected %v, got %v", expected, res) + } +} + +func TestEmailDisallowMalformed(t *testing.T) { + in := ` +to: 'a@' +` + var cfg EmailConfig + err := yaml.UnmarshalStrict([]byte(in), &cfg) + if err != nil { + t.Fatal(err) + } + _, err = mail.ParseAddressList(cfg.To) + if err == nil { + t.Fatalf("no error returned, expected:\n%v", "mail: no angle-addr") + } +} + func TestPagerdutyTestRoutingKey(t *testing.T) { t.Run("error if no routing key or key file", func(t *testing.T) { in := ` diff --git a/docs/configuration.md b/docs/configuration.md index b68ac16f..fa987839 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -487,7 +487,7 @@ You can use this mode if you suspect there is an issue with fallback mode or UTF You can use `amtool` to validate that an Alertmanager configuration file is compatible with UTF-8 strict mode before enabling it in Alertmanager server. You do not need a running Alertmanager server to do this. -Just like Alertmanager server, `amtool` will log a warning if the configuration is incompatible or contains disagreement: +Just like Alertmanager server, `amtool` will log a warning if the configuration is incompatible or contains disagreement: ``` amtool check-config config.yml @@ -503,7 +503,7 @@ Found: - 0 templates ``` -You will know if a configuration is compatible with UTF-8 strict mode when no warnings are logged in `amtool`: +You will know if a configuration is compatible with UTF-8 strict mode when no warnings are logged in `amtool`: ``` amtool check-config config.yml @@ -644,7 +644,7 @@ Here are some more examples: ``` As shown below, in the short-form, it's better to use double quotes to avoid problems with special characters like commas: - + ```yaml matchers: [ "foo = \"bar,baz\"", "dings != bums" ] ``` @@ -867,6 +867,7 @@ webhook_url_file: [ send_resolved: | default = false ] # The email address to send notifications to. +# Allows a comma separated list of rfc5322 compliant email addresses. to: # The sender's address. @@ -1458,6 +1459,6 @@ room_id: # Message template. [ message: default = '{{ template "webex.default.message" .}}' ] -# The HTTP client's configuration. You must use this configuration to supply the bot token as part of the HTTP `Authorization` header. +# The HTTP client's configuration. You must use this configuration to supply the bot token as part of the HTTP `Authorization` header. [ http_config: | default = global.http_config ] ```