Fix: Allow example@email.com without angle brackets in contact points

This commit is contained in:
tonypowa
2025-11-06 13:29:01 +01:00
parent e51fb87cc2
commit de1c2ef28e
3 changed files with 31 additions and 31 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ type emailSender struct {
// isPlaceholderEmail checks if the given email address is a placeholder that should not be sent
func isPlaceholderEmail(email string) bool {
trimmed := strings.TrimSpace(email)
return trimmed == placeholderEmailAddress || trimmed == "example@email.com"
return trimmed == placeholderEmailAddress
}
func (s emailSender) SendEmail(ctx context.Context, cmd *receivers.SendEmailSettings) error {
+29 -29
View File
@@ -18,21 +18,21 @@ func TestIsPlaceholderEmail(t *testing.T) {
email string
expected bool
}{
{
name: "placeholder with angle brackets",
email: "<example@email.com>",
expected: true,
},
{
name: "placeholder without angle brackets",
email: "example@email.com",
expected: true,
},
{
name: "placeholder with spaces",
email: " <example@email.com> ",
expected: true,
},
{
name: "placeholder with angle brackets",
email: "<example@email.com>",
expected: true,
},
{
name: "not a placeholder - example@email.com without angle brackets",
email: "example@email.com",
expected: false,
},
{
name: "placeholder with spaces",
email: " <example@email.com> ",
expected: true,
},
{
name: "valid email",
email: "user@example.com",
@@ -118,20 +118,20 @@ func TestEmailSender_SendEmail_PlaceholderHandling(t *testing.T) {
expectedRecips: []string{"user@example.com", "admin@grafana.com"},
description: "Should send to all valid addresses",
},
{
name: "multiple placeholders with one valid",
recipients: []string{"example@email.com", "<example@email.com>", "valid@example.com"},
expectSend: true,
expectedRecips: []string{"valid@example.com"},
description: "Should filter out all placeholder variations and send to valid address",
},
{
name: "only placeholders without angle brackets",
recipients: []string{"example@email.com"},
expectSend: false,
expectedRecips: nil,
description: "Should skip sending when placeholder is without angle brackets",
},
{
name: "placeholder with angle brackets filtered, others sent",
recipients: []string{"example@email.com", "<example@email.com>", "valid@example.com"},
expectSend: true,
expectedRecips: []string{"example@email.com", "valid@example.com"},
description: "Should filter out only placeholder with angle brackets and send to other addresses",
},
{
name: "example@email.com without angle brackets is valid",
recipients: []string{"example@email.com"},
expectSend: true,
expectedRecips: []string{"example@email.com"},
description: "Should send to example@email.com when it doesn't have angle brackets",
},
}
for _, tt := range tests {
@@ -309,7 +309,7 @@ export function omitTemporaryIdentifiers<T>(object: Readonly<T>): T {
* Placeholder emails that ship with the default grafana-default-email contact point.
* These should not trigger actual email sends or throw errors.
*/
const PLACEHOLDER_EMAILS = ['<example@email.com>', 'example@email.com'];
const PLACEHOLDER_EMAILS = ['<example@email.com>'];
/**
* Check if a single channel/integration has placeholder email addresses.