Autoban dmail spambots (#3408).

If a user sends spam to more than 10 users within a 24 hour window,
automatically ban them for 3 days.
This commit is contained in:
evazion
2017-12-15 15:55:27 -06:00
parent e2eb45a5a3
commit 002b5e385a
2 changed files with 43 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ require 'test_helper'
class DmailTest < ActiveSupport::TestCase
context "A dmail" do
setup do
User.any_instance.stubs(:validate_sock_puppets).returns(true)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "1.2.3.4"
@@ -27,6 +28,20 @@ class DmailTest < ActiveSupport::TestCase
assert(@recipient.dmails.last.is_spam?)
end
end
should "autoban spammers after sending spam to N distinct users" do
Dmail.any_instance.expects(:spam?).returns(true)
users = FactoryGirl.create_list(:user, Dmail::AUTOBAN_THRESHOLD)
users.each do |user|
Dmail.create_split(from: @user, to: user, title: "spam", body: "wonderful spam")
end
assert_equal(true, Dmail.is_spammer?(@user))
assert_equal(true, @user.reload.is_banned)
assert_equal(1, @user.bans.count)
assert_match(/Spambot./, @user.bans.last.reason)
end
end
context "filter" do