mirror of
https://github.com/internetee/registry.git
synced 2025-08-02 07:52:04 +02:00
Merge branch 'master' into registry-623
# Conflicts: # db/structure.sql
This commit is contained in:
commit
ffc32b66de
72 changed files with 1004 additions and 932 deletions
|
@ -12,4 +12,18 @@ class ContactTest < ActiveSupport::TestCase
|
|||
def test_invalid_fixture_is_invalid
|
||||
assert contacts(:invalid).invalid?
|
||||
end
|
||||
|
||||
def test_in_use_if_acts_as_a_registrant
|
||||
DomainContact.delete_all
|
||||
assert @contact.in_use?
|
||||
end
|
||||
|
||||
def test_in_use_if_acts_as_a_domain_contact
|
||||
Domain.update_all(registrant_id: contacts(:william))
|
||||
assert @contact.in_use?
|
||||
end
|
||||
|
||||
def test_not_in_use_if_acts_as_neither_registrant_nor_domain_contact
|
||||
refute contacts(:not_in_use).in_use?
|
||||
end
|
||||
end
|
||||
|
|
63
test/models/contact/identical_test.rb
Normal file
63
test/models/contact/identical_test.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ContactIdenticalTest < ActiveSupport::TestCase
|
||||
REGULAR_FILTER_ATTRIBUTES = %i[
|
||||
name
|
||||
email
|
||||
phone
|
||||
fax
|
||||
ident
|
||||
ident_type
|
||||
ident_country_code
|
||||
org_name
|
||||
]
|
||||
|
||||
def setup
|
||||
@contact = contacts(:william)
|
||||
@identical = contacts(:identical_to_william)
|
||||
end
|
||||
|
||||
def test_returns_identical
|
||||
assert_equal @identical, @contact.identical(@identical.registrar)
|
||||
end
|
||||
|
||||
def test_does_not_return_non_identical
|
||||
REGULAR_FILTER_ATTRIBUTES.each do |attribute|
|
||||
previous_value = @identical.public_send(attribute)
|
||||
@identical.update_attribute(attribute, 'other')
|
||||
assert_nil @contact.identical(@identical.registrar)
|
||||
@identical.update_attribute(attribute, previous_value)
|
||||
end
|
||||
|
||||
@identical.update!({ statuses: %w[ok linked] })
|
||||
assert_nil @contact.identical(@identical.registrar)
|
||||
end
|
||||
|
||||
def test_takes_address_into_account_when_processing_enabled
|
||||
Contact.address_attribute_names.each do |attribute|
|
||||
previous_value = @identical.public_send(attribute)
|
||||
@identical.update_attribute(attribute, 'other')
|
||||
|
||||
Contact.stub :address_processing?, true do
|
||||
assert_nil @contact.identical(@identical.registrar)
|
||||
end
|
||||
|
||||
@identical.update_attribute(attribute, previous_value)
|
||||
end
|
||||
end
|
||||
|
||||
def test_ignores_address_when_processing_disabled
|
||||
Setting.address_processing = false
|
||||
|
||||
Contact.address_attribute_names.each do |attribute|
|
||||
previous_value = @identical.public_send(attribute)
|
||||
@identical.update_attribute(attribute, 'other')
|
||||
|
||||
Contact.stub :address_processing?, false do
|
||||
assert_equal @identical, @contact.identical(@identical.registrar)
|
||||
end
|
||||
|
||||
@identical.update_attribute(attribute, previous_value)
|
||||
end
|
||||
end
|
||||
end
|
19
test/models/contact/postal_address_test.rb
Normal file
19
test/models/contact/postal_address_test.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ContactPostalAddressTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@contact = contacts(:john)
|
||||
end
|
||||
|
||||
def test_invalid_if_country_code_is_invalid_and_address_processing_is_on
|
||||
Setting.address_processing = true
|
||||
@contact.country_code = 'invalid'
|
||||
assert @contact.invalid?
|
||||
end
|
||||
|
||||
def test_valid_if_country_code_is_invalid_and_address_processing_is_off
|
||||
Setting.address_processing = false
|
||||
@contact.country_code = 'invalid'
|
||||
assert @contact.valid?
|
||||
end
|
||||
end
|
|
@ -8,7 +8,6 @@ class ContactTransferTest < ActiveSupport::TestCase
|
|||
|
||||
def test_invalid_without_auth_info
|
||||
@contact.auth_info = nil
|
||||
@contact.validate
|
||||
assert @contact.invalid?
|
||||
end
|
||||
|
||||
|
@ -36,18 +35,23 @@ class ContactTransferTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_keeps_original_contact_untouched
|
||||
original_hash = @contact.to_json
|
||||
original_hash = @contact.attributes
|
||||
@contact.transfer(@new_registrar)
|
||||
@contact.reload
|
||||
assert_equal original_hash, @contact.to_json
|
||||
assert_equal original_hash, @contact.attributes
|
||||
end
|
||||
|
||||
def test_creates_new_contact
|
||||
assert_difference 'Contact.count' do
|
||||
assert_difference -> { @new_registrar.contacts.count } do
|
||||
@contact.transfer(@new_registrar)
|
||||
end
|
||||
end
|
||||
|
||||
def test_reuses_identical_contact
|
||||
identical = contacts(:identical_to_william)
|
||||
assert_equal identical, contacts(:william).transfer(@new_registrar)
|
||||
end
|
||||
|
||||
def test_bypasses_validation
|
||||
@contact = contacts(:invalid)
|
||||
|
||||
|
@ -56,12 +60,12 @@ class ContactTransferTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_changes_registrar
|
||||
def test_assigns_new_registrar
|
||||
new_contact = @contact.transfer(@new_registrar)
|
||||
assert_equal @new_registrar, new_contact.registrar
|
||||
end
|
||||
|
||||
def test_links_to_original
|
||||
def test_links_to_original_contact
|
||||
new_contact = @contact.transfer(@new_registrar)
|
||||
assert_equal @contact, new_contact.original
|
||||
end
|
|
@ -8,7 +8,6 @@ class DomainTransferableTest < ActiveSupport::TestCase
|
|||
|
||||
def test_invalid_without_transfer_code
|
||||
@domain.transfer_code = nil
|
||||
@domain.validate
|
||||
assert @domain.invalid?
|
||||
end
|
||||
|
||||
|
@ -35,7 +34,7 @@ class DomainTransferableTest < ActiveSupport::TestCase
|
|||
assert_equal '1bad4f', domain.transfer_code
|
||||
end
|
||||
|
||||
def test_changes_registrar
|
||||
def test_assigns_new_registrar
|
||||
@domain.transfer(@new_registrar)
|
||||
assert_equal @new_registrar, @domain.registrar
|
||||
end
|
||||
|
|
27
test/models/nameserver/glue_record_test.rb
Normal file
27
test/models/nameserver/glue_record_test.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'test_helper'
|
||||
|
||||
class NameserverGlueRecordTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@nameserver = nameservers(:shop_ns1)
|
||||
end
|
||||
|
||||
def test_invalid_without_ip_if_glue_record_is_required
|
||||
@nameserver.hostname = 'ns1.shop.test'
|
||||
@nameserver.ipv4 = @nameserver.ipv6 = ''
|
||||
assert @nameserver.invalid?
|
||||
assert_includes @nameserver.errors.full_messages, 'Either IPv4 or IPv6 is required' \
|
||||
' for glue record generation'
|
||||
end
|
||||
|
||||
def test_valid_with_ip_if_glue_record_is_required
|
||||
@nameserver.hostname = 'ns1.shop.test'
|
||||
@nameserver.ipv4 = ['192.0.2.1']
|
||||
@nameserver.ipv6 = ''
|
||||
assert @nameserver.valid?
|
||||
end
|
||||
|
||||
def test_valid_without_ip_if_glue_record_is_not_required
|
||||
@nameserver.ipv4 = @nameserver.ipv6 = ''
|
||||
assert @nameserver.valid?
|
||||
end
|
||||
end
|
81
test/models/nameserver_test.rb
Normal file
81
test/models/nameserver_test.rb
Normal file
|
@ -0,0 +1,81 @@
|
|||
require 'test_helper'
|
||||
|
||||
class NameserverTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@nameserver = nameservers(:shop_ns1)
|
||||
end
|
||||
|
||||
def test_valid
|
||||
assert @nameserver.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_domain
|
||||
@nameserver.domain = nil
|
||||
assert @nameserver.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_hostname
|
||||
@nameserver.hostname = ''
|
||||
assert @nameserver.invalid?
|
||||
end
|
||||
|
||||
def test_hostname_format_validation
|
||||
@nameserver.hostname = 'foo.bar'
|
||||
assert @nameserver.valid?
|
||||
|
||||
@nameserver.hostname = 'äöüõšž.ÄÖÜÕŠŽ.umlauts'
|
||||
assert @nameserver.valid?
|
||||
|
||||
@nameserver.hostname = 'foo_bar'
|
||||
assert @nameserver.invalid?
|
||||
end
|
||||
|
||||
def test_ipv4_format_validation
|
||||
@nameserver.ipv4 = ['192.0.2.1']
|
||||
assert @nameserver.valid?
|
||||
|
||||
@nameserver.ipv4 = ['0.0.0.256']
|
||||
assert @nameserver.invalid?
|
||||
|
||||
@nameserver.ipv4 = ['192.168.0.0/24']
|
||||
assert @nameserver.invalid?
|
||||
end
|
||||
|
||||
def test_ipv6_format_validation
|
||||
@nameserver.ipv6 = ['2001:db8::1']
|
||||
assert @nameserver.valid?
|
||||
|
||||
@nameserver.ipv6 = ['3ffe:0b00:0000:0001:0000:0000:000a']
|
||||
assert @nameserver.invalid?
|
||||
end
|
||||
|
||||
def test_hostnames
|
||||
assert_equal %w[ns1.bestnames.test
|
||||
ns2.bestnames.test
|
||||
ns1.bestnames.test
|
||||
ns1.bestnames.test], Nameserver.hostnames
|
||||
end
|
||||
|
||||
def test_normalizes_hostname
|
||||
@nameserver.hostname = ' ns1.bestnameS.test.'
|
||||
@nameserver.validate
|
||||
assert_equal 'ns1.bestnames.test', @nameserver.hostname
|
||||
end
|
||||
|
||||
def test_normalizes_ipv4
|
||||
@nameserver.ipv4 = [' 192.0.2.1']
|
||||
@nameserver.validate
|
||||
assert_equal ['192.0.2.1'], @nameserver.ipv4
|
||||
end
|
||||
|
||||
def test_normalizes_ipv6
|
||||
@nameserver.ipv6 = [' 2001:db8::1']
|
||||
@nameserver.validate
|
||||
assert_equal ['2001:DB8::1'], @nameserver.ipv6
|
||||
end
|
||||
|
||||
def test_encodes_hostname_to_punycode
|
||||
@nameserver.hostname = 'ns1.münchen.de'
|
||||
assert_equal 'ns1.xn--mnchen-3ya.de', @nameserver.hostname_puny
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue