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

[DO NOT REVIEW] [WIP] LG-15187: Update Socure A/B test logic, Pt.2 #11685

Closed
wants to merge 12 commits into from
7 changes: 7 additions & 0 deletions app/controllers/concerns/idv/verify_info_concern.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

module Idv
# @attr idv_session [Idv::Session]
module VerifyInfoConcern
extend ActiveSupport::Concern

Expand Down Expand Up @@ -39,6 +40,12 @@ def shared_update
threatmetrix_session_id: idv_session.threatmetrix_session_id,
request_ip: request.remote_ip,
ipp_enrollment_in_progress: ipp_enrollment_in_progress?,
proofing_components: ProofingComponents.new(
user: current_user,
idv_session:,
session:,
user_session:,
),
)

return true
Expand Down
39 changes: 28 additions & 11 deletions app/jobs/resolution_proofing_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def perform(
service_provider_issuer: nil,
threatmetrix_session_id: nil,
request_ip: nil,
proofing_components: nil, # rubocop:disable Lint/UnusedMethodArgument
proofing_components: nil,
# DEPRECATED ARGUMENTS
should_proof_state_id: false # rubocop:disable Lint/UnusedMethodArgument
)
Expand Down Expand Up @@ -75,7 +75,7 @@ def perform(
timing: timer.results,
)

if use_shadow_mode?(user:)
if use_shadow_mode?(user:, proofing_components:)
SocureShadowModeProofingJob.perform_later(
document_capture_session_result_id: document_capture_session&.result_id,
encrypted_arguments:,
Expand All @@ -86,15 +86,22 @@ def perform(
end
end

def use_shadow_mode?(user:)
IdentityConfig.store.idv_socure_shadow_mode_enabled &&
AbTests::SOCURE_IDV_SHADOW_MODE.bucket(
request: nil,
service_provider: nil,
session: nil,
user:,
user_session: nil,
) == :shadow_mode_enabled
# @param user [User]
# @param proofing_components [Hash,nil]
def use_shadow_mode?(user:, proofing_components:)
# Let idv_socure_shadow_mode_enabled setting to control shadow mode globally
disabled_globally = !IdentityConfig.store.idv_socure_shadow_mode_enabled
return false if disabled_globally

# If the user went through Socure docv, they are already a Socure user and
# are thus eligible for shadow mode.
enabled_for_docv_users =
IdentityConfig.store.idv_socure_shadow_mode_enabled_for_docv_users
is_docv_user = proofing_components&.dig(:document_check) == Idp::Constants::Vendors::SOCURE
return true if enabled_for_docv_users && is_docv_user

# Otherwise fall back to A/B test
shadow_mode_ab_test_bucket(user:) == :socure_shadow_mode_for_non_docv_users
end

private
Expand Down Expand Up @@ -150,4 +157,14 @@ def logger_info_hash(hash)
def progressive_proofer
@progressive_proofer ||= Proofing::Resolution::ProgressiveProofer.new
end

def shadow_mode_ab_test_bucket(user:)
AbTests::SOCURE_IDV_SHADOW_MODE_FOR_NON_DOCV_USERS.bucket(
request: nil,
service_provider: nil,
session: nil,
user:,
user_session: nil,
)
end
end
1 change: 1 addition & 0 deletions app/models/document_capture_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def load_result
EncryptedRedisStructStorage.load(result_id, type: DocumentCaptureSessionResult)
end

# @param doc_auth_response [DocAuth::Response]
def store_result_from_response(doc_auth_response)
session_result = load_result || DocumentCaptureSessionResult.new(
id: generate_result_id,
Expand Down
6 changes: 5 additions & 1 deletion app/services/idv/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ def initialize(applicant)
@applicant = applicant.symbolize_keys
end

# @param document_capture_session [DocumentCaptureSession]
# @param proofing_components [Idv::ProofingComponents]
def proof_resolution(
document_capture_session,
trace_id:,
user_id:,
threatmetrix_session_id:,
request_ip:,
ipp_enrollment_in_progress:
ipp_enrollment_in_progress:,
proofing_components:
)
document_capture_session.create_proofing_session

Expand All @@ -29,6 +32,7 @@ def proof_resolution(
threatmetrix_session_id: threatmetrix_session_id,
request_ip: request_ip,
ipp_enrollment_in_progress: ipp_enrollment_in_progress,
proofing_components: proofing_components.to_h,
}

if IdentityConfig.store.ruby_workers_idv_enabled
Expand Down
1 change: 1 addition & 0 deletions config/application.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ idv_send_link_attempt_window_in_minutes: 10
idv_send_link_max_attempts: 5
idv_socure_reason_code_download_enabled: false
idv_socure_shadow_mode_enabled: false
idv_socure_shadow_mode_enabled_for_docv_users: true
idv_sp_required: false
in_person_completion_survey_url: 'https://login.gov'
in_person_doc_auth_button_enabled: true
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/ab_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def self.all
},
).freeze

SOCURE_IDV_SHADOW_MODE = AbTest.new(
SOCURE_IDV_SHADOW_MODE_FOR_NON_DOCV_USERS = AbTest.new(
experiment_name: 'Socure shadow mode',
should_log: ['IdV: doc auth verify proofing results'].to_set,
buckets: {
shadow_mode_enabled: IdentityConfig.store.socure_idplus_shadow_mode_percent,
socure_shadow_mode_for_non_docv_users: IdentityConfig.store.socure_idplus_shadow_mode_percent,
},
).freeze

Expand Down
1 change: 1 addition & 0 deletions lib/identity_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def self.store
config.add(:idv_send_link_max_attempts, type: :integer)
config.add(:idv_socure_reason_code_download_enabled, type: :boolean)
config.add(:idv_socure_shadow_mode_enabled, type: :boolean)
config.add(:idv_socure_shadow_mode_enabled_for_docv_users, type: :boolean)
config.add(:idv_sp_required, type: :boolean)
config.add(:in_person_completion_survey_url, type: :string)
config.add(:in_person_doc_auth_button_enabled, type: :boolean)
Expand Down
19 changes: 10 additions & 9 deletions spec/config/initializers/ab_tests_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
require 'rails_helper'

RSpec.describe AbTests do
include AbTestsHelper

after :suite do
reload_ab_tests
end

describe '#all' do
it 'returns all registered A/B tests' do
expect(AbTests.all.values).to all(be_kind_of(AbTest))
Expand Down Expand Up @@ -59,17 +53,21 @@
},
}
end

