Bypass MX validation for explicitly allowed domains (#15930)
* Bypass MX validation for explicitly allowed domains This spares some lookups and prevent issues in some edge cases with local domains. * Add tests * Fix test
This commit is contained in:
parent
d023eefbcc
commit
051efed5ed
3 changed files with 26 additions and 2 deletions
|
@ -10,7 +10,7 @@ class EmailMxValidator < ActiveModel::Validator
|
|||
|
||||
if domain.blank?
|
||||
user.errors.add(:email, :invalid)
|
||||
else
|
||||
elsif !on_allowlist?(domain)
|
||||
ips, hostnames = resolve_mx(domain)
|
||||
|
||||
if ips.empty?
|
||||
|
@ -33,6 +33,12 @@ class EmailMxValidator < ActiveModel::Validator
|
|||
nil
|
||||
end
|
||||
|
||||
def on_allowlist?(domain)
|
||||
return false if Rails.configuration.x.email_domains_whitelist.blank?
|
||||
|
||||
Rails.configuration.x.email_domains_whitelist.include?(domain)
|
||||
end
|
||||
|
||||
def resolve_mx(domain)
|
||||
hostnames = []
|
||||
ips = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue