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
4 changes: 4 additions & 0 deletions app/controllers/account_reset/delete_account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def delete
result = AccountReset::DeleteAccount.new(granted_token).call
analytics.account_reset_delete(**result.to_h.except(:email))

irs_attempts_api_tracker.account_reset_account_deleted(
success: result.success?,
failure_reason: result.errors,
)
if result.success?
handle_successful_deletion(result)
else
Expand Down
13 changes: 12 additions & 1 deletion app/services/irs_attempts_api/tracker_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def account_reset_cancel_request(success:)
)
end

# @param [Boolean] success True if the email and password matched
# @param [Boolean] success True if Account Reset Deletion submitted successful
# account Reset Deletion Requested
def account_reset_request_submitted(success:)
track_event(
Expand All @@ -18,6 +18,17 @@ def account_reset_request_submitted(success:)
)
end

# param [Boolean] success True if Account Successfully Deleted
# param [Hash<Key, Array<String>>] failure_reason displays why account deletion failed
# A User confirms and deletes their Login.gov account after 24 hour period
def account_reset_account_deleted(success:, failure_reason:)
track_event(
:account_reset_account_deleted,
success: success,
failure_reason: failure_reason,
)
end

# @param [String] email The submitted email address
# @param [Boolean] success True if the email and password matched
# A user has submitted an email address and password for authentication
Expand Down
45 changes: 41 additions & 4 deletions spec/controllers/account_reset/delete_account_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
describe '#delete' do
it 'logs a good token to the analytics' do
user = create(:user, :signed_up, :with_backup_code)
create(:phone_configuration, user: user, phone: '+1 703-555-1214')
create(:phone_configuration, user: user, phone: Faker::PhoneNumber.cell_phone)
create_list(:webauthn_configuration, 2, user: user)
create_account_reset_request_for(user)
grant_request(user)

session[:granted_token] = AccountResetRequest.all[0].granted_token
session[:granted_token] = AccountResetRequest.first.granted_token
stub_analytics
properties = {
user_id: user.uuid,
Expand All @@ -29,6 +29,26 @@
expect(response).to redirect_to account_reset_confirm_delete_account_url
end

it 'logs a good token to the attempts api' do
user = create(:user, :signed_up, :with_backup_code)
create(:phone_configuration, user: user, phone: Faker::PhoneNumber.cell_phone)
create_list(:webauthn_configuration, 2, user: user)
create_account_reset_request_for(user)
grant_request(user)

session[:granted_token] = AccountResetRequest.first.granted_token
stub_attempts_tracker

expect(@irs_attempts_api_tracker).to receive(:account_reset_account_deleted).with(
success: true,
failure_reason: {},
)

delete :delete

expect(response).to redirect_to account_reset_confirm_delete_account_url
end

it 'redirects to root if the token does not match one in the DB' do
session[:granted_token] = 'foo'
stub_analytics
Expand All @@ -53,6 +73,23 @@
)
end

it 'logs an error in irs attempts tracker' do
session[:granted_token] = 'foo'
stub_attempts_tracker
properties = {
success: false,
failure_reason: { token: [t(
'errors.account_reset.granted_token_invalid',
app_name: APP_NAME,
)] },
}
expect(@irs_attempts_api_tracker).to receive(:account_reset_account_deleted).with(
properties,
)

delete :delete
end

it 'displays a flash and redirects to root if the token is missing' do
stub_analytics
properties = {
Expand Down Expand Up @@ -95,7 +132,7 @@
expect(@analytics).to receive(:track_event).with('Account Reset: delete', properties)

travel_to(Time.zone.now + 2.days) do
session[:granted_token] = AccountResetRequest.all[0].granted_token
session[:granted_token] = AccountResetRequest.first.granted_token
delete :delete
end

Expand Down Expand Up @@ -146,7 +183,7 @@
with('Account Reset: granted token validation', properties)

travel_to(Time.zone.now + 2.days) do
get :show, params: { token: AccountResetRequest.all[0].granted_token }
get :show, params: { token: AccountResetRequest.first.granted_token }
end

expect(response).to redirect_to(root_url)
Expand Down