Merge remote-tracking branch 'origin/master' into log-bounced-emails

This commit is contained in:
Karl Erik Õunapuu 2020-10-27 11:34:19 +02:00
commit fc34105c40
No known key found for this signature in database
GPG key ID: C9DD647298A34764
70 changed files with 791 additions and 4967 deletions

View file

@ -78,6 +78,18 @@ identical_to_william:
auth_info: 5ab865
uuid: c0a191d5-3793-4f0b-8f85-491612d0293e
registrar_ltd:
name: Registrar Ltd
email: registrar@inbox.test
phone: '+555.555'
ident: 1234567890
ident_type: org
registrar: goodnames
ident_country_code: US
code: registrarltd-001
auth_info: e2c441
uuid: 28b65455-6f1a-49fd-961c-0758886dbd76
invalid:
name: any
code: invalid

View file

@ -0,0 +1,44 @@
$VERBOSE=nil
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

View file

@ -12,7 +12,7 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
def test_root_accepts_limit_and_offset_parameters
contacts(:william).update!(ident: '1234', ident_type: 'priv', ident_country_code: 'US')
assert_equal 4, @user.contacts.size
assert_equal 4, @user.contacts(representable: false).size
get '/api/v1/registrant/contacts', params: { 'limit' => 1, 'offset' => 0 },
headers: @auth_headers
@ -22,7 +22,7 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
get '/api/v1/registrant/contacts', headers: @auth_headers
response_json = JSON.parse(response.body, symbolize_names: true)
assert_equal(@user.contacts.size, response_json.count)
assert_equal(@user.contacts(representable: false).size, response_json.count)
end
def test_get_contact_details_by_uuid

View file

@ -35,7 +35,7 @@ class RegistrantApiV1ContactListTest < ActionDispatch::IntegrationTest
get api_v1_registrant_contacts_path, as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token }
response_json = JSON.parse(response.body, symbolize_names: true)
assert_equal @user.contacts.count, response_json.size
assert_equal @user.contacts(representable: false).count, response_json.size
assert_includes response_json.map{ |hash| hash[:code] }, @contact.code
end

View file

@ -167,4 +167,36 @@ class EppDomainRenewBaseTest < EppTestCase
end
assert_epp_response :parameter_value_policy_error
end
def test_fails_if_domain_has_renewal_prohibited_statuses
travel_to Time.zone.parse('2010-07-05')
domain = domains(:shop)
domain.statuses << DomainStatus::SERVER_RENEW_PROHIBITED
domain.save
original_valid_to = domain.valid_to
default_renewal_period = 1.year
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<renew>
<domain:renew xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>#{domain.name}</domain:name>
<domain:curExpDate>#{domain.expire_time.to_date}</domain:curExpDate>
<domain:period unit="y">1</domain:period>
</domain:renew>
</renew>
</command>
</epp>
XML
post epp_renew_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
domain.reload
assert_epp_response :object_status_prohibits_operation
assert_equal original_valid_to, domain.valid_to
end
end

View file

@ -31,7 +31,7 @@ class EppLoginCredentialsTest < EppTestCase
end
def test_already_logged_in
assert true # Handled by mod_epp
assert true # Handled by EPP proxy
end
def test_wrong_credentials

View file

@ -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

View file

@ -1,65 +0,0 @@
require 'test_helper'
class RegistrarAreaIdCardSignInTest < ApplicationIntegrationTest
setup do
@user = users(:api_bestnames)
@original_registrar_area_ip_whitelist = Setting.registrar_ip_whitelist_enabled
end
teardown do
Setting.registrar_ip_whitelist_enabled = @original_registrar_area_ip_whitelist
end
def test_signs_in_a_user_when_id_card_owner_is_found
assert_equal '1234', @user.identity_code
post registrar_id_card_sign_in_path, headers: { 'SSL_CLIENT_S_DN_CN' => 'DOE,JOHN,1234' }
follow_redirect!
assert_response :ok
assert_equal registrar_root_path, path
assert_not_nil controller.current_registrar_user
end
def test_does_not_sign_in_a_user_when_id_card_owner_is_not_found
post registrar_id_card_sign_in_path,
headers: { 'SSL_CLIENT_S_DN_CN' => 'DOE,JOHN,unacceptable-personal-code' }
assert_nil controller.current_registrar_user
assert_equal registrar_id_card_sign_in_path, path
assert_includes response.body, 'Failed to Login'
end
def test_does_not_sign_in_a_user_when_id_card_owner_is_found_but_ip_is_not_allowed
allow_access_to_sign_in_page
assert_equal '127.0.0.1', white_ips(:one).ipv4
assert_equal '1234', @user.identity_code
Setting.registrar_ip_whitelist_enabled = true
post registrar_id_card_sign_in_path, headers: { 'SSL_CLIENT_S_DN_CN' => 'DOE,JOHN,1234',
'REMOTE_ADDR' => '127.0.0.2' }
assert_equal registrar_id_card_sign_in_path, path
assert_equal 'Access denied from IP 127.0.0.2', response.body
get registrar_root_path
assert_redirected_to new_registrar_user_session_path
end
def test_does_not_sign_in_a_user_when_certificate_is_absent
post registrar_id_card_sign_in_path, headers: { 'SSL_CLIENT_S_DN_CN' => '' }
assert_nil controller.current_registrar_user
assert_equal registrar_id_card_sign_in_path, path
end
private
def allow_access_to_sign_in_page
another_registrar_white_ip = white_ips(:one).dup
another_registrar_white_ip.ipv4 = '127.0.0.2'
another_registrar_white_ip.registrar = registrars(:goodnames)
another_registrar_white_ip.save!
end
end

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -39,6 +39,21 @@ class DomainCronTest < ActiveSupport::TestCase
assert_emails 1
end
def does_not_deliver_forced_email_if_template_empty
Setting.redemption_grace_period = 30
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
@domain.reload
@domain.update(template_name: nil)
travel_to Time.zone.parse('2010-08-06')
DomainCron.start_client_hold
assert_emails 0
end
def test_does_not_sets_hold_if_already_set
Setting.redemption_grace_period = 30
@ -52,4 +67,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

