Skip to content
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

Omit errors from analytics when error_details available #11810

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions app/forms/webauthn_visit_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ def check_params(params)
return unless error

if @platform_authenticator
errors.add error, translate_platform_authenticator_error(error),
type: :"#{translate_platform_authenticator_error(error).split('.').last}"
errors.add error, translate_platform_authenticator_error(error), type: :invalid
else
errors.add error, translate_error(error), type: :"#{translate_error(error).split('.').last}"
errors.add error, translate_error(error), type: :invalid
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/form_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def success?

def to_h
hash = { success: success }
hash[:errors] = errors.presence if !serialize_error_details_only?
hash[:errors] = (!defined?(@error_details) && errors).presence if !serialize_error_details_only?
aduth marked this conversation as resolved.
Show resolved Hide resolved
hash[:error_details] = flatten_details(error_details) if error_details.present?
hash.merge!(extra)
hash
Expand Down
3 changes: 0 additions & 3 deletions spec/controllers/account_reset/cancel_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
expect(@analytics).to have_logged_event(
'Account Reset: cancel',
success: false,
errors: { token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)] },
error_details: {
token: { cancel_token_invalid: true },
},
Expand All @@ -48,7 +47,6 @@
expect(@analytics).to have_logged_event(
'Account Reset: cancel',
success: false,
errors: { token: [t('errors.account_reset.cancel_token_missing', app_name: APP_NAME)] },
error_details: { token: { blank: true } },
user_id: 'anonymous-uuid',
)
Expand Down Expand Up @@ -92,7 +90,6 @@
'Account Reset: cancel token validation',
user_id: 'anonymous-uuid',
success: false,
errors: { token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)] },
error_details: {
token: { cancel_token_invalid: true },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
let(:invalid_token_message) do
t('errors.account_reset.granted_token_invalid', app_name: APP_NAME)
end
let(:invalid_token_error) { { token: [invalid_token_message] } }

before { stub_analytics }
describe '#delete' do
Expand Down Expand Up @@ -45,7 +44,6 @@
'Account Reset: delete',
user_id: 'anonymous-uuid',
success: false,
errors: invalid_token_error,
error_details: { token: { granted_token_invalid: true } },
mfa_method_counts: {},
identity_verified: false,
Expand All @@ -63,7 +61,6 @@
'Account Reset: delete',
user_id: 'anonymous-uuid',
success: false,
errors: { token: [t('errors.account_reset.granted_token_missing', app_name: APP_NAME)] },
error_details: { token: { blank: true } },
mfa_method_counts: {},
identity_verified: false,
Expand Down Expand Up @@ -91,7 +88,6 @@
'Account Reset: delete',
user_id: user.uuid,
success: false,
errors: { token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)] },
error_details: { token: { granted_token_expired: true } },
mfa_method_counts: {},
identity_verified: false,
Expand Down Expand Up @@ -179,7 +175,6 @@
'Account Reset: granted token validation',
user_id: 'anonymous-uuid',
success: false,
errors: invalid_token_error,
error_details: { token: { granted_token_invalid: true } },
)
expect(response).to redirect_to(root_url)
Expand All @@ -199,7 +194,6 @@
'Account Reset: granted token validation',
user_id: user.uuid,
success: false,
errors: { token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)] },
error_details: { token: { granted_token_expired: true } },
)
expect(response).to redirect_to(root_url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@
expect(@analytics).to have_logged_event(
'Multi-Factor Authentication',
success: false,
errors: { code: ['pattern_mismatch'] },
error_details: { code: { pattern_mismatch: true } },
multi_factor_auth_method: TwoFactorAuthenticatable::AuthMethod::SMS,
enabled_mfa_methods_count: 1,
Expand Down
17 changes: 1 addition & 16 deletions spec/controllers/event_disavowal_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
build_analytics_hash(
user_id: event.user.uuid,
success: false,
errors: { event: [t('event_disavowals.errors.event_already_disavowed')] },
error_details: { event: { event_already_disavowed: true } },
),
)
Expand All @@ -64,7 +63,6 @@
build_analytics_hash(
user_id: event.user.uuid,
success: false,
errors: { event: [t('event_disavowals.errors.event_already_disavowed')] },
error_details: { event: { event_already_disavowed: true } },
),
)
Expand Down Expand Up @@ -102,13 +100,6 @@
build_analytics_hash(
user_id: event.user.uuid,
success: false,
errors: {
password: [
t(
'errors.attributes.password.too_short.other', count: Devise.password_length.first
),
],
},
error_details: { password: { too_short: true } },
),
)
Expand All @@ -127,7 +118,6 @@
build_analytics_hash(
user_id: event.user.uuid,
success: false,
errors: { password: ['Password must be at least 12 characters long'] },
error_details: { password: { too_short: true } },
),
)
Expand All @@ -151,7 +141,6 @@
build_analytics_hash(
user_id: event.user.uuid,
success: false,
errors: { event: [t('event_disavowals.errors.event_already_disavowed')] },
error_details: { event: { event_already_disavowed: true } },
),
)
Expand All @@ -173,9 +162,6 @@
'Event disavowal token invalid',
build_analytics_hash(
success: false,
errors: {
user: [t('event_disavowals.errors.no_account')],
},
error_details: {
user: { blank: true },
},
Expand All @@ -185,12 +171,11 @@
end
end

def build_analytics_hash(success: true, errors: nil, error_details: nil, user_id: nil)
def build_analytics_hash(success: true, error_details: nil, user_id: nil)
{
event_created_at: event.created_at,
disavowed_device_last_used_at: event.device&.last_used_at,
success:,
errors:,
error_details:,
event_id: event.id,
event_type: event.event_type,
Expand Down
7 changes: 2 additions & 5 deletions spec/controllers/idv/by_mail/enter_code_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
end

describe '#create' do
let(:otp_code_error_message) { { otp: [t('errors.messages.confirmation_code_incorrect')] } }
let(:success_properties) { { success: true } }

context 'user does not have a pending profile' do
Expand Down Expand Up @@ -382,7 +381,6 @@
expect(@analytics).to have_logged_event(
'IdV: enter verify by mail code submitted',
success: false,
errors: otp_code_error_message,
pending_in_person_enrollment: false,
fraud_check_failed: false,
letter_count: 1,
Expand Down Expand Up @@ -416,7 +414,6 @@
it 'redirects to the rate limited index page to show errors' do
analytics_args = {
success: false,
errors: otp_code_error_message,
pending_in_person_enrollment: false,
fraud_check_failed: false,
letter_count: 1,
Expand Down Expand Up @@ -450,11 +447,11 @@

failed_gpo_submission_events =
@analytics.events['IdV: enter verify by mail code submitted']
.reject { |event_attributes| event_attributes[:errors].blank? }
.reject { |event_attributes| event_attributes[:error_details].blank? }

successful_gpo_submission_events =
@analytics.events['IdV: enter verify by mail code submitted']
.select { |event_attributes| event_attributes[:errors].blank? }
.select { |event_attributes| event_attributes[:error_details].blank? }

expect(failed_gpo_submission_events.count).to eq(max_attempts - 1)
expect(successful_gpo_submission_events.count).to eq(1)
Expand Down
2 changes: 0 additions & 2 deletions spec/controllers/idv/how_to_verify_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
step: 'how_to_verify',
analytics_id: 'Doc Auth',
error_details: { selection: { blank: true } },
errors: { selection: ['Select a way to verify your identity.'] },
success: false,
}
end
Expand All @@ -191,7 +190,6 @@
analytics_id: 'Doc Auth',
selection:,
error_details: { selection: { inclusion: true } },
errors: { selection: ['Select a way to verify your identity.'] },
success: false,
}
end
Expand Down
23 changes: 0 additions & 23 deletions spec/controllers/idv/image_uploads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@
expect(@analytics).to have_logged_event(
'IdV: doc auth image upload form submitted',
success: false,
errors: {
front: [I18n.t('doc_auth.errors.not_a_file')],
},
error_details: {
front: { not_a_file: true },
},
Expand Down Expand Up @@ -219,9 +216,6 @@
expect(@analytics).to have_logged_event(
'IdV: doc auth image upload form submitted',
success: false,
errors: {
limit: [I18n.t('doc_auth.errors.rate_limited_heading')],
},
error_details: {
limit: { rate_limited: true },
},
Expand Down Expand Up @@ -520,9 +514,6 @@
expect(@analytics).to have_logged_event(
'IdV: doc auth image upload vendor pii validation',
success: false,
errors: {
name: [I18n.t('doc_auth.errors.alerts.full_name_check')],
},
error_details: {
name: { name: true },
},
Expand Down Expand Up @@ -598,9 +589,6 @@
expect(@analytics).to have_logged_event(
'IdV: doc auth image upload vendor pii validation',
success: false,
errors: {
state: [I18n.t('doc_auth.errors.general.no_liveness')],
},
error_details: {
state: { inclusion: true },
},
Expand Down Expand Up @@ -676,9 +664,6 @@
expect(@analytics).to have_logged_event(
'IdV: doc auth image upload vendor pii validation',
success: false,
errors: {
state_id_number: [I18n.t('doc_auth.errors.general.no_liveness')],
},
error_details: {
state_id_number: { blank: true },
},
Expand Down Expand Up @@ -750,9 +735,6 @@
expect(@analytics).to have_logged_event(
'IdV: doc auth image upload vendor pii validation',
success: false,
errors: {
dob: [I18n.t('doc_auth.errors.alerts.birth_date_checks')],
},
error_details: {
dob: { dob: true },
},
Expand Down Expand Up @@ -825,11 +807,6 @@
expect(@analytics).to have_logged_event(
'IdV: doc auth image upload vendor pii validation',
success: false,
errors: {
state_id_expiration: [
'Try taking new pictures.',
],
},
error_details: {
state_id_expiration: { state_id_expiration: true },
},
Expand Down
3 changes: 0 additions & 3 deletions spec/controllers/idv/in_person/ssn_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@
flow_path: 'standard',
step: 'ssn',
success: false,
errors: {
ssn: ['Enter a nine-digit Social Security number'],
},
error_details: { ssn: { invalid: true } },
}
end
Expand Down
4 changes: 0 additions & 4 deletions spec/controllers/idv/phone_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@
expect(@analytics).to have_logged_event(
'IdV: phone confirmation form',
success: false,
errors: {
phone: [improbable_phone_message],
otp_delivery_preference: [improbable_otp_message],
},
error_details: {
phone: { improbable_phone: true },
otp_delivery_preference: { inclusion: true },
Expand Down
3 changes: 0 additions & 3 deletions spec/controllers/idv/ssn_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@
flow_path: 'standard',
step: 'ssn',
success: false,
errors: {
ssn: [t('idv.errors.pattern_mismatch.ssn')],
},
error_details: { ssn: { invalid: true } },
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,6 @@
prompt: '',
allow_prompt_login: true,
unauthorized_scope: true,
errors: hash_including(:prompt),
error_details: hash_including(:prompt),
user_fully_authenticated: true,
acr_values: acr_values,
Expand Down Expand Up @@ -2071,7 +2070,6 @@
prompt:,
allow_prompt_login: true,
unauthorized_scope: false,
errors: hash_including(:acr_values),
error_details: hash_including(:acr_values),
user_fully_authenticated: true,
acr_values: '',
Expand Down Expand Up @@ -2237,7 +2235,6 @@
prompt: '',
allow_prompt_login: true,
unauthorized_scope: true,
errors: hash_including(:prompt),
error_details: hash_including(:prompt),
user_fully_authenticated: true,
acr_values: '',
Expand Down Expand Up @@ -2276,7 +2273,6 @@
success: false,
prompt: 'select_account',
unauthorized_scope: true,
errors: hash_including(:client_id),
error_details: hash_including(:client_id),
user_fully_authenticated: true,
acr_values: 'http://idmanagement.gov/ns/assurance/ial/1',
Expand Down Expand Up @@ -2311,7 +2307,6 @@
success: false,
prompt: 'select_account',
unauthorized_scope: true,
errors: hash_including(:client_id),
error_details: hash_including(:client_id),
user_fully_authenticated: true,
acr_values: '',
Expand Down
Loading