Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/controllers/concerns/saml_idp_logout_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def track_logout_event
oidc: false,
saml_request_valid: sp_initiated ? valid_saml_request? : true,
)
irs_attempts_api_tracker.logout_initiated(
success: true,
)
end

def track_remote_logout_event
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/openid_connect/logout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def index
result = @logout_form.submit

analytics.logout_initiated(**result.to_h.except(:redirect_uri))
irs_attempts_api_tracker.logout_initiated(
success: result.success?,
)

if result.success? && (redirect_uri = result.extra[:redirect_uri])
sign_out
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/sign_out_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ class SignOutController < ApplicationController

def destroy
analytics.logout_initiated(method: 'cancel link')
irs_attempts_api_tracker.logout_initiated(
success: true,
)
url_after_cancellation = decorated_session.cancel_link_url
sign_out
flash[:success] = t('devise.sessions.signed_out')
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def create
def destroy
analytics.logout_initiated(sp_initiated: false, oidc: false)
irs_attempts_api_tracker.logout_initiated(
user_uuid: current_user.uuid,
unique_session_id: current_user.unique_session_id,
success: true,
)
super
Expand Down
4 changes: 1 addition & 3 deletions app/services/irs_attempts_api/tracker_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ def email_and_password_auth(email:, success:)
# @param [String] unique_session_id The unique session id
# @param [Boolean] success True if the email and password matched
# A user has initiated a logout event
def logout_initiated(user_uuid:, unique_session_id:, success:)
def logout_initiated(success:)
track_event(
:logout_initiated,
user_uuid: user_uuid,
unique_session_id: unique_session_id,
success: success,
)
end
Expand Down
21 changes: 18 additions & 3 deletions spec/controllers/openid_connect/logout_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
expect(response).to redirect_to(/^#{post_logout_redirect_uri}/)
end

it 'tracks analytics' do
it 'tracks events' do
stub_analytics
expect(@analytics).to receive(:track_event).
with(
Expand All @@ -65,6 +65,11 @@
),
)

stub_attempts_tracker
expect(@irs_attempts_api_tracker).to receive(:logout_initiated).
with(
success: true,
)
action
end
end
Expand All @@ -84,7 +89,7 @@
action
end

it 'tracks analytics' do
it 'tracks events' do
stub_analytics

errors = {
Expand All @@ -102,14 +107,19 @@
method: nil,
saml_request_valid: nil,
)
stub_attempts_tracker
expect(@irs_attempts_api_tracker).to receive(:logout_initiated).
with(
success: false,
)

action
end
end

context 'with a bad id_token_hint' do
let(:id_token_hint) { { id_token_hint: 'abc123' } }
it 'tracks analytics' do
it 'tracks events' do
stub_analytics
errors_keys = [:id_token_hint, :redirect_uri]

Expand All @@ -125,6 +135,11 @@
method: nil,
saml_request_valid: nil,
)
stub_attempts_tracker
expect(@irs_attempts_api_tracker).to receive(:logout_initiated).
with(
success: false,
)

action
end
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/saml_idp_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,40 @@
describe '/api/saml/logout' do
it 'tracks the event when idp initiated' do
stub_analytics
stub_attempts_tracker

result = { sp_initiated: false, oidc: false, saml_request_valid: true }
expect(@analytics).to receive(:track_event).with('Logout Initiated', hash_including(result))
expect(@irs_attempts_api_tracker).to receive(:logout_initiated).with(
success: true,
)

delete :logout
end

it 'tracks the event when sp initiated' do
allow(controller).to receive(:saml_request).and_return(FakeSamlLogoutRequest.new)
stub_analytics
stub_attempts_tracker

result = { sp_initiated: true, oidc: false, saml_request_valid: true }
expect(@analytics).to receive(:track_event).with('Logout Initiated', hash_including(result))
expect(@irs_attempts_api_tracker).to receive(:logout_initiated).with(
success: true,
)

delete :logout, params: { SAMLRequest: 'foo' }
end

it 'tracks the event when the saml request is invalid' do
stub_analytics
stub_attempts_tracker

result = { sp_initiated: true, oidc: false, saml_request_valid: false }
expect(@analytics).to receive(:track_event).with('Logout Initiated', hash_including(result))
expect(@irs_attempts_api_tracker).to receive(:logout_initiated).with(
success: true,
)

delete :logout, params: { SAMLRequest: 'foo' }
end
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/sign_out_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
it 'tracks the event' do
stub_sign_in_before_2fa
stub_analytics
stub_attempts_tracker
allow(controller.decorated_session).to receive(:cancel_link_url).and_return('foo')

expect(@analytics).
to receive(:track_event).with('Logout Initiated', hash_including(method: 'cancel link'))

expect(@irs_attempts_api_tracker).to receive(:logout_initiated).with(
success: true,
)

get :destroy
end
end
Expand Down
13 changes: 6 additions & 7 deletions spec/controllers/users/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
describe 'GET /logout' do
it 'tracks a logout event' do
stub_analytics
stub_attempts_tracker
expect(@analytics).to receive(:track_event).with(
'Logout Initiated',
hash_including(
Expand All @@ -128,9 +129,7 @@

sign_in_as_user

expect_any_instance_of(IrsAttemptsApi::Tracker).to receive(:logout_initiated).with(
user_uuid: controller.current_user.uuid,
unique_session_id: controller.current_user.unique_session_id,
expect(@irs_attempts_api_tracker).to receive(:logout_initiated).with(
success: true,
)

Expand All @@ -142,6 +141,7 @@
describe 'DELETE /logout' do
it 'tracks a logout event' do
stub_analytics
stub_attempts_tracker
expect(@analytics).to receive(:track_event).with(
'Logout Initiated',
hash_including(
Expand All @@ -152,9 +152,7 @@

sign_in_as_user

expect_any_instance_of(IrsAttemptsApi::Tracker).to receive(:logout_initiated).with(
user_uuid: controller.current_user.uuid,
unique_session_id: controller.current_user.unique_session_id,
expect(@irs_attempts_api_tracker).to receive(:logout_initiated).with(
success: true,
)

Expand Down Expand Up @@ -205,6 +203,7 @@
subject.session['user_return_to'] = 'http://example.com'

stub_analytics
stub_attempts_tracker
analytics_hash = {
success: true,
user_id: user.uuid,
Expand All @@ -217,7 +216,7 @@
expect(@analytics).to receive(:track_event).
with('Email and Password Authentication', analytics_hash)

expect_any_instance_of(IrsAttemptsApi::Tracker).to receive(:email_and_password_auth).
expect(@irs_attempts_api_tracker).to receive(:email_and_password_auth).
with(email: user.email, success: true)

post :create, params: { user: { email: user.email, password: user.password } }
Expand Down