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/services/user_alerts/alert_user_about_new_device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.send_alert(user:, disavowal_event:, disavowal_token:)
'sign_in_unsuccessful_2fa',
'sign_in_after_2fa',
],
).order(:created_at).includes(:device)
).order(:created_at).includes(:device).to_a
Copy link
Contributor

Choose a reason for hiding this comment

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

Not worth blocking this fix, but I think we could consider a limit here on the outside chance that there are an incredible number of events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll follow-up with you separately on this. I agree with the general premise, but I'd have some concern about limiting what we show here.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe if there are more we just get the count of the rest and say something like "and 15 more devices"


user.confirmed_email_addresses.each do |email_address|
mailer = UserMailer.with(user:, email_address:)
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/report_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
end

it_behaves_like 'a system email'
it_behaves_like 'a system email', synchronous_only: true

it 'sends to the current email' do
expect(mail.to).to eq [email_address.email]
Expand Down
28 changes: 27 additions & 1 deletion spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rails_helper'

RSpec.describe UserMailer, type: :mailer do
let(:user) { build(:user) }
let(:user) { create(:user) }
let(:email_address) { user.email_addresses.first }
let(:banned_email) { 'banned_email+123abc@gmail.com' }
let(:banned_email_address) { create(:email_address, email: banned_email, user: user) }
Expand Down Expand Up @@ -205,6 +205,32 @@
end
end

describe '#new_device_sign_in_before_2fa' do
let(:event) { create(:event, event_type: :sign_in_before_2fa, user:, device: create(:device)) }
subject(:mail) do
UserMailer.with(user:, email_address:).new_device_sign_in_before_2fa(
events: user.events.where(event_type: 'sign_in_before_2fa').includes(:device).to_a,
disavowal_token: 'token',
)
end

it_behaves_like 'a system email'
it_behaves_like 'an email that respects user email locale preference'
end

describe '#new_device_sign_in_after_2fa' do
let(:event) { create(:event, event_type: :sign_in_after_2fa, user:, device: create(:device)) }
subject(:mail) do
UserMailer.with(user:, email_address:).new_device_sign_in_after_2fa(
events: user.events.where(event_type: 'sign_in_after_2fa').includes(:device).to_a,
disavowal_token: 'token',
)
end

it_behaves_like 'a system email'
it_behaves_like 'an email that respects user email locale preference'
end

describe '#personal_key_regenerated' do
let(:mail) do
UserMailer.with(user: user, email_address: email_address).personal_key_regenerated
Expand Down
6 changes: 5 additions & 1 deletion spec/support/shared_examples_for_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.shared_examples 'a system email' do
RSpec.shared_examples 'a system email' do |synchronous_only: false|
it 'is from the default email' do
expect(mail.from).to eq [IdentityConfig.store.email_from]
expect(mail[:from].display_names).to eq [IdentityConfig.store.email_from_display_name]
Expand All @@ -10,6 +10,10 @@
# https://www.caniemail.com/features/image-svg/
expect(body).not_to have_css('img[src$=".svg"]')
end

it 'does not error when delivered asynchronously', unless: synchronous_only do
mail.deliver_later
end
end

# expects there to be a let(:user) in scope
Expand Down