View file

@ -431,6 +431,19 @@ class DomainTest < ActiveSupport::TestCase
assert_equal created_at, domain.registered_at
end
def test_not_renewable_if_renew_prohibited
assert @domain.renewable?
@domain.statuses << DomainStatus::SERVER_RENEW_PROHIBITED
assert_not @domain.renewable?
@domain.statuses.delete(DomainStatus::SERVER_RENEW_PROHIBITED)
assert @domain.renewable?
@domain.statuses << DomainStatus::CLIENT_RENEW_PROHIBITED
assert_not @domain.renewable?
end
private
def valid_domain

View file

@ -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

View file

@ -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

View file

@ -28,6 +28,20 @@ class RegistrantAreaDomainListTest < ApplicationSystemTestCase
assert_no_text 'metro.test'
end
def test_only_shows_direct_relation_and_or_company_domains
# case https://github.com/internetee/registry/issues/1690
tech_contact = contacts(:registrar_ltd)
# All domains share the same tech contact object
Domain.all.each do |domain|
DomainContact.create(domain: domain, contact: tech_contact, type: TechDomainContact)
end
visit registrant_domains_url
assert_no_text 'Company register is unavailable.'
assert_no_text 'metro.test'
end
def test_notification_when_company_register_is_unavailable
CompanyRegister::Client.stub(:new, CompanyRegisterClientStub.new) do
visit registrant_domains_url
@ -54,4 +68,4 @@ class RegistrantAreaDomainListTest < ApplicationSystemTestCase
assert_text 'shop.test'
end
end
end

View 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

View file

@ -1,35 +0,0 @@
require 'application_system_test_case'
class RegistrarAreaMobileIDSignInTest < JavaScriptApplicationSystemTestCase
def setup
super
WebMock.allow_net_connect!
@user = users(:api_bestnames)
@user.identity_code = '1234'
@user.save
end
def test_valid_phone_number
mock_client = Minitest::Mock.new
mock_client.expect(:authenticate,
OpenStruct.new(user_id_code: '1234', challenge_id: '1234'),
[{ phone: "+3721234",
message_to_display: "Authenticating",
service_name: "Testimine" }])
mock_client.expect(:session_code, 1234)
Digidoc::Client.stub(:new, mock_client) do
visit new_registrar_user_session_path
click_on 'login-with-mobile-id-btn'
fill_in 'user[phone]', with: '1234'
click_button 'Login'
flash_message = page.find('div.bg-success')
assert_equal('Confirmation sms was sent to your phone. Verification code is 1234.',
flash_message.text)
end
end
end

View file

@ -0,0 +1,45 @@
require 'application_system_test_case'
class TaraUsersTest < ApplicationSystemTestCase
def setup
super
OmniAuth.config.test_mode = true
@user = users(:api_bestnames)
@existing_user_hash = {
'provider' => 'tara',
'uid' => "EE" + @user.identity_code
}
@new_user_hash = {
'provider' => 'tara',
'uid' => 'EE51007050604'
}
end
def teardown
super
OmniAuth.config.test_mode = false
OmniAuth.config.mock_auth['tara'] = nil
end
def test_existing_user_gets_signed_in
OmniAuth.config.mock_auth[:tara] = OmniAuth::AuthHash.new(@existing_user_hash)
visit new_registrar_user_session_path
click_link('Sign in')
assert_text('Signed in successfully')
end
def test_nonexisting_user_gets_error_message
OmniAuth.config.mock_auth[:tara] = OmniAuth::AuthHash.new(@new_user_hash)
visit new_registrar_user_session_path
click_link('Sign in')
assert_text('No such user')
end
end

View file

@ -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