Skip to content
Closed
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: 3 additions & 1 deletion app/services/form_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def merge_arrays(_key, first, second)
end

def flatten_details(details)
details.transform_values { |errors| errors.pluck(:error) }
details.transform_values do |errors|
errors.map { |error| error[:type] || error[:error] }.index_with(true)
end
end

attr_reader :success
Expand Down
3 changes: 2 additions & 1 deletion app/services/password_reset_token_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def submit
attr_accessor :user

def valid_token
errors.add(:user, 'token_expired', type: :user) unless user.reset_password_period_valid?
return if user.reset_password_period_valid?
errors.add(:user, 'token_expired', type: :token_expired)
end
end
6 changes: 3 additions & 3 deletions spec/controllers/account_reset/cancel_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
success: false,
errors: { token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)] },
error_details: {
token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)],
token: { cancel_token_invalid: true },
},
user_id: 'anonymous-uuid',
}
Expand All @@ -46,7 +46,7 @@
analytics_hash = {
success: false,
errors: { token: [t('errors.account_reset.cancel_token_missing', app_name: APP_NAME)] },
error_details: { token: [:blank] },
error_details: { token: { blank: true } },
user_id: 'anonymous-uuid',
}

Expand Down Expand Up @@ -91,7 +91,7 @@
success: false,
errors: { token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)] },
error_details: {
token: [t('errors.account_reset.cancel_token_invalid', app_name: APP_NAME)],
token: { cancel_token_invalid: true },
},
}
expect(@analytics).to receive(:track_event).
Expand Down
14 changes: 5 additions & 9 deletions spec/controllers/account_reset/delete_account_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
user_id: 'anonymous-uuid',
success: false,
errors: invalid_token_error,
error_details: invalid_token_error,
error_details: { token: { granted_token_invalid: true } },
mfa_method_counts: {},
pii_like_keypaths: [[:mfa_method_counts, :phone]],
account_age_in_days: 0,
Expand Down Expand Up @@ -92,7 +92,7 @@
user_id: 'anonymous-uuid',
success: false,
errors: { token: [t('errors.account_reset.granted_token_missing', app_name: APP_NAME)] },
error_details: { token: [:blank] },
error_details: { token: { blank: true } },
mfa_method_counts: {},
pii_like_keypaths: [[:mfa_method_counts, :phone]],
account_age_in_days: 0,
Expand All @@ -118,9 +118,7 @@
user_id: user.uuid,
success: false,
errors: { token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)] },
error_details: {
token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)],
},
error_details: { token: { granted_token_invalid: true } },
mfa_method_counts: {},
pii_like_keypaths: [[:mfa_method_counts, :phone]],
account_age_in_days: 2,
Expand All @@ -146,7 +144,7 @@
user_id: 'anonymous-uuid',
success: false,
errors: invalid_token_error,
error_details: invalid_token_error,
error_details: { token: { granted_token_invalid: true } },
}
expect(@analytics).to receive(:track_event).
with('Account Reset: granted token validation', properties)
Expand All @@ -167,9 +165,7 @@
user_id: user.uuid,
success: false,
errors: { token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)] },
error_details: {
token: [t('errors.account_reset.granted_token_expired', app_name: APP_NAME)],
},
error_details: { token: { granted_token_invalid: true } },
}
expect(@analytics).to receive(:track_event).
with('Account Reset: granted token validation', properties)
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/idv/doc_auth_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
errors: include(
pii: [I18n.t('doc_auth.errors.general.no_liveness')],
),
error_details: { pii: [I18n.t('doc_auth.errors.general.no_liveness')] },
error_details: { pii: { generic_error: true } },
attention_with_barcode: false,
success: false,
remaining_attempts: IdentityConfig.store.doc_auth_max_attempts,
Expand All @@ -431,7 +431,7 @@
errors: include(
pii: [I18n.t('doc_auth.errors.general.no_liveness')],
),
error_details: { pii: [I18n.t('doc_auth.errors.general.no_liveness')] },
error_details: { pii: { generic_error: true } },
attention_with_barcode: false,
success: false,
remaining_attempts: IdentityConfig.store.doc_auth_max_attempts,
Expand Down
7 changes: 3 additions & 4 deletions spec/controllers/idv/gpo_verify_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@

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

