Skip to content

Commit

Permalink
Add remaining reminder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bettymakes committed Aug 7, 2022
1 parent 686a9c1 commit e972c08
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion test/unit/mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class MailerTest < ActionMailer::TestCase
create(:rubygem, owners: [user], downloads: MIN_DOWNLOADS_FOR_MFA_REQUIRED_POLICY)

@io_output, _error = capture_io { Rake::Task["mfa_policy:reminder_enable_mfa"].execute }

Delayed::Worker.new.work_off

refute_empty ActionMailer::Base.deliveries
Expand All @@ -41,6 +40,44 @@ class MailerTest < ActionMailer::TestCase
assert_match "Thank you for making the RubyGems ecosystem more secure", email.text_part.body.to_s
assert_match "Sending 1 MFA reminder email", @io_output
end

should "send mail to users with with more than 180M+ downloads and have weak MFA" do
user = create(:user, mfa_level: "ui_only")
create(:rubygem, owners: [user], downloads: MIN_DOWNLOADS_FOR_MFA_REQUIRED_POLICY)

@io_output, _error = capture_io { Rake::Task["mfa_policy:reminder_enable_mfa"].execute }
Delayed::Worker.new.work_off

refute_empty ActionMailer::Base.deliveries
email = ActionMailer::Base.deliveries.last
assert_equal [user.email], email.to
assert_equal ["[email protected]"], email.from
assert_equal "[Action Required] Enable multi-factor authentication on your RubyGems account by August 15", email.subject
assert_match "Recently, we've announced our security-focused ambitions to the community.", email.text_part.body.to_s
assert_match "Sending 1 MFA reminder email", @io_output
end

should "not send mail to users with with more than 180M+ downloads and have strong MFA" do
user = create(:user, mfa_level: "ui_and_api")
create(:rubygem, owners: [user], downloads: MIN_DOWNLOADS_FOR_MFA_REQUIRED_POLICY)

@io_output, _error = capture_io { Rake::Task["mfa_policy:reminder_enable_mfa"].execute }
Delayed::Worker.new.work_off

assert_empty ActionMailer::Base.deliveries
assert_match "Sending 0 MFA announcement email", @io_output
end

should "not send mail to users with with less than 180M downloads" do
user = create(:user)
create(:rubygem, owners: [user], downloads: MIN_DOWNLOADS_FOR_MFA_REQUIRED_POLICY - 1)

@io_output, _error = capture_io { Rake::Task["mfa_policy:reminder_enable_mfa"].execute }
Delayed::Worker.new.work_off

assert_empty ActionMailer::Base.deliveries
assert_match "Sending 0 MFA announcement email", @io_output
end
end

teardown do
Expand Down

0 comments on commit e972c08

Please sign in to comment.