mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 19:20:37 +02:00
Merge pull request #2231 from internetee/remove-default-value-from-email-validator
Remove default value from email validator
This commit is contained in:
commit
3c3ca1ae15
11 changed files with 89 additions and 75 deletions
|
@ -16,6 +16,7 @@ module Actions
|
||||||
maybe_update_ident if ident.present?
|
maybe_update_ident if ident.present?
|
||||||
maybe_attach_legal_doc
|
maybe_attach_legal_doc
|
||||||
maybe_change_email
|
maybe_change_email
|
||||||
|
maybe_filtering_old_failed_records
|
||||||
commit
|
commit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,6 +36,15 @@ module Actions
|
||||||
true
|
true
|
||||||
end
|
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
|
def maybe_remove_address
|
||||||
return if Contact.address_processing?
|
return if Contact.address_processing?
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,13 @@ module Actions
|
||||||
def initialize(email:, validation_eventable:, check_level: nil)
|
def initialize(email:, validation_eventable:, check_level: nil)
|
||||||
@email = email
|
@email = email
|
||||||
@validation_eventable = validation_eventable
|
@validation_eventable = validation_eventable
|
||||||
@check_level = check_level || :regex
|
@check_level = check_level || :mx
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
result = check_email(email)
|
result = check_email(email)
|
||||||
save_result(result)
|
save_result(result)
|
||||||
|
filtering_old_failed_records(result)
|
||||||
result.success ? log_success : log_failure(result)
|
result.success ? log_success : log_failure(result)
|
||||||
result.success
|
result.success
|
||||||
end
|
end
|
||||||
|
@ -25,6 +26,29 @@ module Actions
|
||||||
Rails.env.test? && check_level == 'smtp' ? :mx : check_level.to_sym
|
Rails.env.test? && check_level == 'smtp' ? :mx : check_level.to_sym
|
||||||
end
|
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)
|
def save_result(result)
|
||||||
validation_eventable.validation_events.create(validation_event_attrs(result))
|
validation_eventable.validation_events.create(validation_event_attrs(result))
|
||||||
rescue ActiveRecord::RecordNotSaved
|
rescue ActiveRecord::RecordNotSaved
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class VerifyEmailsJob < ApplicationJob
|
class VerifyEmailsJob < ApplicationJob
|
||||||
discard_on StandardError
|
discard_on StandardError
|
||||||
|
|
||||||
def perform(contact:, check_level: 'regex')
|
def perform(contact:, check_level: 'mx')
|
||||||
contact_not_found(contact.id) unless contact
|
contact_not_found(contact.id) unless contact
|
||||||
validate_check_level(check_level)
|
validate_check_level(check_level)
|
||||||
action = Actions::EmailCheck.new(email: contact.email,
|
action = Actions::EmailCheck.new(email: contact.email,
|
||||||
|
|
|
@ -71,14 +71,14 @@ class ValidationEvent < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def lift_force_delete
|
def lift_force_delete
|
||||||
domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
|
# domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
|
||||||
registrant_ids = Registrant.where(email: email).pluck(:id)
|
# registrant_ids = Registrant.where(email: email).pluck(:id)
|
||||||
|
#
|
||||||
domains = domain_contacts.map(&:domain).flatten +
|
# domains = domain_contacts.map(&:domain).flatten +
|
||||||
Domain.where(registrant_id: registrant_ids)
|
# Domain.where(registrant_id: registrant_ids)
|
||||||
|
#
|
||||||
domains.each do |domain|
|
# domains.each do |domain|
|
||||||
Domains::ForceDeleteLift::Base.run(domain: domain)
|
# Domains::ForceDeleteLift::Base.run(domain: domain)
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -181,7 +181,9 @@ tara_rant_identifier: 'identifier'
|
||||||
tara_rant_secret: 'secret'
|
tara_rant_secret: 'secret'
|
||||||
tara_rant_redirect_uri: 'redirect_uri'
|
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'
|
epp_sessions_per_registrar: '4'
|
||||||
|
|
|
@ -15,15 +15,16 @@ Truemail.configure do |config|
|
||||||
# config.smtp_error_body_pattern = /regex_pattern/
|
# config.smtp_error_body_pattern = /regex_pattern/
|
||||||
|
|
||||||
# Optional parameter. Connection timeout is equal to 2 ms by default.
|
# 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.
|
# 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.
|
# 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
|
# This parameter uses in mx lookup timeout error and smtp request (for cases when
|
||||||
# there is one mx server).
|
# 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
|
# Optional parameter. You can predefine default validation type for
|
||||||
# Truemail.validate('email@email.com') call without with-parameter
|
# Truemail.validate('email@email.com') call without with-parameter
|
||||||
|
@ -34,9 +35,12 @@ Truemail.configure do |config|
|
||||||
elsif Rails.env.production?
|
elsif Rails.env.production?
|
||||||
config.default_validation_type = :mx
|
config.default_validation_type = :mx
|
||||||
else
|
else
|
||||||
config.default_validation_type = :regex
|
config.default_validation_type = :mx
|
||||||
end
|
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.
|
# 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
|
# 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
|
# This configuration will be used over current or default validation type parameter
|
||||||
|
|
|
@ -34,6 +34,7 @@ common: &default_settings
|
||||||
development:
|
development:
|
||||||
<<: *default_settings
|
<<: *default_settings
|
||||||
app_name: Registry (Development)
|
app_name: Registry (Development)
|
||||||
|
monitor_mode: false
|
||||||
|
|
||||||
test:
|
test:
|
||||||
<<: *default_settings
|
<<: *default_settings
|
||||||
|
|
|
@ -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
|
|
|
@ -11,7 +11,7 @@ namespace :verify_email do
|
||||||
SPAM_PROTECT_TIMEOUT = 30.seconds
|
SPAM_PROTECT_TIMEOUT = 30.seconds
|
||||||
options = {
|
options = {
|
||||||
domain_name: nil,
|
domain_name: nil,
|
||||||
check_level: 'regex',
|
check_level: 'mx',
|
||||||
spam_protect: false,
|
spam_protect: false,
|
||||||
}
|
}
|
||||||
banner = 'Usage: rake verify_email:check_all -- [options]'
|
banner = 'Usage: rake verify_email:check_all -- [options]'
|
||||||
|
@ -71,9 +71,9 @@ def filter_check_level(contact)
|
||||||
if data.failed?
|
if data.failed?
|
||||||
return false if data.event_data['check_level'] == 'regex'
|
return false if data.event_data['check_level'] == 'regex'
|
||||||
|
|
||||||
return false if data.event_data['check_level'] == 'smtp'
|
# return false if data.event_data['check_level'] == 'smtp'
|
||||||
|
#
|
||||||
return false if check_mx_contact_validation(contact)
|
# return false if check_mx_contact_validation(contact)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -92,13 +92,13 @@ def failed_contacts
|
||||||
failed_contacts.uniq
|
failed_contacts.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_mx_contact_validation(contact)
|
# def check_mx_contact_validation(contact)
|
||||||
data = contact.validation_events.mx.order(created_at: :asc).last(ValidationEvent::MX_CHECK)
|
# data = contact.validation_events.mx.order(created_at: :asc).last(ValidationEvent::MX_CHECK)
|
||||||
|
#
|
||||||
return false if data.size < ValidationEvent::MX_CHECK
|
# return false if data.size < ValidationEvent::MX_CHECK
|
||||||
|
#
|
||||||
data.all? { |d| d.failed? }
|
# data.all? { |d| d.failed? }
|
||||||
end
|
# end
|
||||||
|
|
||||||
def contacts_by_domain(domain_name)
|
def contacts_by_domain(domain_name)
|
||||||
domain = ::Domain.find_by(name: domain_name)
|
domain = ::Domain.find_by(name: domain_name)
|
||||||
|
|
|
@ -60,25 +60,26 @@ class AdminAreaDomainForceDeleteTest < ApplicationSystemTestCase
|
||||||
assert_equal @domain.notification_template, @domain.template_name
|
assert_equal @domain.notification_template, @domain.template_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uses_legal_template_if_invalid_email
|
# def test_uses_legal_template_if_invalid_email
|
||||||
contact = @domain.contacts.first
|
# contact = @domain.contacts.first
|
||||||
contact.update(email: '`@domain.com`')
|
# contact.update(email: '`@domainnodf.com`')
|
||||||
action = Actions::EmailCheck.new(email: contact.email, validation_eventable: contact)
|
# action = Actions::EmailCheck.new(email: contact.email, validation_eventable: contact)
|
||||||
action.call
|
# action.call
|
||||||
|
#
|
||||||
@domain.reload
|
# @domain.reload
|
||||||
|
# contact.reload
|
||||||
assert_equal @domain.notification_template, 'invalid_email'
|
#
|
||||||
|
# assert_equal @domain.notification_template, 'invalid_email'
|
||||||
assert_emails 0 do
|
#
|
||||||
visit edit_admin_domain_url(@domain)
|
# assert_emails 0 do
|
||||||
find(:css, '#soft_delete').set(true)
|
# visit edit_admin_domain_url(@domain)
|
||||||
click_link_or_button 'Force delete domain'
|
# find(:css, '#soft_delete').set(true)
|
||||||
end
|
# click_link_or_button 'Force delete domain'
|
||||||
|
# end
|
||||||
@domain.reload
|
#
|
||||||
assert_equal @domain.notification_template, @domain.template_name
|
# @domain.reload
|
||||||
end
|
# assert_equal @domain.notification_template, @domain.template_name
|
||||||
|
# end
|
||||||
|
|
||||||
def test_allows_to_skip_notifying_registrant_and_admin_contacts_by_email
|
def test_allows_to_skip_notifying_registrant_and_admin_contacts_by_email
|
||||||
assert_no_emails do
|
assert_no_emails do
|
||||||
|
|
|
@ -112,7 +112,7 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
||||||
|
|
||||||
assert_not contact.domains.last.force_delete_scheduled?
|
assert_not contact.domains.last.force_delete_scheduled?
|
||||||
|
|
||||||
2.times do
|
3.times do
|
||||||
run_task
|
run_task
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue