FEATURE: new 'maximum new user accounts per registration IP' site setting

This commit is contained in:
Régis Hanol
2014-11-17 12:04:29 +01:00
parent 78f6cea16c
commit 7641d88224
9 changed files with 67 additions and 18 deletions

View File

@@ -0,0 +1,27 @@
require "spec_helper"
require "spam_handler"
describe SpamHandler do
describe "#should_prevent_registration_from_ip?" do
it "works" do
# max_new_accounts_per_registration_ip = 0 disables the check
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(0)
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[1])
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
# only prevents registration for TL0
SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(2)
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[1])
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0])
Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[1])
-> { Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) }.should raise_error(ActiveRecord::RecordInvalid)
end
end
end

View File

@@ -2,7 +2,7 @@ require 'spec_helper'
describe AllowedIpAddressValidator do
let(:record) { Fabricate.build(:user, ip_address: '99.232.23.123') }
let(:record) { Fabricate.build(:user, trust_level: TrustLevel[0], ip_address: '99.232.23.123') }
let(:validator) { described_class.new({attributes: :ip_address}) }
subject(:validate) { validator.validate_each(record, :ip_address, record.ip_address) }
@@ -14,6 +14,14 @@ describe AllowedIpAddressValidator do
end
end
context "ip address isn't allowed for registration" do
it 'should add an error' do
SpamHandler.stubs(:should_prevent_registration_from_ip?).returns(true)
validate
record.errors[:ip_address].should be_present
end
end
context "ip address should not be blocked" do
it "shouldn't add an error" do
ScreenedIpAddress.stubs(:should_block?).returns(false)
@@ -31,4 +39,4 @@ describe AllowedIpAddressValidator do
end
end
end
end