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 Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem 'rails', '~> 6.1.4'
@hostdata_gem ||= { github: '18F/identity-hostdata', tag: 'v3.4.0' }
@logging_gem ||= { github: '18F/identity-logging', tag: 'v0.1.0' }
@saml_gem ||= { github: '18F/saml_idp', tag: 'v0.14.3-18f' }
@telephony_gem ||= { github: '18f/identity-telephony', tag: 'v0.3.1' }
@telephony_gem ||= { github: '18f/identity-telephony', tag: 'v0.4.0' }
@validations_gem ||= { github: '18F/identity-validations', tag: 'v0.7.0' }

gem 'identity-hostdata', @hostdata_gem
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ GIT

GIT
remote: https://github.com/18f/identity-telephony.git
revision: ce223b6e55e052a63d6bf731f3bd90957cb2040c
tag: v0.3.1
revision: b73e77c5b003c1b5aad9e3db867f5896781e9e88
tag: v0.4.0
specs:
identity-telephony (0.3.1)
identity-telephony (0.4.0)
aws-sdk-pinpoint
aws-sdk-pinpointsmsvoice
i18n
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/users/personal_keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def send_new_personal_key_notifications

telephony_responses = MfaContext.new(current_user).
phone_configurations.map do |phone_configuration|
Telephony.send_personal_key_regeneration_notice(to: phone_configuration.phone)
phone = phone_configuration.phone
Telephony.send_personal_key_regeneration_notice(
to: phone,
country_code: Phonelib.parse(phone).country,
)
end

form_response(emails: emails, telephony_responses: telephony_responses)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def send_user_otp(method)
expiration: TwoFactorAuthenticatable::DIRECT_OTP_VALID_FOR_MINUTES,
channel: method.to_sym,
domain: IdentityConfig.store.domain_name,
country_code: parsed_phone.country,
}

if UserSessionContext.authentication_context?(context)
Expand Down
5 changes: 4 additions & 1 deletion app/services/account_reset/cancel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def notify_user_via_email_of_account_reset_cancellation
end

def notify_user_via_phone_of_account_reset_cancellation
@telephony_response = Telephony.send_account_reset_cancellation_notice(to: phone)
@telephony_response = Telephony.send_account_reset_cancellation_notice(
to: phone,
country_code: Phonelib.parse(phone).country,
)
end

def update_account_reset_request
Expand Down
5 changes: 4 additions & 1 deletion app/services/account_reset/create_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def notify_user_by_email(request)
def notify_user_by_sms_if_applicable
phone = MfaContext.new(user).phone_configurations.take&.phone
return unless phone
@telephony_response = Telephony.send_account_reset_notice(to: phone)
@telephony_response = Telephony.send_account_reset_notice(
to: phone,
country_code: Phonelib.parse(phone).country,
)
end

def extra_analytics_attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def notify_user_via_email_of_account_reset_cancellation

def notify_user_via_phone_of_account_reset_cancellation
MfaContext.new(user).phone_configurations.each do |phone_configuration|
Telephony.send_account_reset_cancellation_notice(to: phone_configuration.phone)
phone = phone_configuration.phone
Telephony.send_account_reset_cancellation_notice(
to: phone,
country_code: Phonelib.parse(phone).country,
)
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion app/services/idv/send_phone_confirmation_otp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def send_otp
expiration: TwoFactorAuthenticatable::DIRECT_OTP_VALID_FOR_MINUTES,
channel: delivery_method,
domain: IdentityConfig.store.domain_name,
country_code: parsed_phone.country,
)
add_cost
otp_sent_response
Expand All @@ -76,7 +77,6 @@ def add_cost
end

def extra_analytics_attributes
parsed_phone = Phonelib.parse(phone)
{
otp_delivery_preference: delivery_method,
country_code: parsed_phone.country,
Expand All @@ -85,5 +85,9 @@ def extra_analytics_attributes
telephony_response: @telephony_response,
}
end

def parsed_phone
@parsed_phone ||= Phonelib.parse(phone)
end
end
end
1 change: 1 addition & 0 deletions app/services/idv/steps/send_link_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def send_link
Telephony.send_doc_auth_link(
to: formatted_destination_phone,
link: link(session_uuid),
country_code: Phonelib.parse(formatted_destination_phone).country,
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ def self.call(user, disavowal_token)
).deliver_now
end
telephony_responses = MfaContext.new(user).phone_configurations.map do |phone_configuration|
Telephony.send_personal_key_sign_in_notice(to: phone_configuration.phone)
phone = phone_configuration.phone
Telephony.send_personal_key_sign_in_notice(
to: phone,
country_code: Phonelib.parse(phone).country,
)
end
form_response(emails: emails, telephony_responses: telephony_responses)
end
Expand Down
1 change: 1 addition & 0 deletions config/application.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ database_timeout: '5000'
deleted_user_accounts_report_configs: '[]'
disable_email_sending: 'true'
disallow_all_web_crawlers: 'true'
pinpoint_sms_sender_id: 'aaa'
doc_auth_extend_timeout_by_minutes: '40'
doc_capture_polling_enabled: 'true'
doc_auth_client_glare_threshold: '50'
Expand Down
7 changes: 6 additions & 1 deletion config/initializers/telephony.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'pinpoint_supported_countries'
Copy link
Contributor

Choose a reason for hiding this comment

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

comment: omg I did not know this file existed - mind blown.


# rubocop:disable Metrics/BlockLength
Telephony.config do |c|
c.adapter = IdentityConfig.store.telephony_adapter.to_sym
Expand All @@ -10,7 +12,10 @@
c.voice_pause_time = IdentityConfig.store.voice_otp_pause_time
c.voice_rate = IdentityConfig.store.voice_otp_speech_rate

c.sender_id = IdentityConfig.store.pinpoint_sms_sender_id
c.country_sender_ids = IdentityConfig.store.pinpoint_sms_sender_id.presence &&
PinpointSupportedCountries::SENDER_ID_COUNTRIES.index_with do
IdentityConfig.store.pinpoint_sms_sender_id
end

IdentityConfig.store.pinpoint_sms_configs.each do |sms_json_config|
c.pinpoint.add_sms_config do |sms|
Expand Down
2 changes: 0 additions & 2 deletions config/pinpoint_overrides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ IE:
supports_voice: false
IL:
supports_voice: false
IN:
supports_sms: true
IQ:
supports_sms_unconfirmed: false
IS:
Expand Down
2 changes: 1 addition & 1 deletion config/pinpoint_supported_countries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ IM:
IN:
country_code: '91'
name: India
supports_sms: false
supports_sms: true
supports_voice: false
IQ:
country_code: '964'
Expand Down
14 changes: 8 additions & 6 deletions lib/pinpoint_supported_countries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ def sms_support
select { |sms_config| sms_config['ISO code'] }. # skip section rows
map do |sms_config|
iso_code = sms_config['ISO code']
supports_sms = case trim_digits_spaces(sms_config['Supports sender IDs'])
when 'Registration required'
supports_sms = case trim_spaces(sms_config['Supports sender IDs'])
when 'Registration required1'
SENDER_ID_COUNTRIES.include?(iso_code)
when 'Registration required3' # basically only India, has special rules
true
else
true
end

CountrySupport.new(
iso_code: iso_code,
name: trim_digits_spaces(sms_config['Country or region']),
name: trim_spaces(sms_config['Country or region']),
supports_sms: supports_sms,
)
end
Expand All @@ -85,7 +87,7 @@ def sms_support
def voice_support
TableConverter.new(download(PINPOINT_VOICE_URL)).convert.map do |voice_config|
CountrySupport.new(
name: trim_digits_spaces(
name: trim_spaces(
voice_config['Country or Region'], # Yes, it is capitalized differently :[
),
supports_voice: true,
Expand Down Expand Up @@ -145,8 +147,8 @@ def name_to_iso_code(name)
}[name]
end

def trim_digits_spaces(str)
str.gsub(/\s{2,}/, ' ').gsub(/[\d\s]+$/, '')
def trim_spaces(str)
str.gsub(/\s{2,}/, ' ').gsub(/\s+$/, '')
end

def digits_only?(str)
Expand Down
4 changes: 4 additions & 0 deletions spec/controllers/test/telephony_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
expiration: 10,
channel: :sms,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)
Telephony.send_authentication_otp(
to: '(555) 555-5000',
otp: '654321',
expiration: 10,
channel: :voice,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)

get :index
Expand Down Expand Up @@ -44,13 +46,15 @@
expiration: 10,
channel: :sms,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)
Telephony.send_authentication_otp(
to: '(555) 555-5000',
otp: '654321',
expiration: 10,
channel: :voice,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)

