Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6518 Spam check runs on abuse reports if the email you enter has different capitalization than the email on your account #4755

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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/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) }

Check warning on line 332 in spec/models/abuse_report_spec.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Raw Output: spec/models/abuse_report_spec.rb:332:57: C: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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
Loading