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

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