mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 11:16:00 +02:00
Merge pull request #1075 from internetee/support-id-card-v2018
Support id card v2018
This commit is contained in:
commit
743c6fecab
20 changed files with 267 additions and 97 deletions
18
test/models/api_user_test.rb
Normal file
18
test/models/api_user_test.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ApiUserTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@user = users(:api_bestnames)
|
||||
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
|
||||
end
|
|
@ -35,22 +35,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_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
|
||||
|
|
|
@ -30,6 +30,34 @@ 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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue