mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
added ability to validate invalid mx email by a and aaaa records
This commit is contained in:
parent
2d2134f83c
commit
9268206daf
6 changed files with 80 additions and 20 deletions
33
app/interactions/actions/a_and_aaaa_email_validation.rb
Normal file
33
app/interactions/actions/a_and_aaaa_email_validation.rb
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
module Actions
|
||||||
|
module AAndAaaaEmailValidation
|
||||||
|
extend self
|
||||||
|
|
||||||
|
def call(email:, value:)
|
||||||
|
check_for_records_value(email: email, value: value)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def check_for_records_value(email:, value:)
|
||||||
|
email = Mail::Address.new(email).domain
|
||||||
|
result = nil
|
||||||
|
dns_servers = ENV['dnssec_resolver_ips'].to_s.split(',').map(&:strip)
|
||||||
|
|
||||||
|
Resolv::DNS.open({ nameserver: dns_servers }) do |dns|
|
||||||
|
dns.timeouts = ENV['a_and_aaaa_validation_timeout'].to_i || 1
|
||||||
|
ress = nil
|
||||||
|
|
||||||
|
case value
|
||||||
|
when 'A'
|
||||||
|
ress = dns.getresources email, Resolv::DNS::Resource::IN::A
|
||||||
|
when 'AAAA'
|
||||||
|
ress = dns.getresources email, Resolv::DNS::Resource::IN::AAAA
|
||||||
|
end
|
||||||
|
|
||||||
|
result = ress.map { |r| r.address }
|
||||||
|
end
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -20,10 +20,10 @@ module Actions
|
||||||
return if Rails.env.test?
|
return if Rails.env.test?
|
||||||
|
|
||||||
[:regex, :mx].each do |m|
|
[:regex, :mx].each do |m|
|
||||||
r = Actions::SimpleMailValidator.run(email: contact.email, level: m)
|
result = Actions::SimpleMailValidator.run(email: contact.email, level: m)
|
||||||
|
|
||||||
unless r.success
|
unless result
|
||||||
contact.add_epp_error('2005', nil, r.errors, I18n.t(:parameter_value_syntax_error))
|
contact.add_epp_error('2005', nil, "email didn't pass validation", I18n.t(:parameter_value_syntax_error))
|
||||||
@error = true
|
@error = true
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,10 +24,10 @@ module Actions
|
||||||
return if Rails.env.test?
|
return if Rails.env.test?
|
||||||
|
|
||||||
[:regex, :mx].each do |m|
|
[:regex, :mx].each do |m|
|
||||||
r = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m)
|
result = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m)
|
||||||
|
|
||||||
unless r.success
|
unless result
|
||||||
contact.add_epp_error('2005', nil, r.errors, I18n.t(:parameter_value_syntax_error))
|
contact.add_epp_error('2005', nil, "email didn't pass validation", I18n.t(:parameter_value_syntax_error))
|
||||||
@error = true
|
@error = true
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,18 +51,17 @@ module Actions
|
||||||
|
|
||||||
def save_result(result)
|
def save_result(result)
|
||||||
if !result.success && @check_level == "mx"
|
if !result.success && @check_level == "mx"
|
||||||
email_domain = Mail::Address.new(@email).domain
|
result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'A')
|
||||||
|
output_a_and_aaaa_validation_results(email: @email,
|
||||||
|
result: result_validation,
|
||||||
|
type: 'A') unless Rails.env.test?
|
||||||
|
|
||||||
result_validation = check_for_records_value(domain: email_domain, value: 'A')
|
result_validation = Actions::AAndAaaaEmailValidation.call(email: @email, value: 'AAAA') if result_validation.empty?
|
||||||
logger.info "Validated A record for #{email_domain}. Validation result - #{result_validation}"
|
output_a_and_aaaa_validation_results(email: @email,
|
||||||
p "Validated A record for #{email_domain}. Validation result - #{result_validation}"
|
result: result_validation,
|
||||||
|
type: 'AAAA') unless Rails.env.test?
|
||||||
result_validation = check_for_records_value(domain: email_domain, value: 'AAAA') if result_validation.empty?
|
|
||||||
logger.info "Validated AAAA record for #{email_domain}. Validation result - #{result_validation}" if result_validation.empty?
|
|
||||||
p "Validated AAAA record for #{email_domain}. Validation result - #{result_validation}" if result_validation.empty?
|
|
||||||
|
|
||||||
result_validation.present? ? result.success = true : result.success = false
|
result_validation.present? ? result.success = true : result.success = false
|
||||||
|
|
||||||
validation_eventable.validation_events.create(validation_event_attrs(result))
|
validation_eventable.validation_events.create(validation_event_attrs(result))
|
||||||
else
|
else
|
||||||
validation_eventable.validation_events.create(validation_event_attrs(result))
|
validation_eventable.validation_events.create(validation_event_attrs(result))
|
||||||
|
@ -72,6 +71,10 @@ module Actions
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def output_a_and_aaaa_validation_results(email:, result:, type: )
|
||||||
|
logger.info "Validated #{type} record for #{email}. Validation result - #{result}"
|
||||||
|
end
|
||||||
|
|
||||||
def check_for_records_value(domain:, value:)
|
def check_for_records_value(domain:, value:)
|
||||||
result = nil
|
result = nil
|
||||||
dns_servers = ENV['dnssec_resolver_ips'].to_s.split(',').map(&:strip)
|
dns_servers = ENV['dnssec_resolver_ips'].to_s.split(',').map(&:strip)
|
||||||
|
|
|
@ -3,7 +3,31 @@ module Actions
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def run(email:, level:)
|
def run(email:, level:)
|
||||||
Truemail.validate(email, with: level).result
|
result = Truemail.validate(email, with: level).result.success
|
||||||
|
result = validate_for_a_and_aaaa_records(email) if !result && level == :mx
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_for_a_and_aaaa_records(email)
|
||||||
|
result_validation = Actions::AAndAaaaEmailValidation.call(email: email, value: 'A')
|
||||||
|
output_a_and_aaaa_validation_results(email: email,
|
||||||
|
result: result_validation,
|
||||||
|
type: 'A') unless Rails.env.test?
|
||||||
|
|
||||||
|
result_validation = Actions::AAndAaaaEmailValidation.call(email: email, value: 'AAAA') if result_validation.empty?
|
||||||
|
output_a_and_aaaa_validation_results(email: email,
|
||||||
|
result: result_validation,
|
||||||
|
type: 'AAAA') unless Rails.env.test?
|
||||||
|
|
||||||
|
result_validation.present? ? true : false
|
||||||
|
end
|
||||||
|
|
||||||
|
def output_a_and_aaaa_validation_results(email:, result:, type: )
|
||||||
|
logger.info "Validated #{type} record for #{email}. Validation result - #{result}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def logger
|
||||||
|
@logger ||= Rails.logger
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ class DoRequestTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||||
Spy.on_instance_method(Actions::EmailCheck, :check_for_records_value).and_return([true])
|
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([true])
|
||||||
|
|
||||||
action = Actions::EmailCheck.new(email: @contact.email,
|
action = Actions::EmailCheck.new(email: @contact.email,
|
||||||
validation_eventable: @contact,
|
validation_eventable: @contact,
|
||||||
|
@ -35,7 +35,7 @@ class DoRequestTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||||
Spy.on_instance_method(Actions::EmailCheck, :check_for_records_value).and_return([])
|
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([])
|
||||||
|
|
||||||
action = Actions::EmailCheck.new(email: @contact.email,
|
action = Actions::EmailCheck.new(email: @contact.email,
|
||||||
validation_eventable: @contact,
|
validation_eventable: @contact,
|
||||||
|
@ -54,7 +54,7 @@ class DoRequestTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||||
Spy.on_instance_method(Actions::EmailCheck, :check_for_records_value).and_return([])
|
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([])
|
||||||
|
|
||||||
action = Actions::EmailCheck.new(email: @contact.email,
|
action = Actions::EmailCheck.new(email: @contact.email,
|
||||||
validation_eventable: @contact,
|
validation_eventable: @contact,
|
||||||
|
@ -82,7 +82,7 @@ class DoRequestTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||||
Spy.on_instance_method(Actions::EmailCheck, :check_for_records_value).and_return([true])
|
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([true])
|
||||||
|
|
||||||
action = Actions::EmailCheck.new(email: @contact.email,
|
action = Actions::EmailCheck.new(email: @contact.email,
|
||||||
validation_eventable: @contact,
|
validation_eventable: @contact,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue