mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Merge pull request #2764 from internetee/2747-multiple-underscores-in-email-addresses
# Improve email validation regex pattern and add comprehensive tests
This commit is contained in:
commit
05210ddbba
2 changed files with 31 additions and 3 deletions
|
@ -8,10 +8,8 @@ Truemail.configure do |config|
|
|||
# By default verifier domain based on verifier email
|
||||
# config.verifier_domain = 'internet.ee'
|
||||
|
||||
# Optional parameter. You can override default regex pattern
|
||||
config.email_pattern = /(?=\A.{6,255}\z)(\A([\p{L}0-9]+[\W\w]*)@(xn--)?((?i-mx:[\p{L}0-9]+([\-.]{1}[\p{L}0-9]+)*\.\p{L}{2,63}))\z)/
|
||||
config.email_pattern = /\A(?=[\p{L}0-9!#$%&'*+\/=?^_{|}~-]*[\p{L}0-9])([\p{L}0-9!#$%&'*+\/=?^_{|}~-]+(?:\.[\p{L}0-9!#$%&'*+\/=?^_{|}~-]+)*)@(?i:(xn--)?(?:[\p{L}0-9][\p{L}0-9-]{0,61}[\p{L}0-9]\.)+[\p{L}]{2,63}|\[[\d.a-fA-F:]+\])\z/
|
||||
|
||||
# Optional parameter. You can override default regex pattern
|
||||
# config.smtp_error_body_pattern = /regex_pattern/
|
||||
|
||||
# Optional parameter. Connection timeout is equal to 2 ms by default.
|
||||
|
|
|
@ -7,6 +7,36 @@ class EmailCheckTest < ActiveSupport::TestCase
|
|||
@contact = contacts(:john)
|
||||
end
|
||||
|
||||
def test_validates_regex_email_format
|
||||
valid_emails = [
|
||||
'user@domain.com',
|
||||
'user_@domain.com',
|
||||
'user.name@domain.com',
|
||||
'hello.world@example.com',
|
||||
'_user.email@domain.com',
|
||||
'__user.email@domain.com',
|
||||
]
|
||||
|
||||
valid_emails.each_with_index do |email, index|
|
||||
assert Actions::EmailCheck.new(email: email, validation_eventable: @contact, check_level: 'regex').call
|
||||
end
|
||||
|
||||
invalid_emails = [
|
||||
'@@domain.com',
|
||||
'`@domain.com',
|
||||
'user..name@domain.com',
|
||||
'.user@domain.com',
|
||||
'user.@domain.com',
|
||||
'us"er@domain.com',
|
||||
'user@domain..com',
|
||||
'~@internet.ee'
|
||||
]
|
||||
|
||||
invalid_emails.each do |email|
|
||||
refute Actions::EmailCheck.new(email: email, validation_eventable: @contact, check_level: 'regex').call
|
||||
end
|
||||
end
|
||||
|
||||
def test_invalid_email_in_mx_level_with_a_and_aaaa_records
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_result)
|
||||
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([true])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue