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
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def confirm_voice_capability
return if params[:otp_delivery_preference] == 'sms'

phone_is_confirmed = UserSessionContext.authentication_or_reauthentication_context?(context)

capabilities = PhoneNumberCapabilities.new(phone, phone_confirmed: phone_is_confirmed)

return if capabilities.supports_voice?
Expand Down Expand Up @@ -233,6 +234,7 @@ def update_phone_attributes
user: current_user,
attributes: { phone_id: user_session[:phone_id],
phone: user_session[:unconfirmed_phone],
phone_confirmed_at: Time.zone.now,
otp_make_default_number: selected_otp_make_default_number },
)
end
Expand Down
6 changes: 5 additions & 1 deletion app/services/update_user_phone_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def initialize(user:, attributes:)

def call
result = user.update!(
attributes.except(:phone_id, :phone, :otp_make_default_number),
attributes.except(
:phone_id, :phone, :phone_confirmed_at,
:otp_make_default_number
),
)
manage_phone_configuration
result
Expand Down Expand Up @@ -51,6 +54,7 @@ def duplicate_phone?
def phone_attributes
@phone_attributes ||= {
phone: attributes[:phone],
confirmed_at: attributes[:phone_confirmed_at],
delivery_preference: attribute(:otp_delivery_preference),
made_default_at: made_default_at_date,
}.delete_if { |_, value| value.nil? }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def phone_configurations_report
id: phone_configuration.id,
phone: phone_configuration.phone,
created_at: phone_configuration.created_at,
confirmed_at: phone_configuration.confirmed_at,
}
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/create_test_accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def create_account(email: 'joe.smith@email.com', password: 'salty pickles', mfa_
user.save!
MfaContext.new(user).phone_configurations.create(
phone: mfa_phone || phone,
confirmed_at: Time.zone.now,
delivery_preference: user.otp_delivery_preference
)
Event.create(user_id: user.id, event_type: :account_created)
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/dev.rake
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ namespace :dev do
{
delivery_preference: user.otp_delivery_preference,
phone: format('+1 (415) 555-%04d', args[:num]),
confirmed_at: Time.zone.now,
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,10 @@
expect(subject.user_session[:unconfirmed_phone]).to eq('+1 (703) 555-5555')
end

it 'does not update user phone' do
it 'does not update user phone or phone_confirmed_at attributes' do
first_configuration = MfaContext.new(subject.current_user).phone_configurations.first
expect(first_configuration.phone).to eq('+1 202-555-1212')
expect(first_configuration.confirmed_at).to eq(@previous_phone_confirmed_at)
end

it 'renders :show' do
Expand Down
1 change: 1 addition & 0 deletions spec/factories/phone_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Faker::Config.locale = :en

factory :phone_configuration do
confirmed_at { Time.zone.now }
phone { '+1 202-555-1212' }
mfa_enabled { true }
user { association :user }
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
user_id: -1,
}.merge(
evaluator.with.slice(
:phone, :delivery_preference, :mfa_enabled
:phone, :confirmed_at, :delivery_preference, :mfa_enabled
),
),
)
Expand All @@ -135,7 +135,7 @@
delivery_preference: user.otp_delivery_preference,
}.merge(
evaluator.with.slice(
:phone, :delivery_preference, :mfa_enabled
:phone, :confirmed_at, :delivery_preference, :mfa_enabled
),
),
)
Expand Down
2 changes: 2 additions & 0 deletions spec/features/phone/add_phone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

expect(page).to have_current_path(account_path)
expect(user.reload.phone_configurations.count).to eq(2)
expect(user.phone_configurations[0].confirmed_at).to be_present
expect(user.phone_configurations[1].confirmed_at).to be_present
end

scenario 'adding a new phone number sends the user an email with a disavowal link' do
Expand Down
2 changes: 2 additions & 0 deletions spec/features/phone/confirmation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def expect_successful_otp_confirmation(delivery_method)
expect(page).to have_content(t('notices.phone_confirmed'))

expect(page).to have_current_path(auth_method_confirmation_path)
expect(phone_configuration.confirmed_at).to_not be_nil
expect(phone_configuration.delivery_preference).to eq(delivery_method.to_s)
end

Expand Down Expand Up @@ -76,6 +77,7 @@ def visit_otp_confirmation(delivery_method)
def expect_successful_otp_confirmation(delivery_method)
expect(page).to have_content(t('notices.phone_confirmed'))
expect(page).to have_current_path(account_path)
expect(phone_configuration.confirmed_at).to_not be_nil
expect(phone_configuration.delivery_preference).to eq(delivery_method.to_s)
end

Expand Down
3 changes: 2 additions & 1 deletion spec/fixtures/data_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
{
"id": 123456,
"phone": "+1 555-555-5555",
"created_at": "2021-10-21T14:53:08.803Z"
"created_at": "2021-10-21T14:53:08.803Z",
"confirmed_at": "2021-10-21T14:53:08.790Z"
}
],
"auth_app_configurations": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
expect(phone_data.first[:created_at]).to be_within(1.second).of(
phone_configuration.created_at,
)
expect(phone_data.first[:confirmed_at]).to be_within(1.second).of(
phone_configuration.confirmed_at,
)
end

it 'includes an array for authentication apps' do
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/data_requests/local/write_user_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
expect(email_row['uuid']).to eq(uuid)
expect(email_row['value']).to eq('test@example.com')
expect(email_row['created_at']).to be_present
expect(email_row['confirmed_at']).to be_present
expect(email_row['internal_id']).to be_nil

phone_row = parsed.find { |r| r['type'] == 'Phone configuration' }
expect(phone_row['uuid']).to eq(uuid)
expect(phone_row['value']).to eq('+1 555-555-5555')
expect(phone_row['created_at']).to be_present
expect(phone_row['confirmed_at']).to be_present
expect(phone_row['internal_id']).to be_present
end

Expand Down