Refactor ID card sign-in

- Extract to Devise custom strategy
- Use `SSL_CLIENT_S_DN_CN` env variable instead of `SSL_CLIENT_S_DN` to
get ID card data
- Remove `database_authenticatable` strategy from `RegistrantUser`

Closes #1047
This commit is contained in:
Artur Beljajev 2019-01-30 19:08:29 +02:00
parent 27976c3fbd
commit a08f063640
20 changed files with 266 additions and 89 deletions

View file

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