spam detection: whitelist users more than 1 month old.

This commit is contained in:
evazion
2019-10-01 21:49:53 -05:00
parent ed7b6c781a
commit 5d90256b24
2 changed files with 11 additions and 1 deletions

View File

@@ -52,6 +52,7 @@ class SpamDetector
def spam?
return false if !SpamDetector.enabled?
return false if user.is_gold?
return false if user.created_at < 1.month.ago
is_spam = super

View File

@@ -7,7 +7,7 @@ class SpamDetectorTest < ActiveSupport::TestCase
SpamDetector.stubs(:enabled?).returns(true)
@user = create(:gold_user, created_at: 1.month.ago)
@spammer = create(:user, created_at: 1.month.ago, email: "akismet-guaranteed-spam@example.com")
@spammer = create(:user, created_at: 2.weeks.ago, email: "akismet-guaranteed-spam@example.com")
end
context "for dmails" do
@@ -27,6 +27,15 @@ class SpamDetectorTest < ActiveSupport::TestCase
refute(dmail.is_spam?)
end
should "not detect old users as spammers" do
@spammer.update!(created_at: 2.months.ago)
Dmail.create_split(from: @user, to: @spammer, title: "spam", body: "wonderful spam", creator_ip_addr: "127.0.0.1")
dmail = @spammer.dmails.last
refute(SpamDetector.new(dmail).spam?)
refute(dmail.is_spam?)
end
should "log a message when spam is detected" do
Rails.logger.expects(:info)
Dmail.create_split(from: @spammer, to: @user, title: "spam", body: "wonderful spam", creator_ip_addr: "127.0.0.1")