mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
Merge branch 'master' into refactor-messages
# Conflicts: # db/structure.sql
This commit is contained in:
commit
056c57530c
32 changed files with 730 additions and 148 deletions
52
test/models/domain/domain_version_test.rb
Normal file
52
test/models/domain/domain_version_test.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainVersionTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@domain = domains(:shop)
|
||||
@contacts = @domain.contacts
|
||||
@user = users(:registrant)
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
end
|
||||
|
||||
def test_assigns_creator_to_paper_trail_whodunnit
|
||||
duplicate_domain = prepare_duplicate_domain
|
||||
|
||||
PaperTrail.whodunnit = @user.id_role_username
|
||||
assert_difference 'duplicate_domain.versions.count', 1 do
|
||||
duplicate_domain.save!
|
||||
end
|
||||
|
||||
assert_equal(duplicate_domain.creator, @user)
|
||||
assert_equal(duplicate_domain.updator, @user)
|
||||
assert_equal(duplicate_domain.creator_str, @user.id_role_username)
|
||||
assert_equal(duplicate_domain.updator_str, @user.id_role_username)
|
||||
end
|
||||
|
||||
def test_assigns_updator_to_paper_trail_whodunnit
|
||||
PaperTrail.whodunnit = @user.id_role_username
|
||||
|
||||
assert_difference '@domain.versions.count', 1 do
|
||||
@domain.apply_registry_lock
|
||||
end
|
||||
|
||||
assert_equal(@domain.updator, @user)
|
||||
assert_equal(@domain.updator_str, @user.id_role_username)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prepare_duplicate_domain
|
||||
duplicate_domain = @domain.dup
|
||||
duplicate_domain.tech_contacts << @contacts
|
||||
duplicate_domain.admin_contacts << @contacts
|
||||
duplicate_domain.name = 'duplicate.test'
|
||||
duplicate_domain.uuid = nil
|
||||
|
||||
duplicate_domain
|
||||
end
|
||||
end
|
72
test/models/domain/registry_lockable_test.rb
Normal file
72
test/models/domain/registry_lockable_test.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainRegistryLockableTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@domain = domains(:airport)
|
||||
end
|
||||
|
||||
def test_registry_lock_on_lockable_domain
|
||||
refute(@domain.locked_by_registrant?)
|
||||
@domain.apply_registry_lock
|
||||
|
||||
assert_equal(
|
||||
[DomainStatus::SERVER_UPDATE_PROHIBITED,
|
||||
DomainStatus::SERVER_DELETE_PROHIBITED,
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED],
|
||||
@domain.statuses
|
||||
)
|
||||
|
||||
assert(@domain.locked_by_registrant?)
|
||||
assert(@domain.locked_by_registrant_at)
|
||||
end
|
||||
|
||||
def test_registry_lock_cannot_be_applied_twice
|
||||
@domain.apply_registry_lock
|
||||
refute(@domain.apply_registry_lock)
|
||||
assert(@domain.locked_by_registrant?)
|
||||
assert(@domain.locked_by_registrant_at)
|
||||
end
|
||||
|
||||
def test_registry_lock_cannot_be_applied_on_pending_statuses
|
||||
@domain.statuses << DomainStatus::PENDING_RENEW
|
||||
refute(@domain.apply_registry_lock)
|
||||
refute(@domain.locked_by_registrant?)
|
||||
refute(@domain.locked_by_registrant_at)
|
||||
end
|
||||
|
||||
def test_remove_registry_lock_on_locked_domain
|
||||
@domain.apply_registry_lock
|
||||
|
||||
assert_equal(
|
||||
[DomainStatus::SERVER_UPDATE_PROHIBITED,
|
||||
DomainStatus::SERVER_DELETE_PROHIBITED,
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED],
|
||||
@domain.statuses
|
||||
)
|
||||
|
||||
@domain.remove_registry_lock
|
||||
|
||||
assert_equal(["ok"], @domain.statuses)
|
||||
refute(@domain.locked_by_registrant?)
|
||||
refute(@domain.locked_by_registrant_at)
|
||||
end
|
||||
|
||||
def test_remove_registry_lock_on_non_locked_domain
|
||||
refute(@domain.locked_by_registrant?)
|
||||
refute(@domain.remove_registry_lock)
|
||||
|
||||
assert_equal([], @domain.statuses)
|
||||
refute(@domain.locked_by_registrant?)
|
||||
refute(@domain.locked_by_registrant_at)
|
||||
end
|
||||
|
||||
def test_registry_lock_cannot_be_removed_if_statuses_were_set_by_admin
|
||||
@domain.statuses << DomainStatus::SERVER_UPDATE_PROHIBITED
|
||||
@domain.statuses << DomainStatus::SERVER_DELETE_PROHIBITED
|
||||
@domain.statuses << DomainStatus::SERVER_TRANSFER_PROHIBITED
|
||||
|
||||
refute(@domain.remove_registry_lock)
|
||||
end
|
||||
end
|
56
test/models/registrant_user/registrant_user_creation_test.rb
Normal file
56
test/models/registrant_user/registrant_user_creation_test.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrantUserCreationTest < ActiveSupport::TestCase
|
||||
def test_find_or_create_by_api_data_creates_a_user
|
||||
user_data = {
|
||||
ident: '37710100070',
|
||||
first_name: 'JOHN',
|
||||
last_name: 'SMITH'
|
||||
}
|
||||
|
||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
end
|
||||
|
||||
def test_find_or_create_by_api_data_creates_a_user_after_upcasing_input
|
||||
user_data = {
|
||||
ident: '37710100070',
|
||||
first_name: 'John',
|
||||
last_name: 'Smith'
|
||||
}
|
||||
|
||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
end
|
||||
|
||||
def test_find_or_create_by_mid_data_creates_a_user
|
||||
user_data = OpenStruct.new(user_country: 'EE', user_id_code: '37710100070',
|
||||
user_givenname: 'JOHN', user_surname: 'SMITH')
|
||||
|
||||
RegistrantUser.find_or_create_by_mid_data(user_data)
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
end
|
||||
|
||||
def test_find_or_create_by_idc_with_legacy_header_creates_a_user
|
||||
header = '/C=EE/O=ESTEID/OU=authentication/CN=SMITH,JOHN,37710100070/SN=SMITH/GN=JOHN/serialNumber=37710100070'
|
||||
|
||||
RegistrantUser.find_or_create_by_idc_data(header, RegistrantUser::ACCEPTED_ISSUER)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
end
|
||||
|
||||
def test_find_or_create_by_idc_with_rfc2253_header_creates_a_user
|
||||
header = 'serialNumber=37710100070,GN=JOHN,SN=SMITH,CN=SMITH\\,JOHN\\,37710100070,OU=authentication,O=ESTEID,C=EE'
|
||||
|
||||
RegistrantUser.find_or_create_by_idc_data(header, RegistrantUser::ACCEPTED_ISSUER)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
end
|
||||
end
|
|
@ -1,62 +1,38 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrantUserTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@user = users(:registrant)
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
end
|
||||
|
||||
def test_find_or_create_by_api_data_creates_a_user
|
||||
user_data = {
|
||||
ident: '37710100070',
|
||||
first_name: 'JOHN',
|
||||
last_name: 'SMITH'
|
||||
}
|
||||
def test_domains_returns_an_list_of_distinct_domains_associated_with_a_specific_id_code
|
||||
domain_names = @user.domains.pluck(:name)
|
||||
assert_equal(4, domain_names.length)
|
||||
|
||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
# User is a registrant, but not a contact for the domain. Should be included in the list.
|
||||
assert(domain_names.include?('shop.test'))
|
||||
end
|
||||
|
||||
def test_find_or_create_by_api_data_creates_a_user_after_upcasing_input
|
||||
user_data = {
|
||||
ident: '37710100070',
|
||||
first_name: 'John',
|
||||
last_name: 'Smith'
|
||||
}
|
||||
def test_administered_domains_returns_a_list_of_domains
|
||||
domain_names = @user.administered_domains.pluck(:name)
|
||||
assert_equal(3, domain_names.length)
|
||||
|
||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
# User is a tech contact for the domain.
|
||||
refute(domain_names.include?('library.test'))
|
||||
end
|
||||
|
||||
def test_find_or_create_by_mid_data_creates_a_user
|
||||
user_data = OpenStruct.new(user_country: 'EE', user_id_code: '37710100070',
|
||||
user_givenname: 'JOHN', user_surname: 'SMITH')
|
||||
|
||||
RegistrantUser.find_or_create_by_mid_data(user_data)
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
def test_contacts_returns_an_list_of_contacts_associated_with_a_specific_id_code
|
||||
assert_equal(1, @user.contacts.count)
|
||||
end
|
||||
|
||||
def test_find_or_create_by_idc_with_legacy_header_creates_a_user
|
||||
header = '/C=EE/O=ESTEID/OU=authentication/CN=SMITH,JOHN,37710100070/SN=SMITH/GN=JOHN/serialNumber=37710100070'
|
||||
|
||||
RegistrantUser.find_or_create_by_idc_data(header, RegistrantUser::ACCEPTED_ISSUER)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
end
|
||||
|
||||
def test_find_or_create_by_idc_with_rfc2253_header_creates_a_user
|
||||
header = 'serialNumber=37710100070,GN=JOHN,SN=SMITH,CN=SMITH\\,JOHN\\,37710100070,OU=authentication,O=ESTEID,C=EE'
|
||||
|
||||
RegistrantUser.find_or_create_by_idc_data(header, RegistrantUser::ACCEPTED_ISSUER)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
def test_ident_and_country_code_helper_methods
|
||||
assert_equal('1234', @user.ident)
|
||||
assert_equal('US', @user.country_code)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue