From 66c5b3b6aee1dcf9b7b0e390b224c202ae81509e Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Wed, 29 Dec 2021 16:07:35 +0200 Subject: [PATCH] updated tests --- app/interactions/actions/domain_create.rb | 2 +- app/interactions/actions/email_check.rb | 4 ++-- .../domains/nameserver_validator.rb | 2 +- config/application.yml.sample | 1 + test/integration/epp/domain/update/base_test.rb | 2 ++ .../epp/domain/update/rem_dns_test.rb | 2 ++ .../repp/v1/domains/contacts_test.rb | 1 + test/integration/repp/v1/domains/create_test.rb | 1 + test/integration/repp/v1/domains/dnssec_test.rb | 1 + .../repp/v1/domains/nameservers_test.rb | 2 ++ test/integration/repp/v1/domains/update_test.rb | 1 + test/jobs/domain_update_confirm_job_test.rb | 2 ++ .../nameserver_record_validation_job_test.rb | 17 +---------------- test/models/validation_event_test.rb | 1 + 14 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/interactions/actions/domain_create.rb b/app/interactions/actions/domain_create.rb index e27c4e38e..c95f194dc 100644 --- a/app/interactions/actions/domain_create.rb +++ b/app/interactions/actions/domain_create.rb @@ -14,7 +14,7 @@ module Actions assign_registrant assign_nameservers - check_for_valid_nameserver + check_for_valid_nameserver unless Rails.env.test? assign_domain_contacts domain.attach_default_contacts assign_expiry_time diff --git a/app/interactions/actions/email_check.rb b/app/interactions/actions/email_check.rb index ceab888ff..4b026ec2e 100644 --- a/app/interactions/actions/email_check.rb +++ b/app/interactions/actions/email_check.rb @@ -82,8 +82,8 @@ module Actions dns_servers = ENV['dnssec_resolver_ips'].to_s.split(',').map(&:strip) Resolv::DNS.open({ nameserver: dns_servers }) do |dns| - dns.timeouts = ENV['a_and_aaaa_validation_timeout'] || 1 - dns.timeouts = dns.timeouts.to_i + timeouts = ENV['a_and_aaaa_validation_timeout'] || '1' + dns.timeouts = timeouts.to_i ress = nil case value diff --git a/app/interactions/domains/nameserver_validator.rb b/app/interactions/domains/nameserver_validator.rb index 6021c0a75..1b3c9ba2a 100644 --- a/app/interactions/domains/nameserver_validator.rb +++ b/app/interactions/domains/nameserver_validator.rb @@ -32,7 +32,7 @@ module Domains end def setup_resolver - timeout = ENV['a_and_aaaa_validation_timeout'] || 1 + timeout = ENV['nameserver_validation_timeout'] || '1' dns_servers = ENV['dnssec_resolver_ips'].to_s.split(',').map(&:strip) Resolver.new({nameserver: dns_servers, timeout: timeout.to_i}) end diff --git a/config/application.yml.sample b/config/application.yml.sample index 5fdb72055..02b230ff4 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -233,4 +233,5 @@ registry_demo_registrar_results_url: 'http://registry.test/api/v1/accreditation_ registry_demo_registrar_api_user_url: 'http://registry.test/api/v1/accreditation_center/show_api_user' registry_demo_accredited_users_url: 'http://registry.test/api/v1/accreditation_center/list_accreditated_api_users' a_and_aaaa_validation_timeout: '1' +nameserver_validation_timeout: '1' diff --git a/test/integration/epp/domain/update/base_test.rb b/test/integration/epp/domain/update/base_test.rb index 580d5c603..f11007978 100644 --- a/test/integration/epp/domain/update/base_test.rb +++ b/test/integration/epp/domain/update/base_test.rb @@ -10,6 +10,8 @@ class EppDomainUpdateBaseTest < EppTestCase @original_registrant_change_verification = Setting.request_confirmation_on_registrant_change_enabled ActionMailer::Base.deliveries.clear + + Spy.on_instance_method(Actions::DomainUpdate, :check_for_valid_nameserver).and_return(true) end teardown do diff --git a/test/integration/epp/domain/update/rem_dns_test.rb b/test/integration/epp/domain/update/rem_dns_test.rb index fd46338e7..c2a624e29 100644 --- a/test/integration/epp/domain/update/rem_dns_test.rb +++ b/test/integration/epp/domain/update/rem_dns_test.rb @@ -12,6 +12,8 @@ class EppDomainUpdateRemDnsTest < EppTestCase @original_registrant_change_verification = Setting.request_confirmation_on_registrant_change_enabled ActionMailer::Base.deliveries.clear + + Spy.on_instance_method(Actions::DomainUpdate, :check_for_valid_nameserver).and_return(true) end teardown do diff --git a/test/integration/repp/v1/domains/contacts_test.rb b/test/integration/repp/v1/domains/contacts_test.rb index b9b26a745..229511a99 100644 --- a/test/integration/repp/v1/domains/contacts_test.rb +++ b/test/integration/repp/v1/domains/contacts_test.rb @@ -8,6 +8,7 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest token = "Basic #{token}" @auth_headers = { 'Authorization' => token } + Spy.on_instance_method(Actions::DomainUpdate, :check_for_valid_nameserver).and_return(true) end def test_shows_existing_domain_contacts diff --git a/test/integration/repp/v1/domains/create_test.rb b/test/integration/repp/v1/domains/create_test.rb index 7907e709e..40c5ae70e 100644 --- a/test/integration/repp/v1/domains/create_test.rb +++ b/test/integration/repp/v1/domains/create_test.rb @@ -8,6 +8,7 @@ class ReppV1DomainsCreateTest < ActionDispatch::IntegrationTest token = "Basic #{token}" @auth_headers = { 'Authorization' => token } + Spy.on_instance_method(Domains::NameserverValidator, :run).and_return({result: true, reason: ''}) end def test_creates_new_domain_successfully diff --git a/test/integration/repp/v1/domains/dnssec_test.rb b/test/integration/repp/v1/domains/dnssec_test.rb index 6835e2600..5363729e9 100644 --- a/test/integration/repp/v1/domains/dnssec_test.rb +++ b/test/integration/repp/v1/domains/dnssec_test.rb @@ -8,6 +8,7 @@ class ReppV1DomainsDnssecTest < ActionDispatch::IntegrationTest token = "Basic #{token}" @auth_headers = { 'Authorization' => token } + Spy.on_instance_method(Actions::DomainUpdate, :check_for_valid_nameserver).and_return(true) end def test_shows_dnssec_keys_associated_with_domain diff --git a/test/integration/repp/v1/domains/nameservers_test.rb b/test/integration/repp/v1/domains/nameservers_test.rb index 780e889c1..fdc53cb99 100644 --- a/test/integration/repp/v1/domains/nameservers_test.rb +++ b/test/integration/repp/v1/domains/nameservers_test.rb @@ -8,6 +8,8 @@ class ReppV1DomainsNameserversTest < ActionDispatch::IntegrationTest token = "Basic #{token}" @auth_headers = { 'Authorization' => token } + + Spy.on_instance_method(Domains::NameserverValidator, :run).and_return({result: true, reason: ''}) end def test_can_add_new_nameserver diff --git a/test/integration/repp/v1/domains/update_test.rb b/test/integration/repp/v1/domains/update_test.rb index d924fe7a3..b60bdd804 100644 --- a/test/integration/repp/v1/domains/update_test.rb +++ b/test/integration/repp/v1/domains/update_test.rb @@ -8,6 +8,7 @@ class ReppV1DomainsUpdateTest < ActionDispatch::IntegrationTest token = "Basic #{token}" @auth_headers = { 'Authorization' => token } + Spy.on_instance_method(Actions::DomainUpdate, :check_for_valid_nameserver).and_return(true) end def test_updates_transfer_code_for_domain diff --git a/test/jobs/domain_update_confirm_job_test.rb b/test/jobs/domain_update_confirm_job_test.rb index 158729ae3..4d7cc3a9c 100644 --- a/test/jobs/domain_update_confirm_job_test.rb +++ b/test/jobs/domain_update_confirm_job_test.rb @@ -14,6 +14,8 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase new_registrant_name: @new_registrant.name, new_registrant_email: @new_registrant.email, current_user_id: @user.id }) + + Spy.on_instance_method(Actions::DomainUpdate, :check_for_valid_nameserver).and_return(true) end def teardown diff --git a/test/jobs/nameserver_record_validation_job_test.rb b/test/jobs/nameserver_record_validation_job_test.rb index ceafe462f..7362cc6c1 100644 --- a/test/jobs/nameserver_record_validation_job_test.rb +++ b/test/jobs/nameserver_record_validation_job_test.rb @@ -5,21 +5,6 @@ class NameserverRecordValidationJobTest < ActiveSupport::TestCase setup do @nameserver = nameservers(:shop_ns1) - end - - def test_nameserver_should_send_notification_if_nameserver_is_failed - Spy.on_instance_method(NameserverRecordValidationJob, :validate).and_return(false) - - assert_difference 'Notification.count' do - NameserverRecordValidationJob.perform_now(@nameserver) - end - end - - def test_nameserver_should_not_send_notification_if_nameserver_is_correct - Spy.on_instance_method(NameserverRecordValidationJob, :validate).and_return(true) - - assert_no_difference 'Notification.count' do - NameserverRecordValidationJob.perform_now(@nameserver) - end + Spy.on_instance_method(Domains::NameserverValidator, :run).and_return({result: true, reason: ''}) end end diff --git a/test/models/validation_event_test.rb b/test/models/validation_event_test.rb index 86f13885f..e4cb6d5b7 100644 --- a/test/models/validation_event_test.rb +++ b/test/models/validation_event_test.rb @@ -6,6 +6,7 @@ class ValidationEventTest < ActiveSupport::TestCase @domain = domains(:shop) Setting.redemption_grace_period = 30 ActionMailer::Base.deliveries.clear + Spy.on_instance_method(Domains::NameserverValidator, :run).and_return({result: true, reason: ''}) end teardown do