mirror of
https://github.com/internetee/registry.git
synced 2025-06-03 19:27:29 +02:00
Fix deprecated email_notification usage in tests
This commit is contained in:
parent
d48b0f4401
commit
70a6a44525
12 changed files with 15 additions and 164 deletions
|
@ -9,8 +9,7 @@ module Actions
|
|||
end
|
||||
|
||||
def call
|
||||
parsed_email = EmailAddressConverter.punycode_to_unicode(email)
|
||||
result = check_email(parsed_email)
|
||||
result = check_email(email)
|
||||
save_result(result)
|
||||
result.success ? log_success : log_failure(result)
|
||||
result.success
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
class EmailAddressVerification < ApplicationRecord
|
||||
RECENTLY_VERIFIED_PERIOD = 1.month
|
||||
# after_save :check_force_delete
|
||||
|
||||
def failed?
|
||||
bounce_present? || (verified_at.present? && !success)
|
||||
end
|
||||
|
||||
def verified?
|
||||
success
|
||||
end
|
||||
|
||||
def bounce_present?
|
||||
BouncedMailAddress.find_by(email: email).present?
|
||||
end
|
||||
|
||||
def check_force_delete
|
||||
return unless failed?
|
||||
|
||||
Domains::ForceDeleteEmail::Base.run(email: email)
|
||||
end
|
||||
|
||||
def verify
|
||||
validation_request = Truemail.validate(email)
|
||||
|
||||
if validation_request.result.success
|
||||
update(verified_at: Time.zone.now,
|
||||
success: true)
|
||||
else
|
||||
update(verified_at: Time.zone.now,
|
||||
success: false)
|
||||
end
|
||||
|
||||
validation_request.result
|
||||
end
|
||||
end
|
|
@ -6,7 +6,7 @@
|
|||
# For email_validation event kind also check_level (regex/mx/smtp) is stored in the event_data
|
||||
class ValidationEvent < ApplicationRecord
|
||||
enum event_type: ValidationEvent::EventType::TYPES, _suffix: true
|
||||
VALIDATION_PERIOD = 1.month.ago.freeze
|
||||
VALIDATION_PERIOD = 1.month.freeze
|
||||
VALID_CHECK_LEVELS = %w[regex mx smtp].freeze
|
||||
VALID_EVENTS_COUNT_THRESHOLD = 5
|
||||
|
||||
|
@ -26,7 +26,7 @@ class ValidationEvent < ApplicationRecord
|
|||
|
||||
belongs_to :validation_eventable, polymorphic: true
|
||||
|
||||
scope :recent, -> { where('created_at > ?', VALIDATION_PERIOD) }
|
||||
scope :recent, -> { where('created_at > ?', Time.zone.now - VALIDATION_PERIOD) }
|
||||
scope :successful, -> { where(success: true) }
|
||||
scope :failed, -> { where(success: false) }
|
||||
scope :regex, -> { where('event_data @> ?', { 'check_level': 'regex' }.to_json) }
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
require 'application_service'
|
||||
require 'email_address_converter'
|
||||
require 'xsd/schema'
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
module EmailAddressConverter
|
||||
module_function
|
||||
|
||||
def punycode_to_unicode(email)
|
||||
return email if domain(email) == 'not_found'
|
||||
|
||||
local = local(email)
|
||||
domain = SimpleIDN.to_unicode(domain(email))
|
||||
"#{local}@#{domain}"&.downcase
|
||||
end
|
||||
|
||||
def unicode_to_punycode(email)
|
||||
return email if domain(email) == 'not_found'
|
||||
|
||||
local = local(email)
|
||||
domain = SimpleIDN.to_ascii(domain(email))
|
||||
"#{local}@#{domain}"&.downcase
|
||||
end
|
||||
|
||||
def domain(email)
|
||||
Mail::Address.new(email).domain&.downcase || 'not_found'
|
||||
rescue Mail::Field::IncompleteParseError
|
||||
'not_found'
|
||||
end
|
||||
|
||||
def local(email)
|
||||
Mail::Address.new(email).local&.downcase || email
|
||||
rescue Mail::Field::IncompleteParseError
|
||||
email
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ require 'rake_option_parser_boilerplate'
|
|||
require 'syslog/logger'
|
||||
|
||||
namespace :verify_email do
|
||||
# bundle exec rake verify_email:check_all -- -d=shop.test --check_level=mx --spam_protect=true
|
||||
# bundle exec rake verify_email:check_all -- --domain_name=shop.test --check_level=mx --spam_protect=true
|
||||
# bundle exec rake verify_email:check_all -- -dshop.test -cmx -strue
|
||||
desc 'Starts verifying email jobs with optional check level and spam protection'
|
||||
task check_all: :environment do
|
||||
|
|
|
@ -40,9 +40,9 @@ class DomainExpireMailerTest < ActionMailer::TestCase
|
|||
|
||||
contact = domain.admin_contacts.first
|
||||
contact.update_attribute(:email, email)
|
||||
# contact.email_verification.verify
|
||||
contact.verify_email
|
||||
|
||||
# assert contact.email_verification_failed?
|
||||
assert contact.email_verification_failed?
|
||||
|
||||
domain.reload
|
||||
|
||||
|
|
|
@ -87,24 +87,6 @@ class ContactTest < ActiveJob::TestCase
|
|||
assert contact.valid?
|
||||
end
|
||||
|
||||
def test_email_verification_smtp_error
|
||||
Truemail.configure.default_validation_type = :smtp
|
||||
|
||||
contact = valid_contact
|
||||
contact.email = 'somecrude1337joke@internet.ee'
|
||||
assert contact.invalid?
|
||||
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_smtp_check_error'), contact.errors.messages[:email].first
|
||||
end
|
||||
|
||||
def test_email_verification_mx_error
|
||||
Truemail.configure.default_validation_type = :mx
|
||||
|
||||
contact = valid_contact
|
||||
contact.email = 'somecrude31337joke@somestrange31337domain.ee'
|
||||
assert contact.invalid?
|
||||
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_mx_check_error'), contact.errors.messages[:email].first
|
||||
end
|
||||
|
||||
def test_email_verification_regex_error
|
||||
Truemail.configure.default_validation_type = :regex
|
||||
|
||||
|
@ -358,16 +340,6 @@ class ContactTest < ActiveJob::TestCase
|
|||
assert_equal domain.whois_record.try(:json).try(:[], 'registrant'), @contact.name
|
||||
end
|
||||
|
||||
def test_creates_email_verification_in_unicode
|
||||
unicode_email = 'suur@äri.ee'
|
||||
punycode_email = Contact.unicode_to_punycode(unicode_email)
|
||||
|
||||
@contact.email = punycode_email
|
||||
@contact.save
|
||||
|
||||
assert_equal @contact.email_verification.email, unicode_email
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact)
|
||||
|
|
|
@ -6,6 +6,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
Setting.redemption_grace_period = 30
|
||||
ActionMailer::Base.deliveries.clear
|
||||
@old_validation_type = Truemail.configure.default_validation_type
|
||||
ValidationEvent.destroy_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
@ -441,9 +442,9 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
end
|
||||
|
||||
def test_lifts_force_delete_if_contact_fixed
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
@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 = '`@internet.ee'
|
||||
|
||||
Truemail.configure.default_validation_type = :regex
|
||||
|
|
|
@ -48,28 +48,6 @@ class RegistrarTest < ActiveJob::TestCase
|
|||
assert registrar.valid?
|
||||
end
|
||||
|
||||
def test_email_verification_smtp_error
|
||||
Truemail.configure.default_validation_type = :smtp
|
||||
|
||||
registrar = valid_registrar
|
||||
registrar.email = 'somecrude1337joke@internet.ee'
|
||||
registrar.billing_email = nil
|
||||
|
||||
assert registrar.invalid?
|
||||
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_smtp_check_error'), registrar.errors.messages[:email].first
|
||||
end
|
||||
|
||||
def test_email_verification_mx_error
|
||||
Truemail.configure.default_validation_type = :mx
|
||||
|
||||
registrar = valid_registrar
|
||||
registrar.email = 'somecrude31337joke@somestrange31337domain.ee'
|
||||
registrar.billing_email = nil
|
||||
|
||||
assert registrar.invalid?
|
||||
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_mx_check_error'), registrar.errors.messages[:email].first
|
||||
end
|
||||
|
||||
def test_email_verification_regex_error
|
||||
Truemail.configure.default_validation_type = :regex
|
||||
|
||||
|
@ -88,26 +66,6 @@ class RegistrarTest < ActiveJob::TestCase
|
|||
assert registrar.valid?
|
||||
end
|
||||
|
||||
def test_billing_email_verification_smtp_error
|
||||
Truemail.configure.default_validation_type = :smtp
|
||||
|
||||
registrar = valid_registrar
|
||||
registrar.billing_email = 'somecrude1337joke@internet.ee'
|
||||
|
||||
assert registrar.invalid?
|
||||
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_smtp_check_error'), registrar.errors.messages[:billing_email].first
|
||||
end
|
||||
|
||||
def test_billing_email_verification_mx_error
|
||||
Truemail.configure.default_validation_type = :mx
|
||||
|
||||
registrar = valid_registrar
|
||||
registrar.billing_email = 'somecrude31337joke@somestrange31337domain.ee'
|
||||
|
||||
assert registrar.invalid?
|
||||
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_mx_check_error'), registrar.errors.messages[:billing_email].first
|
||||
end
|
||||
|
||||
def test_billing_email_verification_regex_error
|
||||
Truemail.configure.default_validation_type = :regex
|
||||
|
||||
|
@ -118,21 +76,6 @@ class RegistrarTest < ActiveJob::TestCase
|
|||
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), registrar.errors.messages[:billing_email].first
|
||||
end
|
||||
|
||||
def test_creates_email_verification_in_unicode
|
||||
unicode_email = 'suur@äri.ee'
|
||||
punycode_email = Registrar.unicode_to_punycode(unicode_email)
|
||||
unicode_billing_email = 'billing@äri.ee'
|
||||
punycode_billing_email = Registrar.unicode_to_punycode(unicode_billing_email)
|
||||
|
||||
registrar = valid_registrar
|
||||
registrar.email = punycode_email
|
||||
registrar.billing_email = punycode_billing_email
|
||||
registrar.save
|
||||
|
||||
assert_equal registrar.email_verification.email, unicode_email
|
||||
assert_equal registrar.billing_email_verification.email, unicode_billing_email
|
||||
end
|
||||
|
||||
def test_invalid_without_accounting_customer_code
|
||||
registrar = valid_registrar
|
||||
registrar.accounting_customer_code = ''
|
||||
|
|
|
@ -16,7 +16,7 @@ class ValidationEventTest < ActiveSupport::TestCase
|
|||
@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 = 'some@strangesentence@internet.ee'
|
||||
email = '~@internet.ee'
|
||||
|
||||
contact = @domain.admin_contacts.first
|
||||
contact.update_attribute(:email, email)
|
||||
|
|
|
@ -61,8 +61,12 @@ class AdminAreaDomainForceDeleteTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
def test_uses_legal_template_if_invalid_email
|
||||
verification = @domain.contacts.first.email_verification
|
||||
verification.update(verified_at: Time.zone.now - 1.day, success: false)
|
||||
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'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue