mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 06:26:15 +02:00
Merge pull request #2635 from internetee/2634-force-delete-status-not-removed-when-invalid-email-was-replaced
added callback force delete check after email update
This commit is contained in:
commit
61ff20594e
16 changed files with 134 additions and 23 deletions
4
.github/workflows/ruby.yml
vendored
4
.github/workflows/ruby.yml
vendored
|
@ -17,7 +17,7 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-22.04]
|
||||
ruby: [ '2.7', '3.0.3' ]
|
||||
ruby: [ '3.0.3' ]
|
||||
runs-on: ${{ matrix.os }}
|
||||
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
||||
steps:
|
||||
|
@ -88,7 +88,7 @@ jobs:
|
|||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
ruby: [ '2.7', '3.0.3' ]
|
||||
ruby: [ '3.0.3' ]
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
env:
|
||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -16,6 +16,5 @@
|
|||
# Do not commit one. Instead, download the latest from https://github.com/internetee/style-guide.
|
||||
.rubocop.yml
|
||||
/lib/tasks/mock.rake
|
||||
|
||||
.DS_Store
|
||||
/node_modules
|
||||
/node_modules
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
FROM internetee/ruby:3.0-buster
|
||||
|
||||
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
git \
|
||||
postgresql-client \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
RUN mkdir -p /opt/webapps/app/tmp/pids
|
||||
WORKDIR /opt/webapps/app
|
||||
COPY Gemfile Gemfile.lock ./
|
||||
|
|
1
Gemfile
1
Gemfile
|
@ -91,6 +91,7 @@ group :test do
|
|||
gem 'minitest', '~> 5.17'
|
||||
gem 'minitest-stub_any_instance'
|
||||
gem 'selenium-webdriver'
|
||||
# gem 'webdrivers'
|
||||
gem 'simplecov', '0.17.1', require: false # CC last supported v0.17
|
||||
gem 'spy'
|
||||
gem 'webmock'
|
||||
|
|
22
Gemfile.lock
22
Gemfile.lock
|
@ -169,8 +169,8 @@ GEM
|
|||
aws-eventstream (~> 1, >= 1.0.2)
|
||||
bcrypt (3.1.16)
|
||||
bindata (2.4.14)
|
||||
bootsnap (1.9.3)
|
||||
msgpack (~> 1.0)
|
||||
bootsnap (1.17.1)
|
||||
msgpack (~> 1.2)
|
||||
bootstrap-sass (3.4.1)
|
||||
autoprefixer-rails (>= 5.2.1)
|
||||
sassc (>= 2.0.0)
|
||||
|
@ -235,15 +235,15 @@ GEM
|
|||
thor (>= 0.14.0, < 2)
|
||||
globalid (1.0.1)
|
||||
activesupport (>= 5.0)
|
||||
google-protobuf (3.21.9)
|
||||
google-protobuf (3.21.9-x86_64-linux)
|
||||
google-protobuf (3.25.2)
|
||||
google-protobuf (3.25.2-x86_64-linux)
|
||||
googleapis-common-protos-types (1.3.0)
|
||||
google-protobuf (~> 3.14)
|
||||
grpc (1.41.1)
|
||||
google-protobuf (~> 3.17)
|
||||
grpc (1.60.0)
|
||||
google-protobuf (~> 3.25)
|
||||
googleapis-common-protos-types (~> 1.0)
|
||||
grpc (1.41.1-x86_64-linux)
|
||||
google-protobuf (~> 3.17)
|
||||
grpc (1.60.0-x86_64-linux)
|
||||
google-protobuf (~> 3.25)
|
||||
googleapis-common-protos-types (~> 1.0)
|
||||
gyoku (1.3.1)
|
||||
builder (>= 2.1.2)
|
||||
|
@ -321,7 +321,7 @@ GEM
|
|||
monetize (~> 1.9.0)
|
||||
money (~> 6.13.2)
|
||||
railties (>= 3.0)
|
||||
msgpack (1.4.2)
|
||||
msgpack (1.7.2)
|
||||
net-protocol (0.1.3)
|
||||
timeout
|
||||
net-smtp (0.3.3)
|
||||
|
@ -416,7 +416,7 @@ GEM
|
|||
activerecord (>= 6.1.5)
|
||||
activesupport (>= 6.1.5)
|
||||
i18n
|
||||
rbtree3 (0.6.0)
|
||||
rbtree3 (0.7.1)
|
||||
redis (5.0.6)
|
||||
redis-client (>= 0.9.0)
|
||||
redis-client (0.14.1)
|
||||
|
@ -604,4 +604,4 @@ DEPENDENCIES
|
|||
wkhtmltopdf-binary (~> 0.12.6.1)
|
||||
|
||||
BUNDLED WITH
|
||||
2.4.19
|
||||
2.5.4
|
||||
|
|
|
@ -144,6 +144,10 @@ module Api
|
|||
def update_and_notify!(contact)
|
||||
contact.transaction do
|
||||
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)
|
||||
contact.registrar.notify(action)
|
||||
end
|
||||
|
|
|
@ -13,6 +13,8 @@ module Actions
|
|||
dns_servers = ENV['dnssec_resolver_ips'].to_s.split(',').map(&:strip)
|
||||
|
||||
resolve_a_and_aaaa_records(dns_servers: dns_servers, email_domain: email_domain, value: value)
|
||||
rescue Mail::Field::IncompleteParseError => e
|
||||
Rails.logger.info "Failed to parse email #{email}."
|
||||
end
|
||||
|
||||
def resolve_a_and_aaaa_records(dns_servers:, email_domain:, value:)
|
||||
|
@ -32,11 +34,15 @@ module Actions
|
|||
|
||||
def resolve_a_records(dns:, hostname:)
|
||||
resources = dns.getresources(hostname, Resolv::DNS::Resource::IN::A)
|
||||
return if resources.nil?
|
||||
|
||||
resources.map(&:address)
|
||||
end
|
||||
|
||||
def resolve_aaaa_records(dns:, hostname:)
|
||||
resources = dns.getresources(hostname, Resolv::DNS::Resource::IN::AAAA)
|
||||
return if resources.nil?
|
||||
|
||||
resources.map(&:address)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,7 +21,12 @@ module Actions
|
|||
|
||||
%i[regex mx].each do |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"
|
||||
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|
|
||||
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"
|
||||
contact.add_epp_error('2005', nil, nil, "#{I18n.t(:parameter_value_syntax_error)} #{err_text}")
|
||||
|
|
|
@ -5,6 +5,29 @@ module EmailVerifable
|
|||
scope :recently_not_validated, -> { where.not(id: ValidationEvent.validated_ids_by(name)) }
|
||||
end
|
||||
|
||||
def validate_email_by_regex_and_mx
|
||||
# return if Rails.env.test?
|
||||
|
||||
verify_email(check_level: 'regex')
|
||||
verify_email(check_level: 'mx')
|
||||
end
|
||||
|
||||
def remove_force_delete_for_valid_contact
|
||||
# return if Rails.env.test?
|
||||
|
||||
domains.each do |domain|
|
||||
contact_emails_valid?(domain) ? domain.cancel_force_delete : nil
|
||||
end
|
||||
end
|
||||
|
||||
def contact_emails_valid?(domain)
|
||||
domain.contacts.each do |c|
|
||||
return false unless c.need_to_lift_force_delete?
|
||||
end
|
||||
|
||||
domain.registrant.need_to_lift_force_delete?
|
||||
end
|
||||
|
||||
def email_verification_failed?
|
||||
need_to_start_force_delete?
|
||||
end
|
||||
|
|
|
@ -85,6 +85,9 @@ class Contact < ApplicationRecord
|
|||
after_save :update_related_whois_records
|
||||
before_validation :clear_address_modifications, if: -> { !self.class.address_processing? }
|
||||
|
||||
# after_save :validate_email_by_regex_and_mx
|
||||
# after_save :remove_force_delete_for_valid_contact
|
||||
|
||||
self.ignored_columns = %w[legacy_id legacy_history_id]
|
||||
|
||||
ORG = 'org'.freeze
|
||||
|
|
|
@ -33,6 +33,8 @@ class JavaScriptApplicationSystemTestCase < ApplicationSystemTestCase
|
|||
|
||||
Capybara.server = :puma, { Silent: true }
|
||||
|
||||
# Webdrivers::Chromedriver.required_version = '114.0.5735.90'
|
||||
|
||||
def setup
|
||||
DatabaseCleaner.start
|
||||
super
|
||||
|
|
|
@ -321,6 +321,60 @@ class ContactTest < ActiveJob::TestCase
|
|||
assert_equal contact.email, 'test@test.test'
|
||||
end
|
||||
|
||||
# def test_verify_email_if_it_changed
|
||||
# # check that email is invalid
|
||||
# assert_equal @contact.validation_events.count, 0
|
||||
|
||||
# trumail_results = OpenStruct.new(success: false,
|
||||
# email: @contact.email,
|
||||
# domain: 'box.tests',
|
||||
# errors: { mx: 'target host(s) not found' })
|
||||
|
||||
# runner = Actions::EmailCheck.new(email: @contact.email,
|
||||
# validation_eventable: @contact,
|
||||
# check_level: 'mx')
|
||||
|
||||
# runner.stub :call, trumail_results do
|
||||
# 3.times do
|
||||
# perform_enqueued_jobs do
|
||||
# VerifyEmailsJob.perform_now(email: @contact.email, check_level: 'mx')
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# assert_equal @contact.validation_events.count, 3
|
||||
# validation_event = @contact.validation_events.last
|
||||
|
||||
# assert_equal validation_event.check_level, 'mx'
|
||||
# assert_equal validation_event.success, false
|
||||
|
||||
# # set force delete to releted contact domain because invlid email
|
||||
# assert @contact.need_to_start_force_delete?
|
||||
|
||||
# @contact.domains.each do |domain|
|
||||
# domain.schedule_force_delete(type: :soft)
|
||||
# end
|
||||
|
||||
# # check it
|
||||
# assert @contact.domains.first.force_delete_scheduled?
|
||||
|
||||
# # change email to valid
|
||||
|
||||
# Truemail.configure.whitelisted_domains = %w[email.com inbox.test outlook.test]
|
||||
|
||||
# @contact.email = 'valid@email.com'
|
||||
# @contact.save! && @contact.reload
|
||||
|
||||
# assert_equal @contact.validation_events.count, 1
|
||||
|
||||
# perform_enqueued_jobs
|
||||
|
||||
# # check that force delete is removed
|
||||
|
||||
# @contact.reload
|
||||
# assert_not @contact.domains.first.force_delete_scheduled?
|
||||
# end
|
||||
|
||||
private
|
||||
|
||||
def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact)
|
||||
|
|
|
@ -9,6 +9,8 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
ActionMailer::Base.deliveries.clear
|
||||
@old_validation_type = Truemail.configure.default_validation_type
|
||||
ValidationEvent.destroy_all
|
||||
|
||||
Truemail.configure.whitelisted_domains = ['email.com', 'internet2.ee']
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
@ -417,6 +419,8 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
Truemail.configure.default_validation_type = :regex
|
||||
|
||||
contact_first = domain.admin_contacts.first
|
||||
|
||||
|
||||
contact_first.update_attribute(:email_history, 'john@inbox.test')
|
||||
contact_first.update_attribute(:email, email)
|
||||
|
||||
|
|
|
@ -29,8 +29,6 @@ class ValidationEventTest < ActiveSupport::TestCase
|
|||
assert contact.need_to_start_force_delete?
|
||||
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?
|
||||
|
|
|
@ -54,13 +54,14 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
|||
end
|
||||
|
||||
def test_should_verify_contact_email_which_was_not_verified
|
||||
|
||||
assert_equal ValidationEvent.count, 0
|
||||
|
||||
|
||||
run_task
|
||||
|
||||
|
||||
assert_equal ValidationEvent.count, Contact.count - 1
|
||||
assert_equal Contact.count, 9
|
||||
|
||||
|
||||
assert_difference 'Contact.count', 1 do
|
||||
create_valid_contact
|
||||
end
|
||||
|
@ -76,7 +77,7 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
|||
contact.domains.last.schedule_force_delete(type: :soft)
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
|
||||
contact.update!(email: 'test@box.test')
|
||||
contact.update_attribute(:email, 'test@box.test')
|
||||
contact.reload
|
||||
|
||||
trumail_results = OpenStruct.new(success: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue