Merge pull request #2187 from internetee/2185-mail-validation-event-threshold-not-applied

2185 mail validation event threshold not applied
This commit is contained in:
Timo Võhmar 2021-10-22 15:40:02 +03:00 committed by GitHub
commit 38ceccfadc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 9 deletions

View file

@ -27,8 +27,14 @@ module Domains
end end
def contact_emails_valid?(domain) def contact_emails_valid?(domain)
domain.contacts.all(&:need_to_lift_force_delete?) && flag = nil
domain.registrant.need_to_lift_force_delete?
domain.contacts.each do |c|
flag = c.need_to_lift_force_delete?
return flag unless flag
end
flag && domain.registrant.need_to_lift_force_delete?
end end
def bounces_absent?(domain) def bounces_absent?(domain)

View file

@ -9,12 +9,20 @@ module EmailVerifable
need_to_start_force_delete? need_to_start_force_delete?
end end
def validate_email_data(level:, count:)
validation_events.recent.order(id: :desc).limit(count).all? do |event|
event.check_level == level.to_s && event.failed?
end
end
def need_to_start_force_delete? def need_to_start_force_delete?
ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.any? do |level, count| ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.each do |level, count|
validation_events.recent.order(id: :desc).limit(count).all? do |event| if validation_events.recent.count >= count && validate_email_data(level: level, count: count)
event.check_level == level.to_s && event.failed? return true
end end
end end
false
end end
def need_to_lift_force_delete? def need_to_lift_force_delete?

View file

@ -50,7 +50,7 @@ def prepare_contacts(options)
if options[:domain_name].present? if options[:domain_name].present?
contacts_by_domain(options[:domain_name]) contacts_by_domain(options[:domain_name])
else else
Contact.recently_not_validated Contact.all
end end
end end
@ -58,7 +58,7 @@ def contacts_by_domain(domain_name)
domain = ::Domain.find_by(name: domain_name) domain = ::Domain.find_by(name: domain_name)
return unless domain return unless domain
domain.contacts.recently_not_validated domain.contacts
end end
def opts_hash def opts_hash

View file

@ -136,6 +136,7 @@ class BouncedMailAddressTest < ActiveSupport::TestCase
BouncedMailAddress.record(sns_bounce_payload) BouncedMailAddress.record(sns_bounce_payload)
bounced_mail = BouncedMailAddress.last bounced_mail = BouncedMailAddress.last
registrant = domains(:shop).registrant registrant = domains(:shop).registrant
registrant.verify_email(check_level: 'smtp')
assert_equal registrant.email, bounced_mail.email assert_equal registrant.email, bounced_mail.email
assert registrant.email_verification_failed? assert registrant.email_verification_failed?

View file

@ -20,7 +20,9 @@ class ValidationEventTest < ActiveSupport::TestCase
contact = @domain.admin_contacts.first contact = @domain.admin_contacts.first
contact.update_attribute(:email, email) contact.update_attribute(:email, email)
contact.verify_email (ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD).times do
contact.verify_email
end
contact.reload contact.reload
refute contact.validation_events.last.success? refute contact.validation_events.last.success?
@ -42,6 +44,24 @@ class ValidationEventTest < ActiveSupport::TestCase
assert contact.validation_events.last.success? assert contact.validation_events.last.success?
end end
def test_fd_didnt_set_if_mx_interation_less_then_value
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
email = 'email@somestrangedomain12345.ee'
contact = @domain.admin_contacts.first
contact.update_attribute(:email, email)
(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD - 1).times do
contact.verify_email(check_level: 'mx')
end
contact.reload
refute contact.validation_events.limit(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD)
.any?(&:success?)
assert_not contact.need_to_start_force_delete?
end
def test_if_fd_need_to_be_set_if_invalid_mx def test_if_fd_need_to_be_set_if_invalid_mx
@domain.update(valid_to: Time.zone.parse('2012-08-05')) @domain.update(valid_to: Time.zone.parse('2012-08-05'))
assert_not @domain.force_delete_scheduled? assert_not @domain.force_delete_scheduled?