Merge pull request #3427 from evazion/feat-autoban-spammers
Fix #3408: More automated measures against spammers
This commit is contained in:
@@ -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"
|
||||
@@ -23,10 +24,24 @@ class DmailTest < ActiveSupport::TestCase
|
||||
|
||||
should "not validate" do
|
||||
assert_difference("Dmail.count", 2)do
|
||||
dmail = Dmail.create_split(:to_id => @recipient.id, :title => "My video", :body => "hey Noneeditsonlyme. My webcam see here http://bit.ly/2vTv9Ki")
|
||||
assert(dmail.is_spam?)
|
||||
Dmail.create_split(:to_id => @recipient.id, :title => "My video", :body => "hey Noneeditsonlyme. My webcam see here http://bit.ly/2vTv9Ki")
|
||||
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
|
||||
@@ -177,7 +192,7 @@ class DmailTest < ActiveSupport::TestCase
|
||||
context "that is automated" do
|
||||
setup do
|
||||
@bot = FactoryGirl.create(:user)
|
||||
Danbooru.config.stubs(:system_user).returns(@bot)
|
||||
User.stubs(:system).returns(@bot)
|
||||
end
|
||||
|
||||
should "only create a copy for the recipient" do
|
||||
|
||||
@@ -85,7 +85,7 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
|
||||
should "dmail the uploaders" do
|
||||
bot = FactoryGirl.create(:user)
|
||||
Danbooru.config.stubs(:system_user).returns(bot)
|
||||
User.stubs(:system).returns(bot)
|
||||
|
||||
assert_difference(["@uploaders[0].dmails.count", "@uploaders[1].dmails.count"], 1) do
|
||||
PostDisapproval.dmail_messages!
|
||||
|
||||
@@ -20,7 +20,7 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
Delayed::Worker.delay_jobs = true # don't delete the old images right away
|
||||
|
||||
@system = FactoryGirl.create(:user, created_at: 2.weeks.ago)
|
||||
Danbooru.config.stubs(:system_user).returns(@system)
|
||||
User.stubs(:system).returns(@system)
|
||||
|
||||
@uploader = FactoryGirl.create(:user, created_at: 2.weeks.ago, can_upload_free: true)
|
||||
@replacer = FactoryGirl.create(:user, created_at: 2.weeks.ago, can_approve_posts: true)
|
||||
|
||||
@@ -28,7 +28,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
should "send an automated dmail to the user" do
|
||||
bot = FactoryGirl.create(:user)
|
||||
Danbooru.config.stubs(:system_user).returns(bot)
|
||||
User.stubs(:system).returns(bot)
|
||||
|
||||
assert_difference("Dmail.count", 1) do
|
||||
@user.promote_to!(User::Levels::GOLD)
|
||||
|
||||
Reference in New Issue
Block a user