Commit a3adef7f authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch '326469-improve-recipients-validation-on-EmailsOnPushService' into 'master'

Add recipients validation using Devise

See merge request gitlab-org/gitlab!81377
parents 316d79d9 3163947a
......@@ -13,9 +13,7 @@ module Integrations
validate :number_of_recipients_within_limit, if: :validate_recipients?
def self.valid_recipients(recipients)
recipients.split.select do |recipient|
recipient.include?('@')
end.uniq(&:downcase)
recipients.split.grep(Devise.email_regexp).uniq(&:downcase)
end
def title
......
......@@ -78,9 +78,10 @@ RSpec.describe Integrations::EmailsOnPush do
end
describe '.valid_recipients' do
let(:recipients) { '<invalid> foobar Valid@recipient.com Dup@lica.te dup@lica.te Dup@Lica.te' }
let(:recipients) { '<invalid> foobar valid@dup@asd Valid@recipient.com Dup@lica.te dup@lica.te Dup@Lica.te' }
it 'removes invalid email addresses and removes duplicates by keeping the original capitalization' do
expect(described_class.valid_recipients(recipients)).not_to contain_exactly('valid@dup@asd')
expect(described_class.valid_recipients(recipients)).to contain_exactly('Valid@recipient.com', 'Dup@lica.te')
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment