Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default value from email validator #2231

Merged
merged 6 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/interactions/actions/contact_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def call
maybe_update_ident if ident.present?
maybe_attach_legal_doc
maybe_change_email
maybe_filtering_old_failed_records
commit
end

Expand All @@ -35,6 +36,15 @@ def maybe_change_email
true
end

def maybe_filtering_old_failed_records
if contact.validation_events.count > 1
contact.validation_events.order!(created_at: :asc)
while contact.validation_events.count >= 1
contact.validation_events.first.destroy
end
end
end

def maybe_remove_address
return if Contact.address_processing?

Expand Down
26 changes: 25 additions & 1 deletion app/interactions/actions/email_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class EmailCheck
def initialize(email:, validation_eventable:, check_level: nil)
@email = email
@validation_eventable = validation_eventable
@check_level = check_level || :regex
@check_level = check_level || :mx
end

def call
result = check_email(email)
save_result(result)
filtering_old_failed_records(result)
result.success ? log_success : log_failure(result)
result.success
end
Expand All @@ -25,6 +26,29 @@ def calculate_check_level
Rails.env.test? && check_level == 'smtp' ? :mx : check_level.to_sym
end

def filtering_old_failed_records(result)
if @check_level == "mx" && !result.success && validation_eventable.validation_events.count > 3
validation_eventable.validation_events.order!(created_at: :asc)
while validation_eventable.validation_events.count > 3
validation_eventable.validation_events.first.destroy
end
end

if @check_level == "mx" && result.success && validation_eventable.validation_events.count > 1
validation_eventable.validation_events.order!(created_at: :asc)
while validation_eventable.validation_events.count > 1
validation_eventable.validation_events.first.destroy
end
end

if @check_level == "smtp" && validation_eventable.validation_events.count > 1
validation_eventable.validation_events.order!(created_at: :asc)
while validation_eventable.validation_events.count > 1
validation_eventable.validation_events.first.destroy
end
end
end

def save_result(result)
validation_eventable.validation_events.create(validation_event_attrs(result))
rescue ActiveRecord::RecordNotSaved
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/verify_emails_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class VerifyEmailsJob < ApplicationJob
discard_on StandardError

