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
8 changes: 7 additions & 1 deletion app/controllers/idv/enter_password_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ def confirm_current_password
def init_profile
idv_session.create_profile_from_applicant_with_password(
password,
resolved_authn_context_result.enhanced_ipp?,
is_enhanced_ipp: resolved_authn_context_result.enhanced_ipp?,
proofing_components: ProofingComponents.new(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): Extract ProofingComponents creation to a private method.

(failed to submit with the review, adding now)

user: current_user,
idv_session:,
session:,
user_session:,
).to_h,
)
if idv_session.verify_by_mail?
current_user.send_email_to_all_addresses(:verify_by_mail_letter_requested)
Expand Down
9 changes: 3 additions & 6 deletions app/services/idv/profile_maker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Idv
class ProfileMaker
attr_reader :pii_attributes
attr_reader :pii_attributes, :proofing_components

def initialize(
applicant:,
Expand All @@ -21,13 +21,14 @@ def save_profile(
gpo_verification_needed:,
in_person_verification_needed:,
selfie_check_performed:,
proofing_components:,
deactivation_reason: nil
)
profile = Profile.new(user: user, active: false, deactivation_reason: deactivation_reason)
profile.initiating_service_provider = initiating_service_provider
profile.deactivate_for_in_person_verification if in_person_verification_needed
profile.encrypt_pii(pii_attributes, user_password)
profile.proofing_components = current_proofing_components
profile.proofing_components = proofing_components
profile.fraud_pending_reason = fraud_pending_reason

profile.idv_level = set_idv_level(
Expand Down Expand Up @@ -61,10 +62,6 @@ def set_idv_level(in_person_verification_needed:, selfie_check_performed:)
end
end

def current_proofing_components
user.proofing_component&.as_json || {}
end

attr_accessor(
:user,
:user_password,
Expand Down
5 changes: 4 additions & 1 deletion app/services/idv/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def respond_to_missing?(method_sym, include_private)
VALID_SESSION_ATTRIBUTES.include?(attr_name_sym) || super
end

def create_profile_from_applicant_with_password(user_password, is_enhanced_ipp)
def create_profile_from_applicant_with_password(
user_password, is_enhanced_ipp:, proofing_components:
)
if user_has_unscheduled_in_person_enrollment?
UspsInPersonProofing::EnrollmentHelper.schedule_in_person_enrollment(
user: current_user,
Expand All @@ -82,6 +84,7 @@ def create_profile_from_applicant_with_password(user_password, is_enhanced_ipp)
gpo_verification_needed: !phone_confirmed? || verify_by_mail?,
in_person_verification_needed: current_user.has_in_person_enrollment?,
selfie_check_performed: session[:selfie_check_performed],
proofing_components:,
)

profile.activate unless profile.reason_not_to_activate
Expand Down
6 changes: 5 additions & 1 deletion spec/controllers/idv/personal_key_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def assert_personal_key_generated_for_profiles(*profile_pii_pairs)
idv_session.applicant = applicant

if mint_profile_from_idv_session
idv_session.create_profile_from_applicant_with_password(password, is_enhanced_ipp)
idv_session.create_profile_from_applicant_with_password(
password,
is_enhanced_ipp:,
proofing_components: {},
)
end
end

Expand Down
8 changes: 6 additions & 2 deletions spec/policies/idv/flow_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@
it 'returns personal_key' do
stub_up_to(:request_letter, idv_session: idv_session)
idv_session.gpo_code_verified = true
idv_session.create_profile_from_applicant_with_password('password', is_enhanced_ipp)
idv_session.create_profile_from_applicant_with_password(
'password', is_enhanced_ipp:, proofing_components: {}
)

expect(subject.info_for_latest_step.key).to eq(:personal_key)
expect(subject.controller_allowed?(controller: Idv::PersonalKeyController)).to be
Expand All @@ -326,7 +328,9 @@
let(:is_enhanced_ipp) { false }
it 'returns personal_key' do
stub_up_to(:otp_verification, idv_session: idv_session)
idv_session.create_profile_from_applicant_with_password('password', is_enhanced_ipp)
idv_session.create_profile_from_applicant_with_password(
'password', is_enhanced_ipp:, proofing_components: {}
)

expect(subject.info_for_latest_step.key).to eq(:personal_key)
expect(subject.controller_allowed?(controller: Idv::PersonalKeyController)).to be
Expand Down
12 changes: 10 additions & 2 deletions spec/services/idv/profile_maker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
let(:user_password) { user.password }
let(:initiating_service_provider) { nil }
let(:in_person_proofing_enforce_tmx_mock) { false }
let(:proofing_components) { { document_check: :mock } }

subject do
described_class.new(
Expand All @@ -18,12 +19,12 @@
end

it 'creates an inactive Profile with encrypted PII' do
proofing_component = ProofingComponent.create(user_id: user.id, document_check: 'mock')
profile = subject.save_profile(
fraud_pending_reason: nil,
gpo_verification_needed: false,
in_person_verification_needed: false,
selfie_check_performed: false,
proofing_components:,
)
pii = subject.pii_attributes

Expand All @@ -32,7 +33,7 @@
expect(profile.encrypted_pii).to_not be_nil
expect(profile.encrypted_pii).to_not match('Some')
expect(profile.fraud_pending_reason).to be_nil
expect(profile.proofing_components).to match(proofing_component.as_json)
expect(profile.proofing_components).to match(proofing_components.as_json)
expect(profile.active).to eq(false)
expect(profile.deactivation_reason).to be_nil

Expand All @@ -48,6 +49,7 @@
deactivation_reason: :encryption_error,
in_person_verification_needed: false,
selfie_check_performed: false,
proofing_components:,
)
end
it 'creates an inactive profile with deactivation reason' do
Expand Down Expand Up @@ -75,6 +77,7 @@
deactivation_reason: nil,
in_person_verification_needed: in_person_verification_needed,
selfie_check_performed: false,
proofing_components:,
)
end

Expand Down Expand Up @@ -118,6 +121,7 @@
deactivation_reason: nil,
in_person_verification_needed: false,
selfie_check_performed: false,
proofing_components:,
)
end
it 'creates a pending profile for gpo verification' do
Expand Down Expand Up @@ -151,6 +155,7 @@
deactivation_reason: nil,
in_person_verification_needed: true,
selfie_check_performed: false,
proofing_components:,
)
end

