Fix: Allow example@email.com without angle brackets in contact points
This commit is contained in:
@@ -24,7 +24,7 @@ type emailSender struct {
|
|||||||
// isPlaceholderEmail checks if the given email address is a placeholder that should not be sent
|
// isPlaceholderEmail checks if the given email address is a placeholder that should not be sent
|
||||||
func isPlaceholderEmail(email string) bool {
|
func isPlaceholderEmail(email string) bool {
|
||||||
trimmed := strings.TrimSpace(email)
|
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 {
|
func (s emailSender) SendEmail(ctx context.Context, cmd *receivers.SendEmailSettings) error {
|
||||||
|
|||||||
@@ -18,21 +18,21 @@ func TestIsPlaceholderEmail(t *testing.T) {
|
|||||||
email string
|
email string
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "placeholder with angle brackets",
|
name: "placeholder with angle brackets",
|
||||||
email: "<example@email.com>",
|
email: "<example@email.com>",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "placeholder without angle brackets",
|
name: "not a placeholder - example@email.com without angle brackets",
|
||||||
email: "example@email.com",
|
email: "example@email.com",
|
||||||
expected: true,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "placeholder with spaces",
|
name: "placeholder with spaces",
|
||||||
email: " <example@email.com> ",
|
email: " <example@email.com> ",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid email",
|
name: "valid email",
|
||||||
email: "user@example.com",
|
email: "user@example.com",
|
||||||
@@ -118,20 +118,20 @@ func TestEmailSender_SendEmail_PlaceholderHandling(t *testing.T) {
|
|||||||
expectedRecips: []string{"user@example.com", "admin@grafana.com"},
|
expectedRecips: []string{"user@example.com", "admin@grafana.com"},
|
||||||
description: "Should send to all valid addresses",
|
description: "Should send to all valid addresses",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple placeholders with one valid",
|
name: "placeholder with angle brackets filtered, others sent",
|
||||||
recipients: []string{"example@email.com", "<example@email.com>", "valid@example.com"},
|
recipients: []string{"example@email.com", "<example@email.com>", "valid@example.com"},
|
||||||
expectSend: true,
|
expectSend: true,
|
||||||
expectedRecips: []string{"valid@example.com"},
|
expectedRecips: []string{"example@email.com", "valid@example.com"},
|
||||||
description: "Should filter out all placeholder variations and send to valid address",
|
description: "Should filter out only placeholder with angle brackets and send to other addresses",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "only placeholders without angle brackets",
|
name: "example@email.com without angle brackets is valid",
|
||||||
recipients: []string{"example@email.com"},
|
recipients: []string{"example@email.com"},
|
||||||
expectSend: false,
|
expectSend: true,
|
||||||
expectedRecips: nil,
|
expectedRecips: []string{"example@email.com"},
|
||||||
description: "Should skip sending when placeholder is without angle brackets",
|
description: "Should send to example@email.com when it doesn't have angle brackets",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
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.
|
* Placeholder emails that ship with the default grafana-default-email contact point.
|
||||||
* These should not trigger actual email sends or throw errors.
|
* 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.
|
* Check if a single channel/integration has placeholder email addresses.
|
||||||
|
|||||||
Reference in New Issue
Block a user