mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
Remove specs
This commit is contained in:
parent
68750883f0
commit
54577b530b
127 changed files with 1954 additions and 7197 deletions
142
test/models/admin_user_test.rb
Normal file
142
test/models/admin_user_test.rb
Normal file
|
@ -0,0 +1,142 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AdminUserTest < ActiveSupport::TestCase
|
||||
def test_valid_user_fixture_is_valid
|
||||
assert valid_user.valid?, proc { valid_user.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_without_username
|
||||
user = valid_user
|
||||
user.username = ''
|
||||
assert user.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_password_and_password_confirmation_when_creating
|
||||
user = valid_non_persisted_user
|
||||
|
||||
user.password = ''
|
||||
user.password_confirmation = ''
|
||||
assert user.invalid?
|
||||
|
||||
user.password = valid_password
|
||||
user.password_confirmation = user.password
|
||||
assert user.valid?
|
||||
end
|
||||
|
||||
def test_validates_password_format
|
||||
user = valid_non_persisted_user
|
||||
|
||||
user.password = 'a' * (Devise.password_length.min.pred)
|
||||
user.password_confirmation = user.password
|
||||
assert user.invalid?
|
||||
|
||||
user.password = 'a' * (Devise.password_length.max.next)
|
||||
user.password_confirmation = user.password
|
||||
assert user.invalid?
|
||||
|
||||
user.password = 'a' * Devise.password_length.min
|
||||
user.password_confirmation = user.password
|
||||
assert user.valid?
|
||||
|
||||
user.password = 'a' * Devise.password_length.max
|
||||
user.password_confirmation = user.password
|
||||
assert user.valid?
|
||||
end
|
||||
|
||||
def test_requires_password_confirmation
|
||||
user = valid_non_persisted_user
|
||||
user.password = valid_password
|
||||
|
||||
user.password_confirmation = ''
|
||||
assert user.invalid?
|
||||
|
||||
user.password_confirmation = 'another'
|
||||
assert user.invalid?
|
||||
|
||||
user.password_confirmation = user.password
|
||||
assert user.valid?, proc { user.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_without_email
|
||||
user = valid_user
|
||||
user.email = ''
|
||||
assert user.invalid?
|
||||
end
|
||||
|
||||
def test_validates_email_format
|
||||
user = valid_user
|
||||
|
||||
user.email = 'invalid'
|
||||
assert user.invalid?
|
||||
|
||||
user.email = 'valid@registry.test'
|
||||
assert user.valid?
|
||||
end
|
||||
|
||||
def test_invalid_when_email_is_already_taken
|
||||
another_user = valid_user
|
||||
user = valid_non_persisted_user
|
||||
|
||||
user.email = another_user.email
|
||||
assert user.invalid?
|
||||
|
||||
user.email = 'new-user@registry.test'
|
||||
assert user.valid?, proc { user.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_without_country_code
|
||||
user = valid_user
|
||||
user.country_code = ''
|
||||
assert user.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_roles
|
||||
user = valid_user
|
||||
user.roles = []
|
||||
assert user.invalid?
|
||||
end
|
||||
|
||||
def test_valid_without_identity_code
|
||||
user = valid_user
|
||||
user.identity_code = ''
|
||||
assert user.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_identity_code_when_country_code_is_estonia
|
||||
user = valid_user
|
||||
user.country_code = 'EE'
|
||||
|
||||
user.identity_code = ''
|
||||
|
||||
assert user.invalid?
|
||||
end
|
||||
|
||||
# https://en.wikipedia.org/wiki/National_identification_number#Estonia
|
||||
def test_validates_identity_code_format_when_country_code_is_estonia
|
||||
user = valid_user
|
||||
user.country_code = 'EE'
|
||||
|
||||
user.identity_code = '47101010030'
|
||||
assert user.invalid?
|
||||
|
||||
user.identity_code = '47101010033'
|
||||
assert user.valid?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_user
|
||||
users(:admin)
|
||||
end
|
||||
|
||||
def valid_non_persisted_user
|
||||
user = valid_user.dup
|
||||
user.password = user.password_confirmation = valid_password
|
||||
user.email = 'another@registry.test'
|
||||
user
|
||||
end
|
||||
|
||||
def valid_password
|
||||
'a' * Devise.password_length.min
|
||||
end
|
||||
end
|
|
@ -5,6 +5,53 @@ class ApiUserTest < ActiveSupport::TestCase
|
|||
@user = users(:api_bestnames)
|
||||
end
|
||||
|
||||
def test_valid_user_fixture_is_valid
|
||||
assert valid_user.valid?, proc { valid_user.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_without_username
|
||||
user = valid_user
|
||||
user.username = ''
|
||||
assert user.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_when_username_is_already_taken
|
||||
user = valid_user
|
||||
another_user = user.dup
|
||||
|
||||
assert another_user.invalid?
|
||||
|
||||
another_user.username = 'another'
|
||||
assert another_user.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_password
|
||||
user = valid_user
|
||||
user.plain_text_password = ''
|
||||
assert user.invalid?
|
||||
end
|
||||
|
||||
def test_validates_password_format
|
||||
user = valid_user
|
||||
min_length = ApiUser.min_password_length
|
||||
|
||||
user.plain_text_password = 'a' * (min_length.pred)
|
||||
assert user.invalid?
|
||||
|
||||
user.plain_text_password = 'a' * min_length
|
||||
assert user.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_roles
|
||||
user = valid_user
|
||||
user.roles = []
|
||||
assert user.invalid?
|
||||
end
|
||||
|
||||
def test_active_by_default
|
||||
assert ApiUser.new.active?
|
||||
end
|
||||
|
||||
def test_finds_user_by_id_card
|
||||
id_card = IdCard.new
|
||||
id_card.personal_code = 'one'
|
||||
|
@ -15,4 +62,10 @@ class ApiUserTest < ActiveSupport::TestCase
|
|||
@user.update!(identity_code: 'another')
|
||||
assert_nil ApiUser.find_by_id_card(id_card)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_user
|
||||
users(:api_bestnames)
|
||||
end
|
||||
end
|
||||
|
|
106
test/models/billing/price_test.rb
Normal file
106
test/models/billing/price_test.rb
Normal file
|
@ -0,0 +1,106 @@
|
|||
require 'test_helper'
|
||||
|
||||
class Billing::PriceTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@user = users(:api_bestnames)
|
||||
end
|
||||
|
||||
def test_valid_price_fixture_is_valid
|
||||
assert valid_price.valid?, proc { valid_price.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_without_price
|
||||
price = valid_price
|
||||
price.price = ''
|
||||
assert price.invalid?
|
||||
end
|
||||
|
||||
def test_validates_price_format
|
||||
price = valid_price
|
||||
|
||||
price.price = -1
|
||||
assert price.invalid?
|
||||
|
||||
price.price = 0
|
||||
assert price.valid?, proc { price.errors.full_messages }
|
||||
|
||||
price.price = "1#{I18n.t('number.currency.format.separator')}1"
|
||||
assert price.valid?
|
||||
|
||||
price.price = 1
|
||||
assert price.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_effective_date
|
||||
price = valid_price
|
||||
price.valid_from = ''
|
||||
assert price.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_operation_category
|
||||
price = valid_price
|
||||
price.operation_category = ''
|
||||
assert price.invalid?
|
||||
end
|
||||
|
||||
def test_validates_operation_category_format
|
||||
price = valid_price
|
||||
|
||||
price.operation_category = 'invalid'
|
||||
assert price.invalid?
|
||||
|
||||
price.operation_category = Billing::Price.operation_categories.first
|
||||
assert price.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_duration
|
||||
price = valid_price
|
||||
price.duration = ''
|
||||
assert price.invalid?
|
||||
end
|
||||
|
||||
def test_validates_duration_format
|
||||
price = valid_price
|
||||
|
||||
price.duration = 'invalid'
|
||||
assert price.invalid?
|
||||
|
||||
price.duration = Billing::Price.durations.first
|
||||
assert price.valid?
|
||||
end
|
||||
|
||||
def test_returns_operation_categories
|
||||
operation_categories = %w[create renew]
|
||||
assert_equal operation_categories, Billing::Price.operation_categories
|
||||
end
|
||||
|
||||
def test_returns_durations
|
||||
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',
|
||||
]
|
||||
assert_equal durations, Billing::Price.durations
|
||||
end
|
||||
|
||||
def test_returns_statuses
|
||||
statuses = %w[upcoming effective expired]
|
||||
assert_equal statuses, Billing::Price.statuses
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_price
|
||||
billing_prices(:create_one_month)
|
||||
end
|
||||
end
|
128
test/models/contact/ident_test.rb
Normal file
128
test/models/contact/ident_test.rb
Normal file
|
@ -0,0 +1,128 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ContactIdentTest < ActiveSupport::TestCase
|
||||
def test_valid_ident_is_valid
|
||||
assert valid_ident.valid?, proc { valid_ident.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_without_code
|
||||
ident = valid_ident
|
||||
ident.code = ''
|
||||
assert ident.invalid?
|
||||
end
|
||||
|
||||
def test_validates_date_of_birth
|
||||
ident = valid_ident
|
||||
ident.type = 'birthday'
|
||||
|
||||
ident.code = '2010-07-05'
|
||||
assert ident.valid?
|
||||
|
||||
ident.code = '2010-07-0'
|
||||
assert ident.invalid?
|
||||
end
|
||||
|
||||
# https://en.wikipedia.org/wiki/National_identification_number#Estonia
|
||||
def test_country_specific_national_id_format_validation
|
||||
country = Country.new('EE')
|
||||
ident = valid_ident
|
||||
ident.type = 'priv'
|
||||
ident.country_code = country.alpha2
|
||||
|
||||
ident.code = 'invalid'
|
||||
assert ident.invalid?
|
||||
assert_includes ident.errors.full_messages, "Code does not conform to national identification number format of #{country}"
|
||||
|
||||
ident.code = '47101010033'
|
||||
assert ident.valid?
|
||||
|
||||
ident.country_code = 'US'
|
||||
ident.code = 'any'
|
||||
assert ident.valid?
|
||||
end
|
||||
|
||||
def test_country_specific_company_registration_number_format_validation
|
||||
country = Country.new('EE')
|
||||
ident = valid_ident
|
||||
ident.type = 'org'
|
||||
ident.country_code = country.alpha2
|
||||
allowed_length = 8
|
||||
|
||||
ident.code = '1' * allowed_length.pred
|
||||
assert ident.invalid?
|
||||
assert_includes ident.errors.full_messages, "Code does not conform to registration number format of #{country}"
|
||||
|
||||
ident.code = '1' * allowed_length.next
|
||||
assert ident.invalid?
|
||||
|
||||
ident.code = '1' * allowed_length
|
||||
assert ident.valid?
|
||||
|
||||
ident.country_code = 'US'
|
||||
ident.code = 'any'
|
||||
assert ident.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_type
|
||||
ident = valid_ident
|
||||
ident.type = ''
|
||||
assert ident.invalid?
|
||||
end
|
||||
|
||||
def test_validates_type
|
||||
assert_not_includes Contact::Ident.types, 'invalid'
|
||||
ident = valid_ident
|
||||
ident.type = 'invalid'
|
||||
|
||||
assert ident.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_country_code
|
||||
ident = valid_ident
|
||||
ident.country_code = ''
|
||||
assert ident.invalid?
|
||||
end
|
||||
|
||||
def test_validates_country_code_format
|
||||
ident = valid_ident
|
||||
|
||||
ident.country_code = 'invalid'
|
||||
assert ident.invalid?
|
||||
|
||||
ident.country_code = 'US'
|
||||
assert ident.valid?
|
||||
end
|
||||
|
||||
def test_validates_for_mismatches
|
||||
ident = valid_ident
|
||||
mismatch = Contact::Ident::MismatchValidator.mismatches.first
|
||||
ident.type = mismatch.type
|
||||
ident.country_code = mismatch.country.alpha2
|
||||
|
||||
assert ident.invalid?
|
||||
assert_includes ident.errors.full_messages, %(Ident type "#{ident.type}" is invalid for #{ident.country})
|
||||
end
|
||||
|
||||
def test_returns_types
|
||||
assert_equal %w[org priv birthday], Contact::Ident.types
|
||||
end
|
||||
|
||||
def test_returns_country
|
||||
country_code = 'US'
|
||||
ident = Contact::Ident.new(country_code: country_code)
|
||||
assert_equal Country.new(country_code), ident.country
|
||||
end
|
||||
|
||||
def test_equality
|
||||
assert_equal Contact::Ident.new(code: 'code', type: 'type', country_code: 'US'),
|
||||
Contact::Ident.new(code: 'code', type: 'type', country_code: 'US')
|
||||
assert_not_equal Contact::Ident.new(code: 'code', type: 'type', country_code: 'US'),
|
||||
Contact::Ident.new(code: 'code', type: 'type', country_code: 'GB')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_ident
|
||||
Contact::Ident.new(code: '1234', type: 'priv', country_code: 'US')
|
||||
end
|
||||
end
|
|
@ -5,8 +5,8 @@ class ContactTest < ActiveSupport::TestCase
|
|||
@contact = contacts(:john)
|
||||
end
|
||||
|
||||
def test_valid_fixture_is_valid
|
||||
assert @contact.valid?, proc { @contact.errors.full_messages }
|
||||
def test_valid_contact_fixture_is_valid
|
||||
assert valid_contact.valid?, proc { valid_contact.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_fixture_is_invalid
|
||||
|
@ -21,30 +21,106 @@ class ContactTest < ActiveSupport::TestCase
|
|||
assert_equal 'org', Contact::ORG
|
||||
end
|
||||
|
||||
def test_invalid_without_email
|
||||
@contact.email = ''
|
||||
assert @contact.invalid?
|
||||
def test_invalid_without_name
|
||||
contact = valid_contact
|
||||
contact.name = ''
|
||||
assert contact.invalid?
|
||||
end
|
||||
|
||||
def test_email_format_validation
|
||||
@contact.email = 'invalid'
|
||||
assert @contact.invalid?
|
||||
def test_validates_code_format
|
||||
contact = valid_contact.dup
|
||||
max_length = 100
|
||||
|
||||
@contact.email = 'test@bestmail.test'
|
||||
assert @contact.valid?
|
||||
contact.code = '!invalid'
|
||||
assert contact.invalid?
|
||||
|
||||
contact.code = 'a' * max_length.next
|
||||
assert contact.invalid?
|
||||
|
||||
contact.code = 'foo:bar'
|
||||
assert contact.valid?
|
||||
|
||||
contact.code = 'a' * max_length
|
||||
assert contact.valid?
|
||||
end
|
||||
|
||||
def test_invalid_when_code_is_already_taken
|
||||
another_contact = valid_contact
|
||||
contact = another_contact.dup
|
||||
|
||||
contact.code = another_contact.code
|
||||
assert contact.invalid?
|
||||
|
||||
contact.regenerate_code
|
||||
assert contact.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_email
|
||||
contact = valid_contact
|
||||
contact.email = ''
|
||||
assert contact.invalid?
|
||||
end
|
||||
|
||||
def test_validates_email_format
|
||||
contact = valid_contact
|
||||
|
||||
contact.email = 'invalid'
|
||||
assert contact.invalid?
|
||||
|
||||
contact.email = 'valid@registrar.test'
|
||||
assert contact.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_phone
|
||||
@contact.email = ''
|
||||
assert @contact.invalid?
|
||||
contact = valid_contact
|
||||
contact.phone = ''
|
||||
assert contact.invalid?
|
||||
end
|
||||
|
||||
def test_phone_format_validation
|
||||
@contact.phone = '+123.'
|
||||
assert @contact.invalid?
|
||||
# https://en.wikipedia.org/wiki/E.164
|
||||
def test_validates_phone_format
|
||||
contact = valid_contact
|
||||
|
||||
@contact.phone = '+123.4'
|
||||
assert @contact.valid?
|
||||
contact.phone = '+.1'
|
||||
assert contact.invalid?
|
||||
|
||||
contact.phone = '+123.'
|
||||
assert contact.invalid?
|
||||
|
||||
contact.phone = '+1.123456789123456'
|
||||
assert contact.invalid?
|
||||
|
||||
contact.phone = '+134.1234567891234'
|
||||
assert contact.invalid?
|
||||
|
||||
contact.phone = '+000.1'
|
||||
assert contact.invalid?
|
||||
|
||||
contact.phone = '+123.0'
|
||||
assert contact.invalid?
|
||||
|
||||
contact.phone = '+1.2'
|
||||
assert contact.valid?
|
||||
|
||||
contact.phone = '+123.4'
|
||||
assert contact.valid?
|
||||
|
||||
contact.phone = '+1.12345678912345'
|
||||
assert contact.valid?
|
||||
|
||||
contact.phone = '+134.123456789123'
|
||||
assert contact.valid?
|
||||
end
|
||||
|
||||
def test_valid_without_address_when_address_processing_id_disabled
|
||||
contact = valid_contact
|
||||
|
||||
contact.street = ''
|
||||
contact.city = ''
|
||||
contact.zip = ''
|
||||
contact.country_code = ''
|
||||
|
||||
assert contact.valid?
|
||||
end
|
||||
|
||||
def test_address
|
||||
|
@ -133,6 +209,45 @@ class ContactTest < ActiveSupport::TestCase
|
|||
assert_not @contact.deletable?
|
||||
end
|
||||
|
||||
def test_normalizes_country_code
|
||||
contact = Contact.new(country_code: 'us')
|
||||
contact.validate
|
||||
assert_equal 'US', contact.country_code
|
||||
end
|
||||
|
||||
def test_normalizes_ident_country_code
|
||||
contact = Contact.new(ident_country_code: 'us')
|
||||
contact.validate
|
||||
assert_equal 'US', contact.ident_country_code
|
||||
end
|
||||
|
||||
def test_generates_code
|
||||
contact = Contact.new(registrar: registrars(:bestnames))
|
||||
assert_nil contact.code
|
||||
|
||||
contact.generate_code
|
||||
|
||||
assert_not_empty contact.code
|
||||
end
|
||||
|
||||
def test_prohibits_code_change
|
||||
assert_no_changes -> { @contact.code } do
|
||||
@contact.code = 'new'
|
||||
@contact.save!
|
||||
@contact.reload
|
||||
end
|
||||
end
|
||||
|
||||
def test_removes_duplicate_statuses
|
||||
contact = Contact.new(statuses: %w[ok ok])
|
||||
assert_equal %w[ok], contact.statuses
|
||||
end
|
||||
|
||||
def test_default_status
|
||||
contact = Contact.new
|
||||
assert_equal %w[ok], contact.statuses
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact)
|
||||
|
@ -146,4 +261,8 @@ class ContactTest < ActiveSupport::TestCase
|
|||
DomainContact.delete_all
|
||||
contacts(:john)
|
||||
end
|
||||
end
|
||||
|
||||
def valid_contact
|
||||
contacts(:john)
|
||||
end
|
||||
end
|
||||
|
|
132
test/models/dns/zone_test.rb
Normal file
132
test/models/dns/zone_test.rb
Normal file
|
@ -0,0 +1,132 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DNS::ZoneTest < ActiveSupport::TestCase
|
||||
def test_valid_zone_fixture_is_valid
|
||||
assert valid_zone.valid?, proc { valid_zone.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_without_origin
|
||||
zone = valid_zone
|
||||
zone.origin = ''
|
||||
assert zone.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_when_origin_is_already_taken
|
||||
zone = valid_zone
|
||||
another_zone = zone.dup
|
||||
assert another_zone.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_ttl
|
||||
zone = valid_zone
|
||||
zone.ttl = ''
|
||||
assert zone.invalid?
|
||||
end
|
||||
|
||||
def test_validates_ttl_format
|
||||
zone = valid_zone
|
||||
|
||||
zone.ttl = 'text'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.ttl = '1.1'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.ttl = '1'
|
||||
assert zone.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_refresh
|
||||
zone = valid_zone
|
||||
zone.refresh = ''
|
||||
assert zone.invalid?
|
||||
end
|
||||
|
||||
def test_validates_refresh_format
|
||||
zone = valid_zone
|
||||
|
||||
zone.refresh = 'text'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.refresh = '1.1'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.refresh = '1'
|
||||
assert zone.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_retry
|
||||
zone = valid_zone
|
||||
zone.retry = ''
|
||||
assert zone.invalid?
|
||||
end
|
||||
|
||||
def test_validates_retry_format
|
||||
zone = valid_zone
|
||||
|
||||
zone.retry = 'text'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.retry = '1.1'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.retry = '1'
|
||||
assert zone.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_expire
|
||||
zone = valid_zone
|
||||
zone.expire = ''
|
||||
assert zone.invalid?
|
||||
end
|
||||
|
||||
def test_validates_expire_format
|
||||
zone = valid_zone
|
||||
|
||||
zone.expire = 'text'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.expire = '1.1'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.expire = '1'
|
||||
assert zone.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_minimum_ttl
|
||||
zone = valid_zone
|
||||
zone.minimum_ttl = ''
|
||||
assert zone.invalid?
|
||||
end
|
||||
|
||||
def test_validates_minimum_ttl_format
|
||||
zone = valid_zone
|
||||
|
||||
zone.minimum_ttl = 'text'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.minimum_ttl = '1.1'
|
||||
assert zone.invalid?
|
||||
|
||||
zone.minimum_ttl = '1'
|
||||
assert zone.valid?
|
||||
end
|
||||
|
||||
def test_invalid_without_email
|
||||
zone = valid_zone
|
||||
zone.email = ''
|
||||
assert zone.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_master_nameserver
|
||||
zone = valid_zone
|
||||
zone.master_nameserver = ''
|
||||
assert zone.invalid?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_zone
|
||||
dns_zones(:one)
|
||||
end
|
||||
end
|
|
@ -3,16 +3,271 @@ require 'test_helper'
|
|||
class DomainTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@domain = domains(:shop)
|
||||
|
||||
@original_nameserver_required = Setting.nameserver_required
|
||||
@original_min_admin_contact_count = Setting.admin_contacts_min_count
|
||||
@original_max_admin_contact_count = Setting.admin_contacts_max_count
|
||||
@original_min_tech_contact_count = Setting.tech_contacts_min_count
|
||||
@original_max_tech_contact_count = Setting.tech_contacts_max_count
|
||||
end
|
||||
|
||||
def test_valid_fixture_is_valid
|
||||
assert @domain.valid?
|
||||
teardown do
|
||||
Setting.nameserver_required = @original_nameserver_required
|
||||
Setting.admin_contacts_min_count = @original_min_admin_contact_count
|
||||
Setting.admin_contacts_max_count = @original_max_admin_contact_count
|
||||
Setting.tech_contacts_min_count = @original_min_tech_contact_count
|
||||
Setting.tech_contacts_max_count = @original_max_tech_contact_count
|
||||
end
|
||||
|
||||
def test_valid_domain_is_valid
|
||||
assert valid_domain.valid?, proc { valid_domain.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_fixture_is_invalid
|
||||
assert domains(:invalid).invalid?
|
||||
end
|
||||
|
||||
# https://www.internet.ee/domeenid/ee-domeenireeglid#domeeninimede-registreerimine
|
||||
def test_validates_name_format
|
||||
assert_equal dns_zones(:one).origin, 'test'
|
||||
domain = valid_domain
|
||||
subdomain_min_length = 2
|
||||
subdomain_max_length = 63
|
||||
|
||||
domain.name = '!invalid'
|
||||
assert domain.invalid?
|
||||
|
||||
domain.name = 'aa--a.test'
|
||||
assert domain.invalid?
|
||||
|
||||
domain.name = '-example.test'
|
||||
assert domain.invalid?
|
||||
|
||||
domain.name = 'example-.test'
|
||||
assert domain.invalid?
|
||||
|
||||
domain.name = "#{'a' * subdomain_min_length.pred}.test"
|
||||
assert domain.invalid?
|
||||
|
||||
domain.name = "#{'a' * subdomain_max_length.next}.test"
|
||||
assert domain.invalid?
|
||||
|
||||
domain.name = 'рф.test'
|
||||
assert domain.invalid?
|
||||
|
||||
domain.name = "#{'a' * subdomain_min_length}.test"
|
||||
assert domain.valid?
|
||||
|
||||
domain.name = "#{'a' * subdomain_max_length}.test"
|
||||
assert domain.valid?
|
||||
|
||||
domain.name = 'example-1-2.test'
|
||||
assert domain.valid?
|
||||
|
||||
domain.name = 'EXAMPLE.test'
|
||||
assert domain.valid?
|
||||
|
||||
domain.name = 'äõöüšž.test'
|
||||
assert domain.valid?
|
||||
|
||||
domain.name = 'xn--mnchen-3ya.test'
|
||||
assert domain.valid?
|
||||
end
|
||||
|
||||
def test_invalid_when_name_is_already_taken
|
||||
Setting.admin_contacts_min_count = Setting.tech_contacts_min_count = 0
|
||||
another_domain = valid_domain
|
||||
domain = another_domain.dup
|
||||
|
||||
domain.name = another_domain.name
|
||||
assert domain.invalid?
|
||||
|
||||
domain.name = "new.#{dns_zones(:one).origin}"
|
||||
assert domain.valid?, proc { domain.errors.full_messages }
|
||||
end
|
||||
|
||||
def test_invalid_when_name_is_zone
|
||||
name = dns_zones(:one).origin
|
||||
domain = valid_domain
|
||||
|
||||
domain.name = name
|
||||
|
||||
assert domain.invalid?
|
||||
assert_includes domain.errors.full_messages, 'Data management policy violation:' \
|
||||
' Domain name is blocked [name]'
|
||||
end
|
||||
|
||||
def test_invalid_without_transfer_code
|
||||
domain = valid_domain
|
||||
domain.transfer_code = ''
|
||||
assert domain.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_when_domain_is_reserved
|
||||
reserved_domain = reserved_domains(:one)
|
||||
domain = valid_domain.dup
|
||||
domain.name = reserved_domain.name
|
||||
|
||||
assert domain.invalid?
|
||||
assert_includes domain.errors.full_messages, 'Required parameter missing; reserved>' \
|
||||
'pw element required for reserved domains'
|
||||
end
|
||||
|
||||
def test_invalid_without_registration_period
|
||||
domain = valid_domain
|
||||
domain.period = ''
|
||||
assert domain.invalid?
|
||||
end
|
||||
|
||||
def test_validates_registration_period_format
|
||||
domain = valid_domain
|
||||
|
||||
domain.period = 'invalid'
|
||||
assert domain.invalid?
|
||||
|
||||
domain.period = 1.1
|
||||
assert domain.invalid?
|
||||
|
||||
domain.period = 1
|
||||
assert domain.valid?
|
||||
end
|
||||
|
||||
def test_invalid_when_the_same_admin_contact_is_linked_twice
|
||||
domain = valid_domain
|
||||
contact = contacts(:john)
|
||||
|
||||
domain.admin_contacts << contact
|
||||
domain.admin_contacts << contact
|
||||
|
||||
assert domain.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_when_the_same_tech_contact_is_linked_twice
|
||||
domain = valid_domain
|
||||
contact = contacts(:john)
|
||||
|
||||
domain.tech_contacts << contact
|
||||
domain.tech_contacts << contact
|
||||
|
||||
assert domain.invalid?
|
||||
end
|
||||
|
||||
def test_validates_name_server_count_when_name_servers_are_required
|
||||
nameserver_attributes = nameservers(:shop_ns1).dup.attributes
|
||||
domain = valid_domain
|
||||
Setting.nameserver_required = true
|
||||
min_count = 1
|
||||
max_count = 2
|
||||
Setting.ns_min_count = min_count
|
||||
Setting.ns_max_count = max_count
|
||||
|
||||
domain.nameservers.clear
|
||||
min_count.times { domain.nameservers.build(nameserver_attributes) }
|
||||
assert domain.valid?, proc { domain.errors.full_messages }
|
||||
|
||||
domain.nameservers.clear
|
||||
max_count.times do |i|
|
||||
domain.nameservers.build(nameserver_attributes.merge(hostname: "ns#{i}.test"))
|
||||
end
|
||||
assert domain.valid?, proc { domain.errors.full_messages }
|
||||
|
||||
domain.nameservers.clear
|
||||
assert domain.invalid?
|
||||
|
||||
domain.nameservers.clear
|
||||
max_count.next.times do |i|
|
||||
domain.nameservers.build(nameserver_attributes.merge(hostname: "ns#{i}.test"))
|
||||
end
|
||||
assert domain.invalid?
|
||||
end
|
||||
|
||||
def test_valid_without_name_servers_when_they_are_optional
|
||||
domain = valid_domain
|
||||
domain.nameservers.clear
|
||||
Setting.nameserver_required = false
|
||||
Setting.ns_min_count = 1
|
||||
|
||||
assert domain.valid?
|
||||
end
|
||||
|
||||
def test_validates_admin_contact_count
|
||||
domain_contact_attributes = domain_contacts(:shop_jane).dup.attributes
|
||||
domain = valid_domain
|
||||
min_count = 1
|
||||
max_count = 2
|
||||
Setting.admin_contacts_min_count = min_count
|
||||
Setting.admin_contacts_max_count = max_count
|
||||
|
||||
domain.admin_domain_contacts.clear
|
||||
min_count.times { domain.admin_domain_contacts.build(domain_contact_attributes) }
|
||||
assert domain.valid?, proc { domain.errors.full_messages }
|
||||
|
||||
domain.admin_domain_contacts.clear
|
||||
max_count.times { domain.admin_domain_contacts.build(domain_contact_attributes) }
|
||||
assert domain.valid?, proc { domain.errors.full_messages }
|
||||
|
||||
domain.admin_domain_contacts.clear
|
||||
assert domain.invalid?
|
||||
|
||||
domain.admin_domain_contacts.clear
|
||||
max_count.next.times { domain.admin_domain_contacts.build(domain_contact_attributes) }
|
||||
assert domain.invalid?
|
||||
end
|
||||
|
||||
def test_validates_tech_contact_count
|
||||
domain_contact_attributes = domain_contacts(:shop_william).dup.attributes
|
||||
domain = valid_domain
|
||||
min_count = 1
|
||||
max_count = 2
|
||||
Setting.tech_contacts_min_count = min_count
|
||||
Setting.tech_contacts_max_count = max_count
|
||||
|
||||
domain.tech_domain_contacts.clear
|
||||
min_count.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
|
||||
assert domain.valid?, proc { domain.errors.full_messages }
|
||||
|
||||
domain.tech_domain_contacts.clear
|
||||
max_count.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
|
||||
assert domain.valid?, proc { domain.errors.full_messages }
|
||||
|
||||
domain.tech_domain_contacts.clear
|
||||
assert domain.invalid?
|
||||
|
||||
domain.tech_domain_contacts.clear
|
||||
max_count.next.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
|
||||
assert domain.invalid?
|
||||
end
|
||||
|
||||
def test_outzone_candidates_scope_returns_records_with_outzone_at_in_the_past
|
||||
travel_to Time.zone.parse('2010-07-05 08:00:00')
|
||||
domain1 = domains(:shop)
|
||||
domain1.update!(outzone_at: Time.zone.parse('2010-07-05 07:59:59'))
|
||||
domain2 = domains(:airport)
|
||||
domain2.update!(outzone_at: Time.zone.parse('2010-07-05 08:00:00'))
|
||||
domain3 = domains(:library)
|
||||
domain3.update!(outzone_at: Time.zone.parse('2010-07-05 08:00:01'))
|
||||
Domain.connection.disable_referential_integrity do
|
||||
Domain.delete_all("id NOT IN (#{[domain1.id, domain2.id, domain3.id].join(',')})")
|
||||
end
|
||||
|
||||
assert_equal [domain1.id], Domain.outzone_candidates.ids
|
||||
end
|
||||
|
||||
def test_expired_scope_returns_records_with_valid_to_in_the_past
|
||||
travel_to Time.zone.parse('2010-07-05 08:00:00')
|
||||
domain1 = domains(:shop)
|
||||
domain1.update!(valid_to: Time.zone.parse('2010-07-05 07:59:59'))
|
||||
domain2 = domains(:airport)
|
||||
domain2.update!(valid_to: Time.zone.parse('2010-07-05 08:00:00'))
|
||||
domain3 = domains(:library)
|
||||
domain3.update!(valid_to: Time.zone.parse('2010-07-05 08:00:01'))
|
||||
Domain.connection.disable_referential_integrity do
|
||||
Domain.delete_all("id NOT IN (#{[domain1.id, domain2.id, domain3.id].join(',')})")
|
||||
end
|
||||
|
||||
assert_equal [domain1.id, domain2.id], Domain.expired.ids
|
||||
end
|
||||
|
||||
def test_domain_name
|
||||
domain = Domain.new(name: 'shop.test')
|
||||
assert_equal 'shop.test', domain.domain_name.to_s
|
||||
|
@ -79,4 +334,87 @@ class DomainTest < ActiveSupport::TestCase
|
|||
|
||||
assert_equal %w[john@inbox.test william@inbox.test].sort, @domain.primary_contact_emails.sort
|
||||
end
|
||||
end
|
||||
|
||||
def test_normalizes_name
|
||||
unnormalized_name = ' Foo.test '
|
||||
domain = Domain.new(name: unnormalized_name)
|
||||
|
||||
assert_equal 'foo.test', domain.name
|
||||
assert_equal 'foo.test', domain.name_puny
|
||||
assert_equal unnormalized_name, domain.name_dirty
|
||||
end
|
||||
|
||||
def test_converts_name_to_punycode
|
||||
domain = Domain.new(name: 'münchen.test')
|
||||
assert_equal 'xn--mnchen-3ya.test', domain.name_puny
|
||||
end
|
||||
|
||||
def test_returns_new_registrant_id
|
||||
id = 1
|
||||
domain = Domain.new(pending_json: { new_registrant_id: id })
|
||||
|
||||
assert_equal id, domain.new_registrant_id
|
||||
end
|
||||
|
||||
def test_returns_new_registrant_email
|
||||
email = 'john@inbox.test'
|
||||
domain = Domain.new(pending_json: { new_registrant_email: email })
|
||||
|
||||
assert_equal email, domain.new_registrant_email
|
||||
end
|
||||
|
||||
def test_expiration
|
||||
now = Time.zone.parse('2010-07-05 08:00:00')
|
||||
travel_to now
|
||||
domain = Domain.new
|
||||
|
||||
domain.valid_to = now + 1.second
|
||||
assert domain.registered?
|
||||
assert_not domain.expired?
|
||||
|
||||
domain.valid_to = now
|
||||
assert domain.expired?
|
||||
assert_not domain.registered?
|
||||
|
||||
domain.valid_to = now - 1.second
|
||||
assert domain.expired?
|
||||
assert_not domain.registered?
|
||||
end
|
||||
|
||||
def test_activation
|
||||
domain = inactive_domain
|
||||
|
||||
assert domain.inactive?
|
||||
assert_not domain.active?
|
||||
|
||||
domain.activate
|
||||
|
||||
assert domain.active?
|
||||
assert_not domain.inactive?
|
||||
end
|
||||
|
||||
def test_deactivation
|
||||
domain = @domain
|
||||
|
||||
assert domain.active?
|
||||
assert_not domain.inactive?
|
||||
|
||||
domain.deactivate
|
||||
|
||||
assert domain.inactive?
|
||||
assert_not domain.active?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_domain
|
||||
domains(:shop)
|
||||
end
|
||||
|
||||
def inactive_domain
|
||||
Setting.nameserver_required = true
|
||||
domain = @domain
|
||||
domain.update!(statuses: [DomainStatus::INACTIVE])
|
||||
domain
|
||||
end
|
||||
end
|
||||
|
|
54
test/models/white_ip_test.rb
Normal file
54
test/models/white_ip_test.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
require 'test_helper'
|
||||
|
||||
class WhiteIpTest < ActiveSupport::TestCase
|
||||
def test_either_ipv4_or_ipv6_is_required
|
||||
white_ip = valid_white_ip
|
||||
|
||||
white_ip.ipv4 = ''
|
||||
white_ip.ipv6 = ''
|
||||
assert white_ip.invalid?
|
||||
assert_includes white_ip.errors.full_messages, 'IPv4 or IPv6 must be present'
|
||||
|
||||
white_ip.ipv4 = valid_ipv4
|
||||
white_ip.ipv6 = ''
|
||||
assert white_ip.valid?
|
||||
|
||||
white_ip.ipv4 = ''
|
||||
white_ip.ipv6 = valid_ipv6
|
||||
assert white_ip.valid?
|
||||
end
|
||||
|
||||
def test_validates_ipv4_format
|
||||
white_ip = valid_white_ip
|
||||
|
||||
white_ip.ipv4 = 'invalid'
|
||||
assert white_ip.invalid?
|
||||
|
||||
white_ip.ipv4 = valid_ipv4
|
||||
assert white_ip.valid?
|
||||
end
|
||||
|
||||
def test_validates_ipv6_format
|
||||
white_ip = valid_white_ip
|
||||
|
||||
white_ip.ipv6 = 'invalid'
|
||||
assert white_ip.invalid?
|
||||
|
||||
white_ip.ipv6 = valid_ipv6
|
||||
assert white_ip.valid?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_white_ip
|
||||
white_ips(:one)
|
||||
end
|
||||
|
||||
def valid_ipv4
|
||||
'192.0.2.1'
|
||||
end
|
||||
|
||||
def valid_ipv6
|
||||
'2001:db8::1'
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue