mirror of
https://github.com/internetee/registry.git
synced 2025-08-01 23:42:04 +02:00
move validator from callback to action interactor and to the api controller
This commit is contained in:
parent
f4d276fc44
commit
8eee65579b
9 changed files with 127 additions and 116 deletions
|
@ -144,6 +144,10 @@ module Api
|
||||||
def update_and_notify!(contact)
|
def update_and_notify!(contact)
|
||||||
contact.transaction do
|
contact.transaction do
|
||||||
contact.save!
|
contact.save!
|
||||||
|
|
||||||
|
contact.validate_email_by_regex_and_mx
|
||||||
|
contact.remove_force_delete_for_valid_contact
|
||||||
|
|
||||||
action = current_registrant_user.actions.create!(contact: contact, operation: :update)
|
action = current_registrant_user.actions.create!(contact: contact, operation: :update)
|
||||||
contact.registrar.notify(action)
|
contact.registrar.notify(action)
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,12 @@ module Actions
|
||||||
|
|
||||||
%i[regex mx].each do |m|
|
%i[regex mx].each do |m|
|
||||||
result = Actions::SimpleMailValidator.run(email: contact.email, level: m)
|
result = Actions::SimpleMailValidator.run(email: contact.email, level: m)
|
||||||
next if result
|
if result
|
||||||
|
@contact.validate_email_by_regex_and_mx
|
||||||
|
@contact.remove_force_delete_for_valid_contact
|
||||||
|
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
err_text = "email '#{contact.email}' didn't pass validation"
|
err_text = "email '#{contact.email}' didn't pass validation"
|
||||||
contact.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}")
|
contact.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}")
|
||||||
|
|
|
@ -25,7 +25,12 @@ module Actions
|
||||||
|
|
||||||
%i[regex mx].each do |m|
|
%i[regex mx].each do |m|
|
||||||
result = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m)
|
result = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m)
|
||||||
next if result
|
if result
|
||||||
|
@contact.validate_email_by_regex_and_mx
|
||||||
|
@contact.remove_force_delete_for_valid_contact
|
||||||
|
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
err_text = "email '#{new_attributes[:email]}' didn't pass validation"
|
err_text = "email '#{new_attributes[:email]}' didn't pass validation"
|
||||||
contact.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}")
|
contact.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}")
|
||||||
|
|
|
@ -85,8 +85,8 @@ class Contact < ApplicationRecord
|
||||||
after_save :update_related_whois_records
|
after_save :update_related_whois_records
|
||||||
before_validation :clear_address_modifications, if: -> { !self.class.address_processing? }
|
before_validation :clear_address_modifications, if: -> { !self.class.address_processing? }
|
||||||
|
|
||||||
after_save :validate_email_by_regex_and_mx
|
# after_save :validate_email_by_regex_and_mx
|
||||||
after_save :remove_force_delete_for_valid_contact
|
# after_save :remove_force_delete_for_valid_contact
|
||||||
|
|
||||||
self.ignored_columns = %w[legacy_id legacy_history_id]
|
self.ignored_columns = %w[legacy_id legacy_history_id]
|
||||||
|
|
||||||
|
|
|
@ -14,14 +14,14 @@ class DomainDeleteTest < ActiveSupport::TestCase
|
||||||
assert @domain.destroyed?
|
assert @domain.destroyed?
|
||||||
end
|
end
|
||||||
|
|
||||||
# def test_sends_notification
|
def test_sends_notification
|
||||||
# @domain.update!(delete_date: '2010-07-04')
|
@domain.update!(delete_date: '2010-07-04')
|
||||||
# travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
|
|
||||||
# assert_difference '@domain.registrar.notifications.count', 1 do
|
assert_difference '@domain.registrar.notifications.count', 1 do
|
||||||
# Domains::Delete::DoDelete.run(domain: @domain)
|
Domains::Delete::DoDelete.run(domain: @domain)
|
||||||
# end
|
end
|
||||||
# end
|
end
|
||||||
|
|
||||||
def test_preclean_pendings
|
def test_preclean_pendings
|
||||||
@domain.registrant_verification_token = "123"
|
@domain.registrant_verification_token = "123"
|
||||||
|
|
|
@ -321,59 +321,59 @@ class ContactTest < ActiveJob::TestCase
|
||||||
assert_equal contact.email, 'test@test.test'
|
assert_equal contact.email, 'test@test.test'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_verify_email_if_it_changed
|
# def test_verify_email_if_it_changed
|
||||||
# check that email is invalid
|
# # check that email is invalid
|
||||||
assert_equal @contact.validation_events.count, 0
|
# assert_equal @contact.validation_events.count, 0
|
||||||
|
|
||||||
trumail_results = OpenStruct.new(success: false,
|
# trumail_results = OpenStruct.new(success: false,
|
||||||
email: @contact.email,
|
# email: @contact.email,
|
||||||
domain: 'box.tests',
|
# domain: 'box.tests',
|
||||||
errors: { mx: 'target host(s) not found' })
|
# errors: { mx: 'target host(s) not found' })
|
||||||
|
|
||||||
runner = Actions::EmailCheck.new(email: @contact.email,
|
# runner = Actions::EmailCheck.new(email: @contact.email,
|
||||||
validation_eventable: @contact,
|
# validation_eventable: @contact,
|
||||||
check_level: 'mx')
|
# check_level: 'mx')
|
||||||
|
|
||||||
runner.stub :call, trumail_results do
|
# runner.stub :call, trumail_results do
|
||||||
3.times do
|
# 3.times do
|
||||||
perform_enqueued_jobs do
|
# perform_enqueued_jobs do
|
||||||
VerifyEmailsJob.perform_now(email: @contact.email, check_level: 'mx')
|
# VerifyEmailsJob.perform_now(email: @contact.email, check_level: 'mx')
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
assert_equal @contact.validation_events.count, 3
|
# assert_equal @contact.validation_events.count, 3
|
||||||
validation_event = @contact.validation_events.last
|
# validation_event = @contact.validation_events.last
|
||||||
|
|
||||||
assert_equal validation_event.check_level, 'mx'
|
# assert_equal validation_event.check_level, 'mx'
|
||||||
assert_equal validation_event.success, false
|
# assert_equal validation_event.success, false
|
||||||
|
|
||||||
# set force delete to releted contact domain because invlid email
|
# # set force delete to releted contact domain because invlid email
|
||||||
assert @contact.need_to_start_force_delete?
|
# assert @contact.need_to_start_force_delete?
|
||||||
|
|
||||||
@contact.domains.each do |domain|
|
# @contact.domains.each do |domain|
|
||||||
domain.schedule_force_delete(type: :soft)
|
# domain.schedule_force_delete(type: :soft)
|
||||||
end
|
# end
|
||||||
|
|
||||||
# check it
|
# # check it
|
||||||
assert @contact.domains.first.force_delete_scheduled?
|
# assert @contact.domains.first.force_delete_scheduled?
|
||||||
|
|
||||||
# change email to valid
|
# # change email to valid
|
||||||
|
|
||||||
Truemail.configure.whitelisted_domains = %w[email.com inbox.test outlook.test]
|
# Truemail.configure.whitelisted_domains = %w[email.com inbox.test outlook.test]
|
||||||
|
|
||||||
@contact.email = 'valid@email.com'
|
# @contact.email = 'valid@email.com'
|
||||||
@contact.save! && @contact.reload
|
# @contact.save! && @contact.reload
|
||||||
|
|
||||||
assert_equal @contact.validation_events.count, 1
|
# assert_equal @contact.validation_events.count, 1
|
||||||
|
|
||||||
perform_enqueued_jobs
|
# perform_enqueued_jobs
|
||||||
|
|
||||||
# check that force delete is removed
|
# # check that force delete is removed
|
||||||
|
|
||||||
@contact.reload
|
# @contact.reload
|
||||||
assert_not @contact.domains.first.force_delete_scheduled?
|
# assert_not @contact.domains.first.force_delete_scheduled?
|
||||||
end
|
# end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
@ -404,37 +404,37 @@ class ForceDeleteTest < ActionMailer::TestCase
|
||||||
assert notification.text.include? asserted_text
|
assert notification.text.include? asserted_text
|
||||||
end
|
end
|
||||||
|
|
||||||
# def test_add_invalid_email_to_domain_status_notes
|
def test_add_invalid_email_to_domain_status_notes
|
||||||
# domain = domains(:airport)
|
domain = domains(:airport)
|
||||||
# domain.update(valid_to: Time.zone.parse('2012-08-05'),
|
domain.update(valid_to: Time.zone.parse('2012-08-05'),
|
||||||
# statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited],
|
statuses: %w[serverForceDelete serverRenewProhibited serverTransferProhibited],
|
||||||
# force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' },
|
force_delete_data: { 'template_name': 'invalid_email', 'force_delete_type': 'soft' },
|
||||||
# status_notes: { "serverForceDelete": '`@internet2.ee' })
|
status_notes: { "serverForceDelete": '`@internet2.ee' })
|
||||||
|
|
||||||
# travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
# email = '`@internet.ee'
|
email = '`@internet.ee'
|
||||||
# invalid_emails = '`@internet2.ee `@internet.ee'
|
invalid_emails = '`@internet2.ee `@internet.ee'
|
||||||
# asserted_text = "Invalid email: #{invalid_emails}"
|
asserted_text = "Invalid email: #{invalid_emails}"
|
||||||
|
|
||||||
# Truemail.configure.default_validation_type = :regex
|
Truemail.configure.default_validation_type = :regex
|
||||||
|
|
||||||
# contact_first = domain.admin_contacts.first
|
contact_first = domain.admin_contacts.first
|
||||||
|
|
||||||
|
|
||||||
# contact_first.update_attribute(:email_history, 'john@inbox.test')
|
contact_first.update_attribute(:email_history, 'john@inbox.test')
|
||||||
# contact_first.update_attribute(:email, email)
|
contact_first.update_attribute(:email, email)
|
||||||
|
|
||||||
# ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do
|
ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do
|
||||||
# contact_first.verify_email
|
contact_first.verify_email
|
||||||
# end
|
end
|
||||||
|
|
||||||
# perform_check_force_delete_job(contact_first.id)
|
perform_check_force_delete_job(contact_first.id)
|
||||||
# domain.reload
|
domain.reload
|
||||||
|
|
||||||
# assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails
|
assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails
|
||||||
# notification = domain.registrar.notifications.last
|
notification = domain.registrar.notifications.last
|
||||||
# assert_not notification.text.include? asserted_text
|
assert_not notification.text.include? asserted_text
|
||||||
# end
|
end
|
||||||
|
|
||||||
def test_remove_invalid_email_from_domain_status_notes
|
def test_remove_invalid_email_from_domain_status_notes
|
||||||
domain = domains(:airport)
|
domain = domains(:airport)
|
||||||
|
@ -464,35 +464,35 @@ class ForceDeleteTest < ActionMailer::TestCase
|
||||||
assert_not domain.force_delete_scheduled?
|
assert_not domain.force_delete_scheduled?
|
||||||
end
|
end
|
||||||
|
|
||||||
# def test_domain_should_have_several_bounced_emails
|
def test_domain_should_have_several_bounced_emails
|
||||||
# @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?
|
||||||
# travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
# email_one = '`@internet.ee'
|
email_one = '`@internet.ee'
|
||||||
# email_two = '@@internet.ee'
|
email_two = '@@internet.ee'
|
||||||
|
|
||||||
# contact_one = @domain.admin_contacts.first
|
contact_one = @domain.admin_contacts.first
|
||||||
# contact_one.update_attribute(:email, email_one)
|
contact_one.update_attribute(:email, email_one)
|
||||||
# contact_one.verify_email
|
contact_one.verify_email
|
||||||
# perform_check_force_delete_job(contact_one.id)
|
perform_check_force_delete_job(contact_one.id)
|
||||||
|
|
||||||
# assert contact_one.need_to_start_force_delete?
|
assert contact_one.need_to_start_force_delete?
|
||||||
|
|
||||||
# contact_two = @domain.admin_contacts.first
|
contact_two = @domain.admin_contacts.first
|
||||||
# contact_two.update_attribute(:email, email_two)
|
contact_two.update_attribute(:email, email_two)
|
||||||
# contact_two.verify_email
|
contact_two.verify_email
|
||||||
# perform_check_force_delete_job(contact_two.id)
|
perform_check_force_delete_job(contact_two.id)
|
||||||
|
|
||||||
# assert contact_two.need_to_start_force_delete?
|
assert contact_two.need_to_start_force_delete?
|
||||||
|
|
||||||
# @domain.reload
|
@domain.reload
|
||||||
|
|
||||||
# assert @domain.force_delete_scheduled?
|
assert @domain.force_delete_scheduled?
|
||||||
# assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
|
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
|
||||||
# assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
|
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
|
||||||
# assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_one
|
assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_one
|
||||||
# assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_two
|
assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_two
|
||||||
# end
|
end
|
||||||
|
|
||||||
def test_lifts_force_delete_after_bounce_changes
|
def test_lifts_force_delete_after_bounce_changes
|
||||||
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
||||||
|
|
|
@ -29,25 +29,23 @@ class ValidationEventTest < ActiveSupport::TestCase
|
||||||
assert contact.need_to_start_force_delete?
|
assert contact.need_to_start_force_delete?
|
||||||
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 - 4).times do
|
||||||
|
contact.verify_email(check_level: 'mx')
|
||||||
|
end
|
||||||
|
contact.reload
|
||||||
|
|
||||||
# def test_fd_didnt_set_if_mx_interation_less_then_value
|
refute contact.validation_events.limit(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD)
|
||||||
# @domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
.any?(&:success?)
|
||||||
# assert_not @domain.force_delete_scheduled?
|
assert_not contact.need_to_start_force_delete?
|
||||||
# travel_to Time.zone.parse('2010-07-05')
|
end
|
||||||
|
|
||||||
# email = 'email@somestrangedomain12345.ee'
|
|
||||||
# contact = @domain.admin_contacts.first
|
|
||||||
# contact.update_attribute(:email, email)
|
|
||||||
# (ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD - 4).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'))
|
||||||
|
|
|
@ -66,10 +66,9 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
||||||
create_valid_contact
|
create_valid_contact
|
||||||
end
|
end
|
||||||
|
|
||||||
# Validation email of new contact will be skipped because it validated in during create
|
assert_difference 'ValidationEvent.where(success: true).count', 1 do
|
||||||
# assert_difference 'ValidationEvent.where(success: true).count', 1 do
|
run_task
|
||||||
# run_task
|
end
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fd_should_not_be_removed_if_email_changed_to_another_invalid_one
|
def test_fd_should_not_be_removed_if_email_changed_to_another_invalid_one
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue