mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Whitelisted ip addresses will not be flagged as spam by flag_sockpuppets
This commit is contained in:
parent
cc9b11ecc5
commit
8aab2253d0
4 changed files with 54 additions and 4 deletions
|
@ -25,8 +25,16 @@ class ScreenedIpAddress < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.should_block?(ip_address)
|
||||
exists_for_ip_address_and_action?(ip_address, actions[:block])
|
||||
end
|
||||
|
||||
def self.is_whitelisted?(ip_address)
|
||||
exists_for_ip_address_and_action?(ip_address, actions[:do_nothing])
|
||||
end
|
||||
|
||||
def self.exists_for_ip_address_and_action?(ip_address, action_type)
|
||||
b = match_for_ip_address(ip_address)
|
||||
b.record_match! if b
|
||||
!!b and b.action_type == actions[:block]
|
||||
!!b and b.action_type == action_type
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,7 +35,8 @@ class SpamRulesEnforcer
|
|||
!first_post.user.staff? and !@post.user.staff? and
|
||||
@post.user != first_post.user and
|
||||
@post.user.ip_address == first_post.user.ip_address and
|
||||
@post.user.new_user?
|
||||
@post.user.new_user? and
|
||||
!ScreenedIpAddress.is_whitelisted?(@post.user.ip_address)
|
||||
end
|
||||
|
||||
def flag_sockpuppet_users
|
||||
|
|
|
@ -146,4 +146,39 @@ describe ScreenedIpAddress do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#is_whitelisted?' do
|
||||
it 'returns false when record does not exist' do
|
||||
described_class.is_whitelisted?(ip_address).should eq(false)
|
||||
end
|
||||
|
||||
it 'returns false when no record matches' do
|
||||
Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:do_nothing])
|
||||
described_class.is_whitelisted?('222.12.12.12').should eq(false)
|
||||
end
|
||||
|
||||
context 'IPv4' do
|
||||
it 'returns true when when record matches and action is :do_nothing' do
|
||||
Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:do_nothing])
|
||||
described_class.is_whitelisted?('111.234.23.11').should eq(true)
|
||||
end
|
||||
|
||||
it 'returns false when when record matches and action is :block' do
|
||||
Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:block])
|
||||
described_class.is_whitelisted?('111.234.23.11').should eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'IPv6' do
|
||||
it 'returns true when when record matches and action is :do_nothing' do
|
||||
Fabricate(:screened_ip_address, ip_address: '2001:db8::ff00:42:8329', action_type: described_class.actions[:do_nothing])
|
||||
described_class.is_whitelisted?('2001:db8::ff00:42:8329').should eq(true)
|
||||
end
|
||||
|
||||
it 'returns false when when record matches and action is :block' do
|
||||
Fabricate(:screened_ip_address, ip_address: '2001:db8::ff00:42:8329', action_type: described_class.actions[:block])
|
||||
described_class.is_whitelisted?('2001:db8::ff00:42:8329').should eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,11 +20,17 @@ describe SpamRulesEnforcer do
|
|||
SpamRulesEnforcer.new(post2).reply_is_from_sockpuppet?.should eq(false)
|
||||
end
|
||||
|
||||
it 'is true if users have the same IP address' do
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: '182.189.119.174'), topic: post1.topic)
|
||||
it 'is true if users have the same IP address and are new' do
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: user1.ip_address), topic: post1.topic)
|
||||
SpamRulesEnforcer.new(post2).reply_is_from_sockpuppet?.should eq(true)
|
||||
end
|
||||
|
||||
it 'is false if the ip address is whitelisted' do
|
||||
ScreenedIpAddress.stubs(:is_whitelisted?).with(user1.ip_address).returns(true)
|
||||
post2 = Fabricate(:post, user: Fabricate(:user, ip_address: user1.ip_address), topic: post1.topic)
|
||||
SpamRulesEnforcer.new(post2).reply_is_from_sockpuppet?.should eq(false)
|
||||
end
|
||||
|
||||
it 'is false if reply and first post are from the same user' do
|
||||
post2 = Fabricate(:post, user: user1, topic: post1.topic)
|
||||
SpamRulesEnforcer.new(post2).reply_is_from_sockpuppet?.should eq(false)
|
||||
|
|
Loading…
Reference in a new issue