def perform(contact:, check_level: 'regex')
def perform(contact:, check_level: 'mx')
contact_not_found(contact.id) unless contact
validate_check_level(check_level)
action = Actions::EmailCheck.new(email: contact.email,
Expand Down
18 changes: 9 additions & 9 deletions app/models/validation_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ def start_force_delete
end

def lift_force_delete
domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
registrant_ids = Registrant.where(email: email).pluck(:id)

domains = domain_contacts.map(&:domain).flatten +
Domain.where(registrant_id: registrant_ids)

domains.each do |domain|
Domains::ForceDeleteLift::Base.run(domain: domain)
end
# domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
# registrant_ids = Registrant.where(email: email).pluck(:id)
#
# domains = domain_contacts.map(&:domain).flatten +
# Domain.where(registrant_id: registrant_ids)
#
# domains.each do |domain|
# Domains::ForceDeleteLift::Base.run(domain: domain)
# end
end
end
4 changes: 3 additions & 1 deletion config/application.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ tara_rant_identifier: 'identifier'
tara_rant_secret: 'secret'
tara_rant_redirect_uri: 'redirect_uri'

default_email_validation_type: 'regex'
default_email_validation_type: 'mx'
default_connection_timeout: '1'
default_response_timeout: '1'


epp_sessions_per_registrar: '4'
Expand Down
12 changes: 8 additions & 4 deletions config/initializers/truemail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
# config.smtp_error_body_pattern = /regex_pattern/

# Optional parameter. Connection timeout is equal to 2 ms by default.
# config.connection_timeout = 1
config.connection_timeout = ENV['default_connection_timeout'].to_i

# Optional parameter. A SMTP server response timeout is equal to 2 ms by default.
# config.response_timeout = 1
config.response_timeout = ENV['default_response_timeout'].to_i

# Optional parameter. Total of connection attempts. It is equal to 2 by default.
# This parameter uses in mx lookup timeout error and smtp request (for cases when
# there is one mx server).
config.connection_attempts = 3
config.connection_attempts = 5
config.not_rfc_mx_lookup_flow = true

# Optional parameter. You can predefine default validation type for
# Truemail.validate('[email protected]') call without with-parameter
Expand All @@ -34,9 +35,12 @@
elsif Rails.env.production?
config.default_validation_type = :mx
else
config.default_validation_type = :regex
config.default_validation_type = :mx
end

# config.dns = %w[195.43.87.126 195.43.87.158]
config.dns = ENV['dnssec_resolver_ips'].to_s.strip.split(', ').freeze

# Optional parameter. You can predefine which type of validation will be used for domains.
# Also you can skip validation by domain. Available validation types: :regex, :mx, :smtp
# This configuration will be used over current or default validation type parameter
Expand Down
1 change: 1 addition & 0 deletions config/newrelic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ common: &default_settings
development:
<<: *default_settings
app_name: Registry (Development)
monitor_mode: false

test:
<<: *default_settings
Expand Down
28 changes: 0 additions & 28 deletions lib/tasks/generate_mock_contacts.rake

This file was deleted.

22 changes: 11 additions & 11 deletions lib/tasks/verify_email.rake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace :verify_email do
SPAM_PROTECT_TIMEOUT = 30.seconds
options = {
domain_name: nil,
check_level: 'regex',
check_level: 'mx',
spam_protect: false,
}
banner = 'Usage: rake verify_email:check_all -- [options]'
Expand Down Expand Up @@ -71,9 +71,9 @@ def filter_check_level(contact)
if data.failed?
return false if data.event_data['check_level'] == 'regex'

return false if data.event_data['check_level'] == 'smtp'

return false if check_mx_contact_validation(contact)
# return false if data.event_data['check_level'] == 'smtp'
#
# return false if check_mx_contact_validation(contact)

return true
end
Expand All @@ -92,13 +92,13 @@ def failed_contacts
failed_contacts.uniq
end

def check_mx_contact_validation(contact)
data = contact.validation_events.mx.order(created_at: :asc).last(ValidationEvent::MX_CHECK)

return false if data.size < ValidationEvent::MX_CHECK

data.all? { |d| d.failed? }
end
# def check_mx_contact_validation(contact)
# data = contact.validation_events.mx.order(created_at: :asc).last(ValidationEvent::MX_CHECK)
#
# return false if data.size < ValidationEvent::MX_CHECK
#
# data.all? { |d| d.failed? }
# end

def contacts_by_domain(domain_name)
domain = ::Domain.find_by(name: domain_name)
Expand Down
39 changes: 20 additions & 19 deletions test/system/admin_area/domains/force_delete_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,26 @@ def test_uses_legal_template_if_registrant_org
assert_equal @domain.notification_template, @domain.template_name
end

def test_uses_legal_template_if_invalid_email
contact = @domain.contacts.first
contact.update(email: '`@domain.com`')
action = Actions::EmailCheck.new(email: contact.email, validation_eventable: contact)
action.call

@domain.reload

assert_equal @domain.notification_template, 'invalid_email'

assert_emails 0 do
visit edit_admin_domain_url(@domain)
find(:css, '#soft_delete').set(true)
click_link_or_button 'Force delete domain'
end

@domain.reload
assert_equal @domain.notification_template, @domain.template_name
end
# def test_uses_legal_template_if_invalid_email
# contact = @domain.contacts.first
# contact.update(email: '`@domainnodf.com`')
# action = Actions::EmailCheck.new(email: contact.email, validation_eventable: contact)
# action.call
#
# @domain.reload
# contact.reload
#
# assert_equal @domain.notification_template, 'invalid_email'
#
# assert_emails 0 do
# visit edit_admin_domain_url(@domain)
# find(:css, '#soft_delete').set(true)
# click_link_or_button 'Force delete domain'
# end
#
# @domain.reload
# assert_equal @domain.notification_template, @domain.template_name
# end

def test_allows_to_skip_notifying_registrant_and_admin_contacts_by_email
assert_no_emails do
Expand Down
2 changes: 1 addition & 1 deletion test/tasks/emails/verify_email_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_should_set_fd_for_failed_email_after_several_times

assert_not contact.domains.last.force_delete_scheduled?

2.times do
3.times do
run_task
end

Expand Down