Merge pull request #2231 from internetee/remove-default-value-from-email-validator

Remove default value from email validator
This commit is contained in:
Timo Võhmar 2021-12-17 19:05:04 +02:00 committed by GitHub
commit 3c3ca1ae15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 89 additions and 75 deletions

View file

@ -16,6 +16,7 @@ module Actions
maybe_update_ident if ident.present?
maybe_attach_legal_doc
maybe_change_email
maybe_filtering_old_failed_records
commit
end
@ -35,6 +36,15 @@ module Actions
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?

View file

@ -5,12 +5,13 @@ module Actions
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
@ -25,6 +26,29 @@ module Actions
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

View file

@ -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,

View file

@ -71,14 +71,14 @@ class ValidationEvent < ApplicationRecord
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

View file

@ -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'

View file

@ -15,15 +15,16 @@ Truemail.configure do |config|
# 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@email.com') call without with-parameter
@ -34,9 +35,12 @@ Truemail.configure do |config|
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

View file

@ -34,6 +34,7 @@ common: &default_settings
development:
<<: *default_settings
app_name: Registry (Development)
monitor_mode: false
test:
<<: *default_settings

View file

@ -1,28 +0,0 @@
# namespace :generate_mock do
# task contacts: :environment do
# 1000.times do
# c = Contact.new
# c.name = generate_random_string
# c.email = generate_random_string + "@" + generate_random_string + ".ee"
# c.registrar_id = registrar
# c.street = generate_random_string
# c.city = generate_random_string
# c.zip = '12323'
# c.country_code = 'EE'
# c.phone = "+372.59813318"
# c.ident_country_code = 'EE'
# c.ident_type = 'priv'
# c.ident = '38903110313'
# c.code = generate_random_string + ":" + generate_random_string
# c.save
# end
# end
#
# def generate_random_string
# (0...10).map { (65 + rand(26)).chr }.join
# end
#
# def registrar
# Registrar.last.id
# end
# end

View file

@ -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]'
@ -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
@ -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)

View file

@ -60,25 +60,26 @@ class AdminAreaDomainForceDeleteTest < ApplicationSystemTestCase
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

View file

@ -112,7 +112,7 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
assert_not contact.domains.last.force_delete_scheduled?
2.times do
3.times do
run_task
end