Expand Down Expand Up @@ -190,6 +195,7 @@
deactivation_reason: nil,
in_person_verification_needed: true,
selfie_check_performed: false,
proofing_components:,
)
end

Expand Down Expand Up @@ -220,6 +226,7 @@
deactivation_reason: nil,
in_person_verification_needed: false,
selfie_check_performed: selfie_check_performed,
proofing_components:,
)
end

Expand Down Expand Up @@ -267,6 +274,7 @@
deactivation_reason: nil,
in_person_verification_needed: false,
selfie_check_performed: false,
proofing_components:,
)
end
it 'creates a profile with the initiating sp recorded' do
Expand Down
51 changes: 38 additions & 13 deletions spec/services/idv/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
RSpec.describe Idv::Session do
let(:user) { create(:user) }
let(:user_session) { {} }
let(:is_enhanced_ipp) { false }

subject do
Idv::Session.new(user_session: user_session, current_user: user, service_provider: nil)
Expand Down Expand Up @@ -128,6 +127,8 @@
end

describe '#create_profile_from_applicant_with_password' do
let(:is_enhanced_ipp) { false }
let(:proofing_components) { { document_check: 'mock' } }
let(:opt_in_param) { nil }

before do
Expand All @@ -146,7 +147,9 @@
now = Time.zone.now

subject.user_phone_confirmation = true
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
profile = subject.profile

expect(profile.activated_at).to eq now
Expand All @@ -165,7 +168,9 @@

it 'does not complete the profile if the user has not completed OTP phone confirmation' do
subject.user_phone_confirmation = nil
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
profile = subject.profile

expect(profile.activated_at).to eq nil
Expand Down Expand Up @@ -200,7 +205,9 @@
end

it 'creates an USPS enrollment' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
expect(UspsInPersonProofing::EnrollmentHelper).to have_received(
:schedule_in_person_enrollment,
).with(
Expand All @@ -212,7 +219,9 @@
end

it 'creates a profile with in person verification pending' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
expect(profile).to have_attributes(
{
activated_at: nil,
Expand All @@ -227,12 +236,16 @@
end

it 'saves the pii to the session' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
expect(Pii::Cacher.new(user, user_session).fetch(profile.id)).to_not be_nil
end

it 'associates the in person enrollment with the created profile' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
expect(enrollment.reload.profile_id).to eq(profile.id)
end
end
Expand All @@ -245,7 +258,9 @@
end

it 'does not create a profile' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
rescue
expect(profile).to be_nil
end
Expand All @@ -264,14 +279,18 @@
end

it 'does not create an USPS enrollment' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
expect(UspsInPersonProofing::EnrollmentHelper).to_not have_received(
:schedule_in_person_enrollment,
)
end

it 'creates a profile' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
expect(profile).to have_attributes(
{
active: true,
Expand All @@ -284,7 +303,9 @@
end

it 'saves the pii to the session' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
expect(Pii::Cacher.new(user, user_session).fetch(profile.id)).to_not be_nil
end
end
Expand All @@ -297,7 +318,9 @@
end

it 'sets profile to pending gpo verification' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
profile = subject.profile

expect(profile.activated_at).to eq nil
Expand All @@ -321,7 +344,9 @@
end

it 'does not complete the user profile' do
subject.create_profile_from_applicant_with_password(user.password, is_enhanced_ipp)
subject.create_profile_from_applicant_with_password(
user.password, is_enhanced_ipp:, proofing_components:
)
profile = subject.profile

expect(profile.activated_at).to eq nil
Expand Down