a3ff3eb193
Simple email validation before attempting to send notifications. If the email is not valid, skip sending notifications and go to update email_sent so we don't try it again. Also, move ValidateEmail function into new package so it can be used in nodeevents without import cycle. Change-Id: I63ce0fc84f7b1d964f7cc6da61206f54baaf1a21
51 lines
983 B
Go
51 lines
983 B
Go
// Copyright (C) 2022 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package utils_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"storj.io/storj/satellite/console/consoleweb/consoleapi/utils"
|
|
)
|
|
|
|
func TestEmailValidation(t *testing.T) {
|
|
invalidEmailAddresses := []string{
|
|
"test@t@t.test",
|
|
"test",
|
|
"test@!t.test",
|
|
"test@#test.test",
|
|
"test@$t.test",
|
|
"t%t.test",
|
|
"test@^test.test",
|
|
"test@&test.test",
|
|
"test@*test.test",
|
|
"test@(test.test",
|
|
"test@)test.test",
|
|
"test@=test.test",
|
|
"test@[test.test",
|
|
"test@]test.test",
|
|
"test@{test.test",
|
|
"test@}test.test",
|
|
"test@/test.test",
|
|
"test@\\test.test",
|
|
"test@|test.test",
|
|
"test@:test.test",
|
|
"test@;test.test",
|
|
"test@,test.test",
|
|
"test@\"test.test",
|
|
"test@'test.test",
|
|
"test@<test.test",
|
|
"test@>test.test",
|
|
"test@_test.test",
|
|
"test@?test.test",
|
|
}
|
|
|
|
for _, e := range invalidEmailAddresses {
|
|
result := utils.ValidateEmail(e)
|
|
require.False(t, result)
|
|
}
|
|
}
|