From 79f5eff68b21b604ef14ed78e137f38173a940c4 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Tue, 2 Jun 2015 15:06:45 +0530 Subject: [PATCH] FIX: do not block registration for whitelisted IP address --- lib/spam_handler.rb | 3 +++ spec/components/spam_handler_spec.rb | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/spam_handler.rb b/lib/spam_handler.rb index 6fc184e74..b14532c27 100644 --- a/lib/spam_handler.rb +++ b/lib/spam_handler.rb @@ -16,6 +16,9 @@ class SpamHandler return false if staff_members_with_same_ip > 0 + ip_whitelisted = ScreenedIpAddress.is_whitelisted?(ip_address) + return false if ip_whitelisted + tl0_accounts_with_same_ip = User.unscoped .where(trust_level: TrustLevel[0]) .where(ip_address: ip_address.to_s) diff --git a/spec/components/spam_handler_spec.rb b/spec/components/spam_handler_spec.rb index 325932b9d..bde8f0b2b 100644 --- a/spec/components/spam_handler_spec.rb +++ b/spec/components/spam_handler_spec.rb @@ -46,6 +46,17 @@ describe SpamHandler do Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) end + it "doesn't limit registrations when the IP is whitelisted" do + # setup + SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(0) + Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) + ScreenedIpAddress.stubs(:is_whitelisted?).with("42.42.42.42").returns(true) + + # should not limit registration + SiteSetting.stubs(:max_new_accounts_per_registration_ip).returns(1) + Fabricate(:user, ip_address: "42.42.42.42", trust_level: TrustLevel[0]) + end + end end