mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: new 'maximum new user accounts per registration IP' site setting
This commit is contained in:
27
spec/components/spam_handler_spec.rb
Normal file
27
spec/components/spam_handler_spec.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user