Skip to content

Commit

Permalink
AO3-6518 Spam check runs on abuse reports if the email you enter has …
Browse files Browse the repository at this point in the history
…different capitalization than the email on your account (#4755)

* downcase email before compare

* added test

* updated `:safe_report`s initialization
  • Loading branch information
forceofcalm authored Feb 5, 2025
1 parent 5ee5670 commit 9197368
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/abuse_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def check_for_spam
end

def logged_in_with_matching_email?
User.current_user.present? && User.current_user.email == email
User.current_user.present? && User.current_user.email.downcase == email.downcase
end

def akismet_attributes
Expand Down
9 changes: 8 additions & 1 deletion spec/models/abuse_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
context "when report is spam" do
let(:legit_user) { create(:user) }
let(:spam_report) { build(:abuse_report, username: 'viagra-test-123') }
let(:safe_report) { build(:abuse_report, username: 'viagra-test-123', email: legit_user.email) }
let!(:safe_report) { build(:abuse_report, username: 'viagra-test-123', email: legit_user.email) }

before do
allow(Akismetor).to receive(:spam?).and_return(true)
Expand All @@ -340,6 +340,13 @@
expect(spam_report.errors[:base]).to include("This report looks like spam to our system!")
end

it "is valid even if the email casing is different" do
legit_user.email = legit_user.email.upcase
legit_user.save
User.current_user = legit_user
expect(safe_report.save).to be_truthy
end

it "is valid even with spam if logged in and providing correct email" do
User.current_user = legit_user
expect(safe_report.save).to be_truthy
Expand Down

0 comments on commit 9197368

Please sign in to comment.