-
Notifications
You must be signed in to change notification settings - Fork 166
LG-5725 IALMax requests ial2 info if user is verified #8350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f2e096b
LG-5725 IALMax requests ial2 info if user is verified
Sgtpluck f07ba6e
changelog: Bugfixes, IALMax, OIDC IALMax now completes ial2 consent
Sgtpluck f860f98
Add user to piv cac ial_context
Sgtpluck 43cc375
Review feedback
Sgtpluck 12372d7
Add tests for piv_cac_login_controller'
Sgtpluck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
220 changes: 220 additions & 0 deletions
220
spec/controllers/users/piv_cac_login_controller_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe Users::PivCacLoginController do | ||
| describe 'GET new' do | ||
| before do | ||
| stub_analytics | ||
| allow(@analytics).to receive(:track_event) | ||
| end | ||
|
|
||
| context 'without a token' do | ||
| before { get :new } | ||
|
|
||
| it 'tracks the piv_cac setup' do | ||
| expect(@analytics).to have_received(:track_event).with( | ||
| 'User Registration: piv cac setup visited', | ||
| ) | ||
| end | ||
|
|
||
| it 'redirects to root url' do | ||
| expect(response).to render_template(:new) | ||
| end | ||
| end | ||
|
|
||
| context 'with a token' do | ||
| let(:token) { 'TEST:abcdefg' } | ||
|
|
||
| context 'an invalid token' do | ||
| before { get :new, params: { token: token } } | ||
| it 'tracks the login attempt' do | ||
| expect(@analytics).to have_received(:track_event).with( | ||
| 'PIV/CAC Login', | ||
| { | ||
| errors: {}, | ||
| key_id: nil, | ||
| success: false, | ||
| }, | ||
| ) | ||
| end | ||
|
|
||
| it 'redirects to the error url' do | ||
| expect(response).to redirect_to(login_piv_cac_error_url(error: 'token.bad')) | ||
| end | ||
| end | ||
|
|
||
| context 'with a valid token' do | ||
| let(:service_provider) { create(:service_provider) } | ||
| let(:sp_session) { { ial: 1, issuer: service_provider.issuer } } | ||
| let(:nonce) { SecureRandom.base64(20) } | ||
| let(:data) do | ||
| { | ||
| nonce: nonce, | ||
| uuid: '1234', | ||
| subject: 'subject', | ||
| issuer: 'issuer', | ||
| }.with_indifferent_access | ||
| end | ||
|
|
||
| before do | ||
| subject.piv_session[:piv_cac_nonce] = nonce | ||
| subject.session[:sp] = sp_session | ||
|
|
||
| allow(PivCacService).to receive(:decode_token).with(token) { data } | ||
| get :new, params: { token: token } | ||
| end | ||
|
|
||
| context 'without a valid user' do | ||
| before do | ||
| # valid_token? is being called twice, once to determine if it's a valid submission | ||
| # and once to set the session variable in process_invalid_submission | ||
| # good opportunity for a refactor | ||
| expect(PivCacService).to have_received(:decode_token).with(token) { data }.twice | ||
| end | ||
|
|
||
| it 'tracks the login attempt' do | ||
| expect(@analytics).to have_received(:track_event).with( | ||
| 'PIV/CAC Login', | ||
| { | ||
| errors: { | ||
| type: 'user.not_found', | ||
| }, | ||
| key_id: nil, | ||
| success: false, | ||
| }, | ||
| ) | ||
| end | ||
|
|
||
| it 'sets the session variable' do | ||
| expect(subject.session[:needs_to_setup_piv_cac_after_sign_in]).to be true | ||
| end | ||
|
|
||
| it 'redirects to the error url' do | ||
| expect(response).to redirect_to(login_piv_cac_error_url(error: 'user.not_found')) | ||
| end | ||
| end | ||
|
|
||
| context 'with a valid user' do | ||
| let(:user) { build(:user) } | ||
| let(:piv_cac_config) { create(:piv_cac_configuration, user: user) } | ||
| let(:data) do | ||
| { | ||
| nonce: nonce, | ||
| uuid: piv_cac_config.x509_dn_uuid, | ||
| subject: 'subject', | ||
| issuer: 'issuer', | ||
| }.with_indifferent_access | ||
| end | ||
|
|
||
| before do | ||
| expect(PivCacService).to have_received(:decode_token).with(token) { data } | ||
| sign_in user | ||
| end | ||
|
|
||
| it 'tracks the login attempt' do | ||
| expect(@analytics).to have_received(:track_event).with( | ||
| 'PIV/CAC Login', | ||
| { | ||
| errors: {}, | ||
| key_id: nil, | ||
| success: true, | ||
| }, | ||
| ) | ||
| end | ||
|
|
||
| it 'sets the session correctly' do | ||
| expect(controller.user_session[TwoFactorAuthenticatable::NEED_AUTHENTICATION]). | ||
| to eq false | ||
|
|
||
| expect(controller.user_session[:authn_at]).to_not be nil | ||
| expect(controller.user_session[:authn_at].class).to eq ActiveSupport::TimeWithZone | ||
| end | ||
|
|
||
| it 'tracks the user_marked_authed event' do | ||
| expect(@analytics).to have_received(:track_event).with( | ||
| 'User marked authenticated', | ||
| { authentication_type: :piv_cac }, | ||
| ) | ||
| end | ||
|
|
||
| it 'saves the piv_cac session information' do | ||
| session_info = { | ||
| subject: data[:subject], | ||
| issuer: data[:issuer], | ||
| presented: true, | ||
| } | ||
| expect(controller.user_session[:decrypted_x509]).to eq session_info.to_json | ||
| end | ||
|
|
||
| describe 'it handles the otp_context' do | ||
| it 'sets the otp user_session' do | ||
| expect(controller.user_session[:auth_method]). | ||
| to eq TwoFactorAuthenticatable::AuthMethod::PIV_CAC | ||
|
|
||
| expect(controller.user_session[:unconfirmed_phone]).to be nil | ||
| expect(controller.user_session[:context]).to eq 'authentication' | ||
| end | ||
|
|
||
| it 'tracks the user_marked_authed event' do | ||
| expect(@analytics).to have_received(:track_event).with( | ||
| 'User marked authenticated', | ||
| { authentication_type: :valid_2fa }, | ||
| ) | ||
| end | ||
|
|
||
| context 'ial1 user' do | ||
| it 'redirects to the after_sign_in_path_for' do | ||
| expect(response).to redirect_to(account_url) | ||
| end | ||
|
|
||
| context 'ial_max service level' do | ||
| let(:sp_session) do | ||
| { ial: Idp::Constants::IAL_MAX, issuer: service_provider.issuer } | ||
| end | ||
|
|
||
| it 'redirects to the after_sign_in_path_for' do | ||
| expect(response).to redirect_to(account_url) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'ial2 user' do | ||
| let(:user) { create(:user, profiles: [create(:profile, :verified, :active)]) } | ||
|
|
||
| context 'ial1 service level' do | ||
| it 'redirects to the after_sign_in_path_for' do | ||
| expect(response).to redirect_to(account_url) | ||
| end | ||
| end | ||
|
|
||
| context 'ial2 service_level' do | ||
| let(:sp_session) { { ial: Idp::Constants::IAL2, issuer: service_provider.issuer } } | ||
|
|
||
| it 'redirects to the capture_password_url' do | ||
| expect(response).to redirect_to(capture_password_url) | ||
| end | ||
| end | ||
|
|
||
| context 'ial_max service_level' do | ||
| let(:sp_session) do | ||
| { ial: Idp::Constants::IAL_MAX, issuer: service_provider.issuer } | ||
| end | ||
|
|
||
| it 'redirects to the capture_password_url' do | ||
| expect(response).to redirect_to(capture_password_url) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'GET error' do | ||
| before { get :error, params: { error: 'token.bad' } } | ||
|
|
||
| it 'sends the error to the error presenter' do | ||
| expect(assigns(:presenter).error).to eq 'token.bad' | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.