diff --git a/test/helpers/form_helper_test.rb b/test/helpers/form_helper_test.rb new file mode 100644 index 000000000..199384170 --- /dev/null +++ b/test/helpers/form_helper_test.rb @@ -0,0 +1,11 @@ +require 'test_helper' + +class FormHelperTest < ActionView::TestCase + def test_legal_document_field + meth = MiniTest::Mock.new + returned_legal_document_field = ApplicationController.helpers.legal_document_field('Hello', meth) + + assert returned_legal_document_field.include? 'data-legal-document="true"' + assert returned_legal_document_field.include? 'accept=".pdf,.asice,.asics,.sce,.scs,.adoc,.edoc,.bdoc,.zip,.rar,.gz,.tar,.7z,.odt,.doc,.docx"' + end +end \ No newline at end of file diff --git a/test/helpers/form_tag_helper_test.rb b/test/helpers/form_tag_helper_test.rb new file mode 100644 index 000000000..f664957fc --- /dev/null +++ b/test/helpers/form_tag_helper_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class FormTagHelperTest < ActionView::TestCase + def test_legal_document_field + returned_legal_document_field = ApplicationController.helpers.legal_document_field_tag('Hello') + assert returned_legal_document_field.include? 'data-legal-document="true"' + assert returned_legal_document_field.include? 'accept=".pdf,.asice,.asics,.sce,.scs,.adoc,.edoc,.bdoc,.zip,.rar,.gz,.tar,.7z,.odt,.doc,.docx"' + end +end \ No newline at end of file diff --git a/test/integration/epp/contact/update/base_test.rb b/test/integration/epp/contact/update/base_test.rb index 98c0e4462..ff43905de 100644 --- a/test/integration/epp/contact/update/base_test.rb +++ b/test/integration/epp/contact/update/base_test.rb @@ -325,6 +325,104 @@ class EppContactUpdateBaseTest < EppTestCase assert_nil @contact.state end + def test_update_contact_with_update_prohibited + @contact.update(statuses: [Contact::CLIENT_UPDATE_PROHIBITED]) + @contact.update_columns(code: @contact.code.upcase) + + street = '123 Example' + city = 'Tallinn' + state = 'Harjumaa' + zip = '123456' + country_code = 'EE' + + request_xml = <<-XML + + + + + + #{@contact.code} + + + + #{street} + #{city} + #{state} + #{zip} + #{country_code} + + + + + + + + XML + + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + @contact.reload + + assert_not_equal city, @contact.city + assert_not_equal street, @contact.street + assert_not_equal zip, @contact.zip + assert_not_equal country_code, @contact.country_code + assert_not_equal state, @contact.state + + assert_epp_response :object_status_prohibits_operation + end + + def test_legal_document + assert_equal 'john-001', @contact.code + assert_not_equal 'new name', @contact.name + assert_not_equal 'new-email@inbox.test', @contact.email + assert_not_equal '+123.4', @contact.phone + + Setting.request_confirmation_on_domain_deletion_enabled = false + + # https://github.com/internetee/registry/issues/415 + @contact.update_columns(code: @contact.code.upcase) + + assert_not @contact.legal_documents.present? + + request_xml = <<-XML + + + + + + john-001 + + + new name + + +123.4 + new-email@inbox.test + + + + + + #{'test' * 2000} + + + + + XML + + assert_difference -> { @contact.legal_documents.reload.size } do + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + @contact.reload + end + + assert_epp_response :completed_successfully + assert_equal 'new name', @contact.name + assert_equal 'new-email@inbox.test', @contact.email + assert_equal '+123.4', @contact.phone + end + private def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact) diff --git a/test/integration/registrant_area/application_helper_test.rb b/test/integration/registrant_area/application_helper_test.rb new file mode 100644 index 000000000..d915baf61 --- /dev/null +++ b/test/integration/registrant_area/application_helper_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class ApplicationHelperTest < ActionView::TestCase + def test_env_style_when_pic_present + assert_dom_equal %{}, + %{} + end + + def test_env_style_return_nil + env_style = '' + assert_dom_equal %{}, + %{} + end +end diff --git a/test/integration/registrar_area/domains_test.rb b/test/integration/registrar_area/domains_test.rb index 1a4e0534c..307bcae5e 100644 --- a/test/integration/registrar_area/domains_test.rb +++ b/test/integration/registrar_area/domains_test.rb @@ -1,6 +1,8 @@ require 'test_helper' class RegistrarAreaDomainsIntegrationTest < ApplicationIntegrationTest + include FormTagHelper + setup do sign_in users(:api_bestnames) end diff --git a/test/interactions/domain_delete_interaction/domain_delete_test.rb b/test/interactions/domain_delete_interaction/domain_delete_test.rb index 9582fae03..7716ddb63 100644 --- a/test/interactions/domain_delete_interaction/domain_delete_test.rb +++ b/test/interactions/domain_delete_interaction/domain_delete_test.rb @@ -22,4 +22,43 @@ class DomainDeleteTest < ActiveSupport::TestCase Domains::Delete::DoDelete.run(domain: @domain) end end + + def test_preclean_pendings + @domain.registrant_verification_token = "123" + @domain.registrant_verification_asked_at = "123" + @domain.preclean_pendings + + assert_nil @domain.registrant_verification_token + assert_nil @domain.registrant_verification_asked_at + end + + def test_clean_pendings + @domain.is_admin = true + @domain.registrant_verification_token = "123" + @domain.registrant_verification_asked_at = "123" + @domain.pending_json = { delete: DomainStatus::PENDING_DELETE} + @domain.update(statuses: [DomainStatus::PENDING_DELETE_CONFIRMATION, + DomainStatus::PENDING_UPDATE, + DomainStatus::PENDING_DELETE, + ]) + @domain.status_notes[DomainStatus::PENDING_UPDATE] = '123' + @domain.status_notes[DomainStatus::PENDING_DELETE] = '234' + @domain.reload + + + @domain.clean_pendings! + @domain.reload + + assert @domain.is_admin + assert_nil @domain.registrant_verification_token + assert_nil @domain.registrant_verification_asked_at + assert_equal @domain.pending_json, {} + + assert (not @domain.statuses.include? DomainStatus::PENDING_DELETE_CONFIRMATION) + assert (not @domain.statuses.include? DomainStatus::PENDING_UPDATE) + assert (not @domain.statuses.include? DomainStatus::PENDING_DELETE) + + assert_equal @domain.status_notes[DomainStatus::PENDING_UPDATE], '' + assert_equal @domain.status_notes[DomainStatus::PENDING_DELETE], '' + end end diff --git a/test/jobs/domain_delete_job_test.rb b/test/jobs/domain_delete_job_test.rb new file mode 100644 index 000000000..a6f7d9065 --- /dev/null +++ b/test/jobs/domain_delete_job_test.rb @@ -0,0 +1,20 @@ +require "test_helper" + +class DomainDeleteJobTest < ActiveSupport::TestCase + setup do + travel_to Time.zone.parse('2010-07-05') + @domain = domains(:shop) + @domain.update!(delete_date:'2010-07-05') + @domain.reload + end + + def test_delete_domain + dom = Domain.find_by(id: @domain.id) + assert dom + + DomainDeleteJob.run(@domain.id) + + dom = Domain.find_by(id: @domain.id) + assert_nil dom + end +end \ No newline at end of file diff --git a/test/jobs/domain_expire_email_job_test.rb b/test/jobs/domain_expire_email_job_test.rb new file mode 100644 index 000000000..f57de2686 --- /dev/null +++ b/test/jobs/domain_expire_email_job_test.rb @@ -0,0 +1,29 @@ +require "test_helper" + +class DomainExpireEmailJobTest < ActiveSupport::TestCase + setup do + @domain = domains(:shop) + travel_to Time.zone.parse('2010-08-06') + @domain.update(valid_to: Time.now - 1.day) + @domain.reload + end + + def test_domain_expire + success = DomainExpireEmailJob.run(@domain.id) + assert success + end + + def test_domain_expire_with_force_delete + @domain.update(statuses: [DomainStatus::FORCE_DELETE]) + @domain.reload + assert_equal ['serverForceDelete'], @domain.statuses + + success = DomainExpireEmailJob.run(@domain.id) + assert success + + statuses = @domain.statuses + statuses.delete(DomainStatus::FORCE_DELETE) + @domain.update(statuses: statuses) + assert_equal ['ok'], @domain.statuses + end +end \ No newline at end of file diff --git a/test/jobs/regenerate_registrar_whoises_job_test.rb b/test/jobs/regenerate_registrar_whoises_job_test.rb new file mode 100644 index 000000000..3fe94612b --- /dev/null +++ b/test/jobs/regenerate_registrar_whoises_job_test.rb @@ -0,0 +1,13 @@ +require "test_helper" + +class RegenerateRegistrarWhoisesJobTest < ActiveSupport::TestCase + setup do + travel_to Time.zone.parse('2010-07-05 10:00') + @registrar = registrars(:bestnames) + end + + def test_job_return_true + # if return false, then job was failes + assert RegenerateRegistrarWhoisesJob.run(@registrar.id) + end +end \ No newline at end of file diff --git a/test/lib/validators/date_time_iso8601_validator_test.rb b/test/lib/validators/date_time_iso8601_validator_test.rb new file mode 100644 index 000000000..ca397c6e5 --- /dev/null +++ b/test/lib/validators/date_time_iso8601_validator_test.rb @@ -0,0 +1,62 @@ +require 'test_helper' + +class DateTimeIso8601Validatable + include ActiveModel::Validations + validates_with DateTimeIso8601Validator, :attributes=>[:errors] + attr_accessor :code, :type + validates :code, iso8601: { date_only: true }, if: :birthday? + + def birthday? + type == "birthday" + end + + def empty? + code.empty? + end +end + +class DateTimeIso8601ValidatorTest < ActiveSupport::TestCase + def test_check_invalid_reverse_date + obj = DateTimeIso8601Validatable.new + obj.type = "birthday" + obj.code = "22-12-2020" + assert_not obj.valid? + end + + def test_check_date_without_separate_symbols + obj = DateTimeIso8601Validatable.new + obj.type = "birthday" + obj.code = "24521012" + assert_not obj.valid? + end + + def test_check_empty_date + obj = DateTimeIso8601Validatable.new + obj.type = "birthday" + obj.code = "" + assert_not obj.valid? + end + + def test_check_valid_date + obj = DateTimeIso8601Validatable.new + obj.code = Date.new(2000,5,25).iso8601 + obj.type = "birthday" + assert obj.valid? + end + + def test_return_code_2005_in_epp_validate + obj = DateTimeIso8601Validatable.new + obj.code = Date.new(2000,5,25).iso8601 + obj.type = "birthday" + epp_resp = DateTimeIso8601Validator.validate_epp(obj, obj.code) + assert_equal epp_resp[:msg], "Expiry absolute must be compatible to ISO 8601" + end + + def test_epp_request_with_empty_data + obj = DateTimeIso8601Validatable.new + obj.code = "" + obj.type = "birthday" + epp_resp = DateTimeIso8601Validator.validate_epp(obj, obj.code) + assert_nil epp_resp + end +end \ No newline at end of file diff --git a/test/lib/validators/duration_iso8601_validator_test.rb b/test/lib/validators/duration_iso8601_validator_test.rb new file mode 100644 index 000000000..a4acaad60 --- /dev/null +++ b/test/lib/validators/duration_iso8601_validator_test.rb @@ -0,0 +1,57 @@ +require 'test_helper' + +class DurationIso8601Validatable + include ActiveModel::Validations + validates_with DurationIso8601Validator, :attributes=>[:errors] + attr_accessor :duration + validates :duration, inclusion: { in: Proc.new { |price| price.class.durations } } + + def self.durations + [ + '3 mons', + '6 mons', + '9 mons', + '1 year', + '2 years', + '3 years', + '4 years', + '5 years', + '6 years', + '7 years', + '8 years', + '9 years', + '10 years', + ] + end + + def empty? + duration.empty? + end +end + +class DurationIso8601ValidatorTest < ActiveSupport::TestCase + def test_valid_duration + dura = DurationIso8601Validatable.new + dura.duration = '1 year' + assert dura.valid? + end + + def test_invalid_duration + dura = DurationIso8601Validatable.new + dura.duration = 'one millinons years' + assert_not dura.valid? + end + + def test_empty_duration + dura = DurationIso8601Validatable.new + dura.duration = '' + assert_not dura.valid? + end + + def test_return_epp_response_code_2005 + dura = DurationIso8601Validatable.new + dura.duration = '1 year' + epp_resp = DurationIso8601Validator.validate_epp(dura, dura.duration) + assert_equal epp_resp[:msg], "Expiry relative must be compatible to ISO 8601" + end +end diff --git a/test/models/admin_user_test.rb b/test/models/admin_user_test.rb index aedc911bd..e737f8a3c 100644 --- a/test/models/admin_user_test.rb +++ b/test/models/admin_user_test.rb @@ -123,6 +123,15 @@ class AdminUserTest < ActiveSupport::TestCase assert user.valid? end + def test_min_password_length + assert_equal AdminUser.min_password_length, 8 + end + + def test_country_instance + user = valid_user + assert user.country.present? + end + private def valid_user diff --git a/test/models/certificate_test.rb b/test/models/certificate_test.rb new file mode 100644 index 000000000..a48c6081f --- /dev/null +++ b/test/models/certificate_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' + +class CertificateTest < ActiveSupport::TestCase + setup do + @certificate = certificates(:api) + @certificate.update!(csr: "-----BEGIN CERTIFICATE REQUEST-----\nMIICszCCAZsCAQAwbjELMAkGA1UEBhMCRUUxFDASBgNVBAMMC2ZyZXNoYm94LmVl\nMRAwDgYDVQQHDAdUYWxsaW5uMREwDwYDVQQKDAhGcmVzaGJveDERMA8GA1UECAwI\nSGFyanVtYWExETAPBgNVBAsMCEZyZXNoYm94MIIBIjANBgkqhkiG9w0BAQEFAAOC\nAQ8AMIIBCgKCAQEA1VVESynZoZhIbe8s9zHkELZ/ZDCGiM2Q8IIGb1IOieT5U2mx\nIsVXz85USYsSQY9+4YdEXnupq9fShArT8pstS/VN6BnxdfAiYXc3UWWAuaYAdNGJ\nDr5Jf6uMt1wVnCgoDL7eJq9tWMwARC/viT81o92fgqHFHW0wEolfCmnpik9o0ACD\nFiWZ9IBIevmFqXtq25v9CY2cT9+eZW127WtJmOY/PKJhzh0QaEYHqXTHWOLZWpnp\nHH4elyJ2CrFulOZbHPkPNB9Nf4XQjzk1ffoH6e5IVys2VV5xwcTkF0jY5XTROVxX\nlR2FWqic8Q2pIhSks48+J6o1GtXGnTxv94lSDwIDAQABoAAwDQYJKoZIhvcNAQEL\nBQADggEBAEFcYmQvcAC8773eRTWBJJNoA4kRgoXDMYiiEHih5iJPVSxfidRwYDTF\nsP+ttNTUg3JocFHY75kuM9T2USh+gu/trRF0o4WWa+AbK3JbbdjdT1xOMn7XtfUU\nZ/f1XCS9YdHQFCA6nk4Z+TLWwYsgk7n490AQOiB213fa1UIe83qIfw/3GRqRUZ7U\nwIWEGsHED5WT69GyxjyKHcqGoV7uFnqFN0sQVKVTy/NFRVQvtBUspCbsOirdDRie\nAB2KbGHL+t1QrRF10szwCJDyk5aYlVhxvdI8zn010nrxHkiyQpDFFldDMLJl10BW\n2w9PGO061z+tntdRcKQGuEpnIr9U5Vs=\n-----END CERTIFICATE REQUEST-----\n") + end + + def test_does_metadata_is_api + api = @certificate.assign_metadata + assert api, 'api' + end + + def test_certificate_sign_returns_false + assert_not @certificate.sign!, 'false' + end +end \ No newline at end of file diff --git a/test/models/disputed_domain_test.rb b/test/models/disputed_domain_test.rb index 01897e19b..a37a61c37 100644 --- a/test/models/disputed_domain_test.rb +++ b/test/models/disputed_domain_test.rb @@ -16,6 +16,20 @@ class DisputedDomainTest < ActiveSupport::TestCase @dispute.reload assert @dispute.closed + assert @dispute.forward_to_auction_if_possible + + n = Whois::Record.find_by(name: @dispute.domain_name) + assert @dispute.remove_whois_data(n) + end + + def test_invalid_auth + travel_to Time.zone.parse('2010-10-05') + assert_not Dispute.valid_auth?(nil, nil) + end + + def test_valid_auth + travel_to Time.zone.parse('2010-10-05') + assert Dispute.valid_auth?(@dispute.domain_name, @dispute.password) end def test_syncs_password_to_reserved diff --git a/test/models/dnskey_test.rb b/test/models/dnskey_test.rb new file mode 100644 index 000000000..2f4eff3af --- /dev/null +++ b/test/models/dnskey_test.rb @@ -0,0 +1,58 @@ +require 'test_helper' + +class DnskeyTest < ActiveSupport::TestCase + include EppErrors + + setup do + @dnskey = 'AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8' + @domain = domains(:shop) + end + + def test_valid_dns_key + dns = Dnskey.new + dns.domain_id = @domain.id + dns.flags = 257 + dns.protocol = 3 + dns.alg = 8 + dns.public_key = @dnskey + + assert dns.save + end + + def test_invalid_algrorithm + dns = Dnskey.new + dns.alg = 666 + errors = dns.validate_algorithm + assert_equal errors, ['Valid algorithms are: 3, 5, 6, 7, 8, 10, 13, 14'] + end + + def test_invalid_protocol + dns = Dnskey.new + dns.protocol = 666 + errors = dns.validate_protocol + assert_equal errors, ['Valid protocols are: 3'] + end + + def test_invalid_flags + dns = Dnskey.new + dns.flags = 666 + errors = dns.validate_flags + assert_equal errors, ['Valid flags are: 0, 256, 257'] + end + + def test_ds_digest_type_one + Setting.ds_digest_type = 1 + + dns = Dnskey.new + dns.domain_id = @domain.id + dns.flags = 257 + dns.protocol = 3 + dns.alg = 8 + dns.public_key = @dnskey + + assert dns.save + + assert_equal dns.ds_digest_type, 1 + assert_equal dns.ds_digest, '640D173A44D9AF2856FBE282EE64CE11A76DBB84' + end +end \ No newline at end of file diff --git a/test/models/domain_contact_test.rb b/test/models/domain_contact_test.rb new file mode 100644 index 000000000..4bfefb7f1 --- /dev/null +++ b/test/models/domain_contact_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' + +class DomainContactTest < ActiveSupport::TestCase + setup do + @domain_contact = domain_contacts(:shop_jane) + end + + def test_if_domain_contact_type_invalid + @domain_contact.update(type: "Some") + assert @domain_contact.name, '' + end + + def test_value_typeahead + assert @domain_contact.value_typeahead, 'Jane' + end + +end \ No newline at end of file diff --git a/test/models/legal_document_test.rb b/test/models/legal_document_test.rb index f09c52047..e187f6fc3 100644 --- a/test/models/legal_document_test.rb +++ b/test/models/legal_document_test.rb @@ -5,6 +5,10 @@ class LegalDocumentTest < ActiveSupport::TestCase assert valid_legal_document.valid?, proc { valid_legal_document.errors.full_messages } end + def test_duplicate_legal_docs + assert LegalDocument.remove_duplicates + end + private def valid_legal_document diff --git a/test/models/mass_action_test.rb b/test/models/mass_action_test.rb new file mode 100644 index 000000000..8c730a5e6 --- /dev/null +++ b/test/models/mass_action_test.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class MassActionTest < ActiveSupport::TestCase + setup do + @csv_valid = Rails.root.join('test', 'fixtures', 'files', 'mass_actions', 'valid_mass_force_delete_list.csv').to_s + @csv_invalid = Rails.root.join('test', 'fixtures', 'files', 'mass_actions', 'invalid_mass_force_delete_list.csv').to_s + end + + def test_mass_action_procces_with_valid_data + assert MassAction.process("force_delete", @csv_valid) + end + + def test_mass_action_proccess_with_invalid_data + assert_not MassAction.process("force_delete", @csv_invalid) + end + + def test_mass_action_invalid_attributes + assert_not MassAction.process("force_restart", @csv_valid) + end +end \ No newline at end of file diff --git a/test/models/whois/record_test.rb b/test/models/whois/record_test.rb index d06b23cae..eceba9205 100644 --- a/test/models/whois/record_test.rb +++ b/test/models/whois/record_test.rb @@ -15,6 +15,11 @@ class Whois::RecordTest < ActiveSupport::TestCase Setting.registry_whois_disclaimer = @original_disclaimer end + def test_whois_records_without_auction + domain = Whois::Record.without_auctions + assert_equal domain[0].name, 'shop.test' + end + def test_reads_disclaimer_setting Setting.registry_whois_disclaimer = JSON.generate({en: 'test_disclaimer'}) assert_equal Setting.registry_whois_disclaimer, Whois::Record.disclaimer diff --git a/test/system/admin_area/contacts_test.rb b/test/system/admin_area/contacts_test.rb index 19b15c8a5..92b0a064b 100644 --- a/test/system/admin_area/contacts_test.rb +++ b/test/system/admin_area/contacts_test.rb @@ -9,7 +9,7 @@ class AdminContactsTest < ApplicationSystemTestCase end def test_update_contact - visit admin_contact_path(id: @contact.id) + visit admin_contact_path(@contact.id) assert_text "#{@contact.name}" click_on 'Edit statuses' diff --git a/test/system/admin_area/domain_versions_test.rb b/test/system/admin_area/domain_versions_test.rb index 8ff90a562..833398c61 100644 --- a/test/system/admin_area/domain_versions_test.rb +++ b/test/system/admin_area/domain_versions_test.rb @@ -5,6 +5,7 @@ class DomainVersionsTest < ApplicationSystemTestCase super @registrar = registrars(:bestnames) + @domain = domains(:shop) create_domain_with_history sign_in users(:admin) @@ -59,4 +60,35 @@ class DomainVersionsTest < ApplicationSystemTestCase assert_text 'Best Names' assert_text '23.04.18, 18:50 update 1-AdminUser' end + + def test_search_registrant_param + visit admin_domain_versions_path + fill_in 'Registrant', with: @domain.registrant, match: :first + find('.btn.btn-primary').click + + assert_equal current_url, + 'http://www.example.com/admin/domain_versions?q[name]=&q[registrant]=John&q[registrar]=&q[event]=&results_per_page=' + end + + def test_search_registrar_param + visit admin_domain_versions_path + find('#q_registrar').set(@domain.registrar) + find('.btn.btn-primary').click + + assert_equal current_url, + 'http://www.example.com/admin/domain_versions?q[name]=&q[registrant]=&q[registrar]=Best+Names&q[event]=&results_per_page=' + end + + def test_search_name_param + visit admin_domain_versions_path + fill_in 'Name', with: @domain.name, match: :first + find('.btn.btn-primary').click + + assert_equal current_url, + 'http://www.example.com/admin/domain_versions?q[name]=shop.test&q[registrant]=&q[registrar]=&q[event]=&results_per_page=' + end + + def test_search_event_param + # TODO + end end