it 'returns a bucket' do
expect(bucket).not_to be_nil
end
end

context 'and the user does not have an Idv::Session' do
let(:user_session) do
{}
end

it 'does not return a bucket' do
expect(bucket).to be_nil
end

it 'does not write :idv key in user_session' do
expect { bucket }.not_to change { user_session }
end
Expand All @@ -81,6 +79,7 @@
let(:session) do
{ document_capture_session_uuid: 'a-random-uuid' }
end

it 'returns a bucket' do
expect(bucket).not_to be_nil
end
Expand All @@ -96,6 +95,7 @@

context 'when A/B test is disabled and it would otherwise assign a bucket' do
let(:user) { build(:user) }

let(:user_session) do
{
idv: {
Expand All @@ -108,6 +108,7 @@
disable_ab_test.call
reload_ab_tests
end

it 'does not assign a bucket' do
expect(bucket).to be_nil
end
Expand Down Expand Up @@ -266,11 +267,11 @@
end
end

describe 'SOCURE_IDV_SHADOW_MODE' do
describe 'SOCURE_IDV_SHADOW_MODE_FOR_NON_DOCV_USERS' do
let(:user) { create(:user) }

subject(:bucket) do
AbTests::SOCURE_IDV_SHADOW_MODE.bucket(
AbTests::SOCURE_IDV_SHADOW_MODE_FOR_NON_DOCV_USERS.bucket(
request: nil,
service_provider: nil,
session: nil,
Expand Down Expand Up @@ -301,7 +302,7 @@
end

it 'returns a bucket' do
expect(bucket).to eq :shadow_mode_enabled
expect(bucket).to eq :socure_shadow_mode_for_non_docv_users
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/controllers/idv/in_person/verify_info_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
user_id: anything,
request_ip: request.remote_ip,
ipp_enrollment_in_progress: false,
proofing_components: Idv::ProofingComponents,
)

put :update
Expand All @@ -364,6 +365,7 @@
user_id: anything,
request_ip: anything,
ipp_enrollment_in_progress: true,
proofing_components: Idv::ProofingComponents,
)

put :update
Expand Down Expand Up @@ -392,6 +394,7 @@
user_id: anything,
request_ip: request.remote_ip,
ipp_enrollment_in_progress: true,
proofing_components: Idv::ProofingComponents,
)

put :update
Expand Down
Loading