separated out ip ban logic from regular bans, users can no longer register if an ip ban is in place
This commit is contained in:
5
test/factories/ip_ban.rb
Normal file
5
test/factories/ip_ban.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
Factory.define(:ip_ban) do |f|
|
||||
f.creator {|x| x.association(:user)}
|
||||
f.reason {Faker::Lorem.words}
|
||||
f.ip_addr "127.0.0.1"
|
||||
end
|
||||
@@ -5,6 +5,7 @@ Factory.define(:user) do |f|
|
||||
f.email {Faker::Internet.email}
|
||||
f.default_image_size "medium"
|
||||
f.base_upload_limit 10
|
||||
f.ip_addr "127.0.0.1"
|
||||
end
|
||||
|
||||
Factory.define(:banned_user, :parent => :user) do |f|
|
||||
|
||||
@@ -153,18 +153,6 @@ class BanTest < ActiveSupport::TestCase
|
||||
ban = Factory.create(:ban, :user => user, :banner => admin, :duration => 1)
|
||||
assert(Ban.is_user_banned?(user))
|
||||
end
|
||||
end
|
||||
|
||||
context "by ip address" do
|
||||
should "not return expired bans" do
|
||||
admin = Factory.create(:admin_user)
|
||||
|
||||
ban = Factory.create(:ban, :ip_addr => "1.2.3.4", :banner => admin, :duration => -1)
|
||||
assert(!Ban.is_ip_banned?("1.2.3.4"))
|
||||
|
||||
ban = Factory.create(:ban, :ip_addr => "5.6.7.8", :banner => admin, :duration => 1)
|
||||
assert(Ban.is_ip_banned?("5.6.7.8"))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
4
test/unit/ip_ban_test.rb
Normal file
4
test/unit/ip_ban_test.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class IpBanTest < ActiveSupport::TestCase
|
||||
end
|
||||
@@ -6,6 +6,14 @@ class UserTest < ActiveSupport::TestCase
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
should "not validate if the originating ip address is banned" do
|
||||
Factory.create(:ip_ban)
|
||||
user = Factory.build(:user)
|
||||
user.save
|
||||
assert(user.errors.any?)
|
||||
assert_equal("IP address is banned", user.errors.full_messages.join)
|
||||
end
|
||||
|
||||
should "limit post uploads" do
|
||||
user = Factory.create(:user)
|
||||
assert(!user.can_upload?)
|
||||
|
||||
Reference in New Issue
Block a user