Skip to content

Commit

Permalink
LG-768 Create event for personal key as 2FA
Browse files Browse the repository at this point in the history
**Why**: To make it easier to query if any particular users have used
their personal key to sign in, and to add an event to the user's account
page for visibility.
  • Loading branch information
monfresh committed Oct 30, 2018
1 parent f0e24b3 commit f974a89
Show file tree
Hide file tree
Showing 8 changed files with 1,089 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def presenter_for_two_factor_authentication_method

def handle_result(result)
if result.success?
create_user_event(:personal_key_used)
generate_new_personal_key
handle_valid_otp
else
Expand Down
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Event < ApplicationRecord
piv_cac_enabled: 10,
piv_cac_disabled: 11,
new_personal_key: 12,
personal_key_used: 13,
}

validates :event_type, presence: true
Expand Down
1 change: 1 addition & 0 deletions config/locales/event_types/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ en:
email_changed: Email address changed
new_personal_key: Personal key changed
password_changed: Password changed
personal_key_used: Personal key used to sign in
phone_changed: Phone number changed
phone_confirmed: Phone confirmed
piv_cac_disabled: PIV/CAC card unassociated
Expand Down
1 change: 1 addition & 0 deletions config/locales/event_types/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ es:
email_changed: Email cambiado
new_personal_key: Clave personal cambiado
password_changed: Contraseña cambiada
personal_key_used: Clave personal utilizada para iniciar sesión
phone_changed: Número de teléfono cambiado
phone_confirmed: Teléfono confirmado
piv_cac_disabled: Tarjeta PIV/CAC no asociada
Expand Down
1 change: 1 addition & 0 deletions config/locales/event_types/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fr:
email_changed: Adresse courriel modifiée
new_personal_key: Clé personnelle modifié
password_changed: Mot de passe modifié
personal_key_used: Clé personnelle utilisée pour la connexion
phone_changed: Numéro de téléphone modifié
phone_confirmed: Numéro de téléphone confirmé
piv_cac_disabled: Carte PIV/CAC non associée
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,17 @@

describe '#create' do
context 'when the user enters a valid personal key' do
before do
stub_sign_in_before_2fa(build(:user, personal_key: 'foo'))
it 'tracks the valid authentication event' do
sign_in_before_2fa

form = instance_double(PersonalKeyForm)
response = FormResponse.new(
success: true, errors: {}, extra: { multi_factor_auth_method: 'personal key' }
)
allow(PersonalKeyForm).to receive(:new).
with(subject.current_user, 'foo').and_return(form)
allow(form).to receive(:submit).and_return(response)
end

it 'redirects to the manage_personal_key_url so the user can see their new personal key' do
post :create, params: payload

expect(response).to redirect_to manage_personal_key_url
end

it 'calls handle_valid_otp_for_authentication_context' do
expect(subject).to receive(:handle_valid_otp_for_authentication_context).and_call_original

post :create, params: payload
end

it 'tracks the valid authentication event' do
stub_analytics
analytics_hash = { success: true, errors: {}, multi_factor_auth_method: 'personal key' }

Expand Down
1 change: 1 addition & 0 deletions spec/features/users/sign_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@
click_acknowledge_personal_key

expect(page).to have_current_path(account_path)
expect(page).to have_content t('event_types.personal_key_used')
end
end

Expand Down
Loading

0 comments on commit f974a89

Please sign in to comment.