delete :destroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def index
expiration: 10,
channel: :sms,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)
expect(subject.current_user.direct_otp).not_to eq(@old_otp)
expect(subject.current_user.direct_otp).not_to be_nil
Expand Down Expand Up @@ -328,6 +329,7 @@ def index
expiration: 10,
channel: :voice,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)
expect(subject.current_user.direct_otp).not_to eq(@old_otp)
expect(subject.current_user.direct_otp).not_to be_nil
Expand Down Expand Up @@ -384,6 +386,7 @@ def index
expiration: 10,
channel: :sms,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
expiration: 10,
channel: :sms,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)

expect(current_path).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
expect(personal_key_sign_in_mail).to receive(:deliver_now)
expect(UserMailer).to receive(:personal_key_sign_in).and_return(personal_key_sign_in_mail)
expect(Telephony).to receive(:send_personal_key_sign_in_notice).
with(to: '+1 (202) 345-6789')
with(to: '+1 (202) 345-6789', country_code: 'US')

sign_in_before_2fa(user)
choose_another_security_option('personal_key')
Expand Down
2 changes: 1 addition & 1 deletion spec/features/users/regenerate_personal_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
with(user, user.email).
and_return(personal_key_sign_in_mail)
expect(Telephony).to receive(:send_personal_key_regeneration_notice).
with(to: user.phone_configurations.first.phone)
with(to: user.phone_configurations.first.phone, country_code: 'US')

visit account_two_factor_authentication_path
click_button t('account.links.regenerate_personal_key')
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/pinpoint_supported_countries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>India</td>
<td>IN</td>
<td>Registration required<sup><a href="#sms-support-note-3">3</a></sup>
</td>
<td>Yes</td>
</tr>
</table>
HTML
end
Expand Down Expand Up @@ -116,6 +123,11 @@
name: Cayman Islands
supports_sms: true
supports_voice: true
IN:
country_code: '91'
name: India
supports_sms: true
supports_voice: false
STR
end
end
Expand All @@ -128,6 +140,7 @@
PinpointSupportedCountries::CountrySupport.new(iso_code: 'AU', name: 'Australia', supports_sms: true),
PinpointSupportedCountries::CountrySupport.new(iso_code: 'BY', name: 'Belarus', supports_sms: true),
PinpointSupportedCountries::CountrySupport.new(iso_code: 'KY', name: 'Cayman Islands', supports_sms: true),
PinpointSupportedCountries::CountrySupport.new(iso_code: 'IN', name: 'India', supports_sms: true),
]
end
# rubocop:enable Layout/LineLength
Expand Down Expand Up @@ -164,6 +177,7 @@
PinpointSupportedCountries::CountryDialingCode.new(country_code: '61', iso_code: 'AU', name: 'Australia', supports_sms: true, supports_voice: true),
PinpointSupportedCountries::CountryDialingCode.new(country_code: '375', iso_code: 'BY', name: 'Belarus', supports_sms: true, supports_voice: false),
PinpointSupportedCountries::CountryDialingCode.new(country_code: '1345', iso_code: 'KY', name: 'Cayman Islands', supports_sms: true, supports_voice: true),
PinpointSupportedCountries::CountryDialingCode.new(country_code: '91', iso_code: 'IN', name: 'India', supports_sms: true, supports_voice: false),
]
end
# rubocop:enable Layout/LineLength
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
phone_config2 = create(:phone_configuration, user: user)

expect(Telephony).to receive(:send_account_reset_cancellation_notice).
with(to: phone_config1.phone)
with(to: phone_config1.phone, country_code: 'US')
expect(Telephony).to receive(:send_account_reset_cancellation_notice).
with(to: phone_config2.phone)
with(to: phone_config2.phone, country_code: 'US')

subject.call
end
Expand Down
2 changes: 2 additions & 0 deletions spec/services/idv/send_phone_confirmation_otp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
expiration: 10,
channel: :sms,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)
end
end
Expand All @@ -85,6 +86,7 @@
expiration: 10,
channel: :voice,
domain: IdentityConfig.store.domain_name,
country_code: 'US',
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
expect(UserMailer).to have_received(:personal_key_sign_in).
with(user, confirmed_email_addresses[1].email, disavowal_token: disavowal_token)
expect(Telephony).to have_received(:send_personal_key_sign_in_notice).
with(to: phone_configurations[0].phone)
with(to: phone_configurations[0].phone, country_code: 'US')
expect(Telephony).to have_received(:send_personal_key_sign_in_notice).
with(to: phone_configurations[1].phone)
with(to: phone_configurations[1].phone, country_code: 'US')

expect(response.to_h[:emails]).to eq(2)
expect(response.to_h[:sms_message_ids].size).to eq(2)
Expand Down