-
Notifications
You must be signed in to change notification settings - Fork 166
ProgressiveProofer refactor 1/N: ThreatMetrix #11420
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
Changes from all commits
66aa5f4
6857146
7d96842
083f8f5
0267f9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Proofing | ||
| module Resolution | ||
| module Plugins | ||
| class ThreatMetrixPlugin | ||
| def call( | ||
| applicant_pii:, | ||
| current_sp:, | ||
| request_ip:, | ||
| threatmetrix_session_id:, | ||
| timer:, | ||
| user_email: | ||
| ) | ||
| unless FeatureManagement.proofing_device_profiling_collecting_enabled? | ||
| return threatmetrix_disabled_result | ||
| end | ||
|
|
||
| # The API call will fail without a session ID, so do not attempt to make | ||
| # it to avoid leaking data when not required. | ||
| return threatmetrix_id_missing_result if threatmetrix_session_id.blank? | ||
| return threatmetrix_pii_missing_result if applicant_pii.blank? | ||
|
|
||
| ddp_pii = applicant_pii.merge( | ||
| threatmetrix_session_id: threatmetrix_session_id, | ||
| email: user_email, | ||
| request_id: request_ip, | ||
| ) | ||
|
|
||
| timer.time('threatmetrix') do | ||
| proofer.proof(ddp_pii) | ||
| end.tap do |result| | ||
| Db::SpCost::AddSpCost.call( | ||
| current_sp, :threatmetrix, | ||
| transaction_id: result.transaction_id | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| def proofer | ||
| @proofer ||= | ||
| if IdentityConfig.store.lexisnexis_threatmetrix_mock_enabled | ||
| Proofing::Mock::DdpMockClient.new | ||
| else | ||
| Proofing::LexisNexis::Ddp::Proofer.new( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a heads up. Will be updating the config to add a "policy" attribute since we have decided for Authentication we will have a different policy. But otherwise. Taking a look this shouldn't affect our implementation much. may be a merge conflict depending on whats merged first. |
||
| api_key: IdentityConfig.store.lexisnexis_threatmetrix_api_key, | ||
| org_id: IdentityConfig.store.lexisnexis_threatmetrix_org_id, | ||
| base_url: IdentityConfig.store.lexisnexis_threatmetrix_base_url, | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| def threatmetrix_disabled_result | ||
| Proofing::DdpResult.new( | ||
| success: true, | ||
| client: 'tmx_disabled', | ||
| review_status: 'pass', | ||
| ) | ||
| end | ||
|
|
||
| def threatmetrix_pii_missing_result | ||
| Proofing::DdpResult.new( | ||
| success: false, | ||
| client: 'tmx_pii_missing', | ||
| review_status: 'reject', | ||
| ) | ||
| end | ||
|
|
||
| def threatmetrix_id_missing_result | ||
| Proofing::DdpResult.new( | ||
| success: false, | ||
| client: 'tmx_session_id_missing', | ||
| review_status: 'reject', | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Proofing::Resolution::Plugins::ThreatMetrixPlugin do | ||
| let(:applicant_pii) { Idp::Constants::MOCK_IDV_APPLICANT_WITH_SSN } | ||
| let(:current_sp) { build(:service_provider) } | ||
| let(:proofer_result) do | ||
| instance_double(Proofing::DdpResult, success?: true, transaction_id: 'ddp-123') | ||
| end | ||
| let(:request_ip) { Faker::Internet.ip_v4_address } | ||
| let(:threatmetrix_session_id) { 'cool-session-id' } | ||
| let(:user_email) { Faker::Internet.email } | ||
|
|
||
| subject(:plugin) do | ||
| described_class.new | ||
| end | ||
|
|
||
| before do | ||
| allow(IdentityConfig.store).to receive(:lexisnexis_threatmetrix_mock_enabled). | ||
| and_return(false) | ||
| allow(plugin.proofer).to receive(:proof).and_return(proofer_result) | ||
| end | ||
|
|
||
| describe '#call' do | ||
| def sp_cost_count | ||
| SpCost.where(cost_type: :threatmetrix, issuer: current_sp.issuer).count | ||
| end | ||
|
|
||
| subject(:call) do | ||
| plugin.call( | ||
| applicant_pii:, | ||
| current_sp:, | ||
| request_ip:, | ||
| threatmetrix_session_id:, | ||
| timer: JobHelpers::Timer.new, | ||
| user_email:, | ||
| ) | ||
| end | ||
|
|
||
| context 'ThreatMetrix is enabled' do | ||
| before do | ||
| allow(FeatureManagement).to receive(:proofing_device_profiling_collecting_enabled?). | ||
| and_return(true) | ||
| end | ||
|
|
||
| it 'calls the ThreatMetrix proofer' do | ||
| call | ||
| expect(plugin.proofer).to have_received(:proof) | ||
| end | ||
|
|
||
| it 'creates a ThreatMetrix associated cost' do | ||
| expect { call }.to change { sp_cost_count }.to(1) | ||
| end | ||
|
|
||
| context 'session id is missing' do | ||
| let(:threatmetrix_session_id) { nil } | ||
|
|
||
| it 'does not call the ThreatMetrix proofer' do | ||
| expect(plugin.proofer).not_to receive(:proof) | ||
| call | ||
| end | ||
|
|
||
| it 'returns a failed result' do | ||
| call.tap do |result| | ||
| expect(result.success).to be(false) | ||
| expect(result.client).to eq('tmx_session_id_missing') | ||
| expect(result.review_status).to eq('reject') | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'pii is missing' do | ||
| let(:applicant_pii) { {} } | ||
|
|
||
| it 'does not call the ThreatMetrix proofer' do | ||
| expect(plugin.proofer).not_to receive(:proof) | ||
| call | ||
| end | ||
|
|
||
| it 'returns a failed result' do | ||
| call.tap do |result| | ||
| expect(result.success).to be(false) | ||
| expect(result.client).to eq('tmx_pii_missing') | ||
| expect(result.review_status).to eq('reject') | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'ThreatMetrix is disabled' do | ||
| before do | ||
| allow(FeatureManagement).to receive(:proofing_device_profiling_collecting_enabled?). | ||
| and_return(false) | ||
| end | ||
|
|
||
| it 'returns a disabled result' do | ||
| call.tap do |result| | ||
| expect(result.success).to be(true) | ||
| expect(result.client).to eq('tmx_disabled') | ||
| expect(result.review_status).to eq('pass') | ||
| end | ||
| end | ||
|
|
||
| it 'does not create a ThreatMetrix associated cost' do | ||
| expect { call }.not_to change { sp_cost_count } | ||
| end | ||
| end | ||
| end | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.