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
2 changes: 1 addition & 1 deletion app/forms/new_phone_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def extra_analytics_attributes
end

def validate_not_voip
return if phone.blank?
return if phone.blank? || !FeatureManagement.voip_check?

@phone_info = Telephony.phone_info(phone)

Expand Down
1 change: 1 addition & 0 deletions config/application.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ usps_ipp_password: ''
usps_ipp_root_url: ''
usps_ipp_sponsor_id: ''
usps_ipp_username: ''
voip_check: 'false'
voip_block: 'false'
voip_allowed_phones: '[]'

Expand Down
5 changes: 5 additions & 0 deletions lib/feature_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ def self.log_to_stdout?
!Rails.env.test? && AppConfig.env.log_to_stdout == 'true'
end

# Whether or not we can call the phone_info endpoint at all
def self.voip_check?
AppConfig.env.voip_check == 'true'
end

# Whether or not we should block VOIP phone numbers
def self.voip_block?
AppConfig.env.voip_block == 'true'
Expand Down
5 changes: 4 additions & 1 deletion spec/controllers/users/phone_setup_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require 'rails_helper'

describe Users::PhoneSetupController do
before { allow(FeatureManagement).to receive(:voip_block?).and_return(true) }
before do
allow(FeatureManagement).to receive(:voip_check?).and_return(true)
allow(FeatureManagement).to receive(:voip_block?).and_return(true)
end

describe 'GET index' do
context 'when signed out' do
Expand Down
1 change: 1 addition & 0 deletions spec/features/phone/add_phone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

scenario 'adding a VOIP phone' do
allow(FeatureManagement).to receive(:voip_block?).and_return(true)
allow(FeatureManagement).to receive(:voip_check?).and_return(true)

user = create(:user, :signed_up)

Expand Down
40 changes: 34 additions & 6 deletions spec/forms/new_phone_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,20 @@

context 'voip numbers' do
let(:telephony_gem_voip_number) { '+12255552000' }
let(:voip_block?) { false }
let(:voip_check?) { true }

before do
allow(FeatureManagement).to receive(:voip_block?).and_return(voip_block?)
allow(FeatureManagement).to receive(:voip_check?).and_return(voip_check?)
end

subject(:result) do
form.submit(params.merge(phone: telephony_gem_voip_number))
end

context 'when voip numbers are blocked' do
before do
expect(FeatureManagement).to receive(:voip_block?).and_return(true)
end
let(:voip_block?) { true }

it 'is invalid' do
expect(result.success?).to eq(false)
Expand All @@ -186,12 +191,25 @@
expect(result.errors).to be_blank
end
end

context 'when voip checks are disabled' do
let(:voip_check?) { false }

it 'does not check the phone type' do
expect(Telephony).to_not receive(:phone_info)

result
end

it 'allows voip numbers since it cannot check the type' do
expect(result.success?).to eq(true)
expect(result.errors).to be_blank
end
end
end

context 'when voip numbers are allowed' do
before do
expect(FeatureManagement).to receive(:voip_block?).and_return(false)
end
let(:voip_block) { false }

it 'does a voip check but does not enforce it' do
expect(Telephony).to receive(:phone_info).and_call_original
Expand All @@ -200,6 +218,16 @@
expect(result.to_h).to include(phone_type: :voip)
end
end

context 'when voip checks are disabled' do
let(:voip_check?) { false }

it 'does not check the phone type' do
expect(Telephony).to_not receive(:phone_info)

result
end
end
end
end
end