subject(:action) do
Expand Down Expand Up @@ -175,11 +174,11 @@
errors: otp_code_error_message,
pending_in_person_enrollment: false,
enqueued_at: nil,
error_details: otp_code_incorrect,
error_details: { otp: { confirmation_code_incorrect: true } },
pii_like_keypaths: [[:errors, :otp], [:error_details, :otp]],
)
expect(@irs_attempts_api_tracker).to receive(:idv_gpo_verification_submitted).
with(success: false, failure_reason: otp_code_incorrect)
with(success: false, failure_reason: { otp: { confirmation_code_incorrect: true } })

action

Expand All @@ -205,7 +204,7 @@
errors: otp_code_error_message,
pending_in_person_enrollment: false,
enqueued_at: nil,
error_details: otp_code_incorrect,
error_details: { otp: { confirmation_code_incorrect: true } },
pii_like_keypaths: [[:errors, :otp], [:error_details, :otp]],
).exactly(max_attempts).times

Expand Down
12 changes: 6 additions & 6 deletions spec/controllers/idv/image_uploads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
front: ['Please fill in this field.'],
},
error_details: {
front: [:blank],
front: { blank: true },
},
user_id: user.uuid,
attempts: 1,
Expand Down Expand Up @@ -120,7 +120,7 @@
front: [I18n.t('doc_auth.errors.not_a_file')],
},
error_details: {
front: [I18n.t('doc_auth.errors.not_a_file')],
front: { not_a_file: true },
},
user_id: user.uuid,
attempts: 1,
Expand Down Expand Up @@ -220,7 +220,7 @@
limit: [I18n.t('errors.doc_auth.throttled_heading')],
},
error_details: {
limit: [I18n.t('errors.doc_auth.throttled_heading')],
limit: { throttled: true },
},
user_id: user.uuid,
attempts: IdentityConfig.store.doc_auth_max_attempts,
Expand Down Expand Up @@ -446,7 +446,7 @@
pii: [I18n.t('doc_auth.errors.alerts.full_name_check')],
},
error_details: {
pii: [I18n.t('doc_auth.errors.alerts.full_name_check')],
pii: { name_error: true },
},
attention_with_barcode: false,
user_id: user.uuid,
Expand Down Expand Up @@ -524,7 +524,7 @@
pii: [I18n.t('doc_auth.errors.general.no_liveness')],
},
error_details: {
pii: [I18n.t('doc_auth.errors.general.no_liveness')],
pii: { generic_error: true },
},
attention_with_barcode: false,
user_id: user.uuid,
Expand Down Expand Up @@ -602,7 +602,7 @@
pii: [I18n.t('doc_auth.errors.alerts.birth_date_checks')],
},
error_details: {
pii: [I18n.t('doc_auth.errors.alerts.birth_date_checks')],
pii: { dob_error: true },
},
attention_with_barcode: false,
user_id: user.uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
result = {
success: false,
errors: { otp_delivery_preference: ['is not included in the list'] },
error_details: { otp_delivery_preference: [:inclusion] },
error_details: { otp_delivery_preference: { inclusion: true } },
otp_delivery_preference: '🎷',
}

Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/idv/phone_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
context 'when form is invalid' do
let(:improbable_phone_error) do
{
phone: [:improbable_phone],
otp_delivery_preference: [:inclusion],
phone: { improbable_phone: true },
otp_delivery_preference: { inclusion: true },
}
end
let(:improbable_phone_message) { t('errors.messages.improbable_phone') }
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/saml_idp_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def name_id_version(format_urn)
analytics_hash = {
success: false,
errors: { authn_context: [t('errors.messages.unauthorized_authn_context')] },
error_details: { authn_context: [:unauthorized_authn_context] },
error_details: { authn_context: { unauthorized_authn_context: true } },
nameid_format: Saml::Idp::Constants::NAME_ID_FORMAT_PERSISTENT,
authn_context: ['http://idmanagement.gov/ns/assurance/loa/5'],
authn_context_comparison: 'exact',
Expand Down Expand Up @@ -917,7 +917,7 @@ def name_id_version(format_urn)
analytics_hash = {
success: false,
errors: { service_provider: [t('errors.messages.unauthorized_service_provider')] },
error_details: { service_provider: [:unauthorized_service_provider] },
error_details: { service_provider: { unauthorized_service_provider: true } },
nameid_format: Saml::Idp::Constants::NAME_ID_FORMAT_PERSISTENT,
authn_context: request_authn_contexts,
authn_context_comparison: 'exact',
Expand Down Expand Up @@ -959,8 +959,8 @@ def name_id_version(format_urn)
authn_context: [t('errors.messages.unauthorized_authn_context')],
},
error_details: {
authn_context: [:unauthorized_authn_context],
service_provider: [:unauthorized_service_provider],
authn_context: { unauthorized_authn_context: true },
service_provider: { unauthorized_service_provider: true },
},
nameid_format: Saml::Idp::Constants::NAME_ID_FORMAT_PERSISTENT,
authn_context: ['http://idmanagement.gov/ns/assurance/loa/5'],
Expand Down Expand Up @@ -1350,7 +1350,7 @@ def name_id_version(format_urn)
analytics_hash = {
success: false,
errors: { nameid_format: [t('errors.messages.unauthorized_nameid_format')] },
error_details: { nameid_format: [:unauthorized_nameid_format] },
error_details: { nameid_format: { unauthorized_nameid_format: true } },
nameid_format: Saml::Idp::Constants::NAME_ID_FORMAT_EMAIL,
authn_context: request_authn_contexts,
authn_context_comparison: 'exact',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe SignUp::EmailConfirmationsController do
describe '#create' do
let(:token_not_found_error) { { confirmation_token: [:not_found] } }
let(:token_expired_error) { { confirmation_token: [:expired] } }
let(:token_not_found_error) { { confirmation_token: { not_found: true } } }
let(:token_expired_error) { { confirmation_token: { expired: true } } }
let(:analytics_token_error_hash) do
{
success: false,
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/sign_up/passwords_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
end

it 'tracks an invalid password event' do
password_short_error = { password: [:too_short] }
password_short_error = { password: { too_short: true } }
token = 'new token'
user = create(:user, :unconfirmed, confirmation_token: token)

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/sign_up/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
success: false,
throttled: false,
errors: { email: [t('valid_email.validations.email.invalid')] },
error_details: { email: [:invalid] },
error_details: { email: { invalid: true } },
email_already_exists: false,
user_id: 'anonymous-uuid',
domain_name: 'invalid',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

properties = {
success: false,
error_details: { code: [:incorrect_length, :incorrect] },
error_details: { code: { incorrect_length: true, incorrect: true } },
confirmation_for_add_phone: false,
context: 'authentication',
multi_factor_auth_method: 'sms',
Expand Down Expand Up @@ -153,7 +153,7 @@

properties = {
success: false,
error_details: { code: [:incorrect_length, :incorrect] },
error_details: { code: { incorrect_length: true, incorrect: true } },
confirmation_for_add_phone: false,
context: 'authentication',
multi_factor_auth_method: 'sms',
Expand Down Expand Up @@ -469,7 +469,7 @@
properties = {
success: false,
errors: nil,
error_details: { code: [:incorrect_length, :incorrect] },
error_details: { code: { incorrect_length: true, incorrect: true } },
confirmation_for_add_phone: true,
context: 'confirmation',
multi_factor_auth_method: 'sms',
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/users/edit_phone_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
attributes = {
success: false,
errors: hash_including(:delivery_preference),
error_details: { delivery_preference: [:inclusion] },
error_details: { delivery_preference: { inclusion: true } },
delivery_preference: 'noise',
make_default_number: true,
phone_configuration_id: phone_configuration.id,
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/users/passwords_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

context 'form returns failure' do
it 'renders edit' do
password_short_error = { password: [:too_short] }
password_short_error = { password: { too_short: true } }
stub_sign_in

stub_analytics
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/users/phone_setup_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
],
},
error_details: {
phone: [
:improbable_phone,
t('two_factor_authentication.otp_delivery_preference.voice_unsupported', location: ''),
],
phone: {
improbable_phone: true,
voice_unsupported: true,
},
},
otp_delivery_preference: 'sms',
area_code: nil,
Expand Down
Loading