mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 10:45:58 +02:00
Merge remote-tracking branch 'origin/master' into 1580-registrar-api-contacts-endpoint
This commit is contained in:
commit
a80d037677
37 changed files with 376 additions and 411 deletions
|
@ -0,0 +1,43 @@
|
|||
require 'test_helper'
|
||||
require 'auth_token/auth_token_creator'
|
||||
|
||||
class RegistrantApiCompaniesTest < ApplicationIntegrationTest
|
||||
def setup
|
||||
super
|
||||
|
||||
@contact = contacts(:john)
|
||||
@user = users(:registrant)
|
||||
@auth_headers = { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
end
|
||||
|
||||
def test_accepts_limit_and_offset_parameters
|
||||
contacts(:william).update!(ident: '1234', ident_type: 'priv', ident_country_code: 'US')
|
||||
|
||||
get '/api/v1/registrant/companies', params: { 'limit' => 1, 'offset' => 0 },
|
||||
headers: @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(200, response.status)
|
||||
assert_equal(1, response_json.values.flatten.count)
|
||||
|
||||
get '/api/v1/registrant/companies', headers: @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(@user.companies.size, response_json.count)
|
||||
end
|
||||
|
||||
def test_format
|
||||
contacts(:william).update!(ident: '1234', ident_type: 'priv', ident_country_code: 'US')
|
||||
get '/api/v1/registrant/companies', headers: @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(1, response_json.count)
|
||||
assert response_json.is_a?(Hash)
|
||||
assert_equal(:companies, response_json.keys.first)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def auth_token
|
||||
token_creator = AuthTokenCreator.create_with_defaults(@user)
|
||||
hash = token_creator.token_in_hash
|
||||
"Bearer #{hash[:access_token]}"
|
||||
end
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrantAreaIdCardSignInTest < ApplicationIntegrationTest
|
||||
setup do
|
||||
allow_business_registry_component_reach_server
|
||||
end
|
||||
|
||||
def test_succeeds
|
||||
post registrant_id_card_sign_in_path, headers: { 'SSL_CLIENT_S_DN_CN' => 'DOE,JOHN,1234',
|
||||
'SSL_CLIENT_I_DN_C' => 'US' }
|
||||
follow_redirect!
|
||||
|
||||
assert_response :ok
|
||||
assert_equal registrant_root_path, path
|
||||
assert_not_nil controller.current_registrant_user
|
||||
end
|
||||
|
||||
def test_fails_when_certificate_is_absent
|
||||
post registrant_id_card_sign_in_path, headers: { 'SSL_CLIENT_S_DN_CN' => '' }
|
||||
|
||||
assert_response :ok
|
||||
assert_equal registrant_id_card_sign_in_path, path
|
||||
assert_nil controller.current_registrant_user
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def allow_business_registry_component_reach_server
|
||||
WebMock.allow_net_connect!
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class IdCardAuthenticatableTest < ActiveSupport::TestCase
|
||||
def test_valid_when_id_card_data_is_present_in_env
|
||||
strategy = Devise::Strategies::IdCardAuthenticatable.new({ 'SSL_CLIENT_S_DN_CN' => 'some' })
|
||||
assert strategy.valid?
|
||||
end
|
||||
|
||||
def test_not_valid_when_id_card_data_is_absent_in_env
|
||||
strategy = Devise::Strategies::IdCardAuthenticatable.new({})
|
||||
assert_not strategy.valid?
|
||||
end
|
||||
end
|
|
@ -73,7 +73,7 @@ class DomainDeleteMailerTest < ActionMailer::TestCase
|
|||
|
||||
assert_emails 1
|
||||
assert_equal ['legal@registry.test'], email.from
|
||||
assert_equal @domain.force_delete_contact_emails, email.to
|
||||
assert @domain.force_delete_contact_emails.sort == email.to.sort
|
||||
assert_equal 'Domeen shop.test on kustutusmenetluses' \
|
||||
' / Domain shop.test is in deletion process' \
|
||||
' / Домен shop.test в процессе удаления', email.subject
|
||||
|
|
|
@ -52,17 +52,6 @@ class ApiUserTest < ActiveSupport::TestCase
|
|||
assert ApiUser.new.active?
|
||||
end
|
||||
|
||||
def test_finds_user_by_id_card
|
||||
id_card = IdCard.new
|
||||
id_card.personal_code = 'one'
|
||||
|
||||
@user.update!(identity_code: 'one')
|
||||
assert_equal @user, ApiUser.find_by_id_card(id_card)
|
||||
|
||||
@user.update!(identity_code: 'another')
|
||||
assert_nil ApiUser.find_by_id_card(id_card)
|
||||
end
|
||||
|
||||
def test_verifies_pki_status
|
||||
certificate = certificates(:api)
|
||||
|
||||
|
|
|
@ -242,4 +242,14 @@ class NewDomainForceDeleteTest < ActiveSupport::TestCase
|
|||
|
||||
assert_not_includes(@domain.statuses, asserted_status)
|
||||
end
|
||||
|
||||
def test_force_delete_does_not_affect_pending_update_check
|
||||
@domain.schedule_force_delete(type: :soft)
|
||||
@domain.reload
|
||||
|
||||
@domain.statuses << DomainStatus::PENDING_UPDATE
|
||||
|
||||
assert @domain.force_delete_scheduled?
|
||||
assert @domain.pending_update?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,4 +52,26 @@ class DomainCronTest < ActiveSupport::TestCase
|
|||
|
||||
assert_emails 0
|
||||
end
|
||||
|
||||
def test_cleans_expired_pendings_when_force_delete_active
|
||||
Setting.expire_pending_confirmation = 0
|
||||
|
||||
# Set force delete
|
||||
@domain.schedule_force_delete(type: :soft)
|
||||
@domain.reload
|
||||
|
||||
@domain.statuses << DomainStatus::PENDING_UPDATE
|
||||
# Set domain registrant change that's expired
|
||||
@domain.update!(registrant_verification_asked_at: Time.zone.now,
|
||||
registrant_verification_token: 'test',
|
||||
statuses: @domain.statuses)
|
||||
|
||||
assert @domain.pending_update?
|
||||
@domain.reload
|
||||
|
||||
DomainCron.clean_expired_pendings
|
||||
@domain.reload
|
||||
|
||||
assert_not @domain.pending_update?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,13 +26,4 @@ class RegistrantUserCreationTest < ActiveSupport::TestCase
|
|||
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
|
||||
end
|
||||
|
|
|
@ -30,34 +30,6 @@ class RegistrantUserTest < ActiveSupport::TestCase
|
|||
assert_equal Country.new('US'), user.country
|
||||
end
|
||||
|
||||
def test_finding_by_id_card_creates_new_user_upon_first_sign_in
|
||||
assert_not_equal 'US-5555', @user.registrant_ident
|
||||
id_card = IdCard.new
|
||||
id_card.first_name = 'John'
|
||||
id_card.last_name = 'Doe'
|
||||
id_card.personal_code = '5555'
|
||||
id_card.country_code = 'US'
|
||||
|
||||
assert_difference 'RegistrantUser.count' do
|
||||
RegistrantUser.find_by_id_card(id_card)
|
||||
end
|
||||
|
||||
user = RegistrantUser.last
|
||||
assert_equal 'US-5555', user.registrant_ident
|
||||
assert_equal 'John Doe', user.username
|
||||
end
|
||||
|
||||
def test_finding_by_id_card_reuses_existing_user_upon_subsequent_id_card_sign_ins
|
||||
@user.update!(registrant_ident: 'US-5555')
|
||||
id_card = IdCard.new
|
||||
id_card.personal_code = '5555'
|
||||
id_card.country_code = 'US'
|
||||
|
||||
assert_no_difference 'RegistrantUser.count' do
|
||||
RegistrantUser.find_by_id_card(id_card)
|
||||
end
|
||||
end
|
||||
|
||||
def test_queries_company_register_for_associated_companies
|
||||
assert_equal 'US-1234', @user.registrant_ident
|
||||
|
||||
|
@ -92,4 +64,4 @@ class RegistrantUserTest < ActiveSupport::TestCase
|
|||
assert_equal %w(shop airport), @user.administered_domains
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
51
test/system/registrant_area/tara/tara_users_test.rb
Normal file
51
test/system/registrant_area/tara/tara_users_test.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
require 'application_system_test_case'
|
||||
|
||||
class RegistrantAreaTaraUsersTest < ApplicationSystemTestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
OmniAuth.config.test_mode = true
|
||||
@registrant = users(:registrant)
|
||||
|
||||
@existing_user_hash = {
|
||||
'provider' => 'rant_tara',
|
||||
'uid' => "US1234",
|
||||
'info': { 'first_name': 'Registrant', 'last_name': 'User' }
|
||||
}
|
||||
|
||||
@new_user_hash = {
|
||||
'provider' => 'rant_tara',
|
||||
'uid' => 'EE51007050604',
|
||||
'info': { 'first_name': 'New Registrant', 'last_name': 'User'}
|
||||
}
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
OmniAuth.config.test_mode = false
|
||||
OmniAuth.config.mock_auth['rant_tara'] = nil
|
||||
end
|
||||
|
||||
def test_existing_user_gets_signed_in
|
||||
OmniAuth.config.mock_auth[:rant_tara] = OmniAuth::AuthHash.new(@existing_user_hash)
|
||||
|
||||
visit new_registrant_user_session_path
|
||||
click_link('Sign in')
|
||||
|
||||
assert_text('Signed in successfully')
|
||||
end
|
||||
|
||||
def test_new_user_is_created_and_signed_in
|
||||
OmniAuth.config.mock_auth[:rant_tara] = OmniAuth::AuthHash.new(@new_user_hash)
|
||||
|
||||
assert_difference 'RegistrantUser.count' do
|
||||
visit new_registrant_user_session_path
|
||||
click_link('Sign in')
|
||||
|
||||
assert_equal 'New Registrant User', RegistrantUser.last.username
|
||||
assert_equal 'EE-51007050604', RegistrantUser.last.registrant_ident
|
||||
assert_text('Signed in successfully')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -27,10 +27,10 @@ Rake::Task.clear
|
|||
Rails.application.load_tasks
|
||||
|
||||
class CompanyRegisterClientStub
|
||||
Company = Struct.new(:registration_number)
|
||||
Company = Struct.new(:registration_number, :company_name)
|
||||
|
||||
def representation_rights(citizen_personal_code:, citizen_country_code:)
|
||||
[Company.new('1234567')]
|
||||
[Company.new('1234567', 'ACME Ltd')]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue