2013-10-11 13:33:23 -04:00
|
|
|
# encoding: UTF-8
|
2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe "spammers on same IP" do
|
2016-12-12 20:59:38 -05:00
|
|
|
let(:ip_address) { '182.189.119.174' }
|
|
|
|
let!(:spammer1) { Fabricate(:user, ip_address: ip_address) }
|
|
|
|
let!(:spammer2) { Fabricate(:user, ip_address: ip_address) }
|
|
|
|
let(:spammer3) { Fabricate(:user, ip_address: ip_address) }
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'when flag_sockpuppets is disabled' do
|
2016-12-12 20:59:38 -05:00
|
|
|
let!(:first_post) { create_post(user: spammer1) }
|
|
|
|
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2016-12-12 20:59:38 -05:00
|
|
|
it 'should not increase spam count' do
|
|
|
|
expect(first_post.reload.spam_count).to eq(0)
|
|
|
|
expect(second_post.reload.spam_count).to eq(0)
|
|
|
|
end
|
2013-10-11 13:33:23 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'when flag_sockpuppets is enabled' do
|
2016-12-12 20:59:38 -05:00
|
|
|
before do
|
|
|
|
SiteSetting.flag_sockpuppets = true
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
SiteSetting.flag_sockpuppets = false
|
|
|
|
end
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'when first spammer starts a topic' do
|
2016-12-12 20:59:38 -05:00
|
|
|
let!(:first_post) { create_post(user: spammer1) }
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'when second spammer replies' do
|
2016-12-12 20:59:38 -05:00
|
|
|
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2016-12-12 20:59:38 -05:00
|
|
|
it 'should increase spam count' do
|
|
|
|
expect(first_post.reload.spam_count).to eq(1)
|
|
|
|
expect(second_post.reload.spam_count).to eq(1)
|
|
|
|
end
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'with third spam post' do
|
2016-12-12 20:59:38 -05:00
|
|
|
let!(:third_post) { create_post(user: spammer3, topic: first_post.topic) }
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2016-12-12 20:59:38 -05:00
|
|
|
it 'should increase spam count' do
|
|
|
|
expect(first_post.reload.spam_count).to eq(1)
|
|
|
|
expect(second_post.reload.spam_count).to eq(1)
|
|
|
|
expect(third_post.reload.spam_count).to eq(1)
|
|
|
|
end
|
2013-10-11 13:33:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'when first user is not new' do
|
2016-12-12 20:59:38 -05:00
|
|
|
let!(:old_user) { Fabricate(:user, ip_address: ip_address, created_at: 2.days.ago, trust_level: TrustLevel[1]) }
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'when first user starts a topic' do
|
2016-12-12 20:59:38 -05:00
|
|
|
let!(:first_post) { create_post(user: old_user) }
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'with a reply by a new user at the same IP address' do
|
2016-12-12 20:59:38 -05:00
|
|
|
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
2013-10-11 13:33:23 -04:00
|
|
|
|
2016-12-12 20:59:38 -05:00
|
|
|
it 'should increase the spam count correctly' do
|
|
|
|
expect(first_post.reload.spam_count).to eq(0)
|
|
|
|
expect(second_post.reload.spam_count).to eq(1)
|
|
|
|
end
|
2013-10-11 13:33:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|