ip bans: add hit counter, deleted flag, new ban type.
* Make IP bans soft deletable. * Add a hit counter to track how many times an IP ban has blocked someone. * Add a last hit timestamp to track when the IP ban last blocked someone. * Add a new type of IP ban, the signup ban. Signup bans restrict new signups from editing anything until they've verified their email address.
This commit is contained in:
@@ -5,18 +5,19 @@ class IpBanTest < ActiveSupport::TestCase
|
||||
ip_ban = create(:ip_ban, ip_addr: "1.2.3.4")
|
||||
|
||||
assert_equal("1.2.3.4", ip_ban.subnetted_ip)
|
||||
assert(IpBan.is_banned?("1.2.3.4"))
|
||||
assert(IpBan.ip_matches("1.2.3.4").exists?)
|
||||
end
|
||||
|
||||
should "be able to ban a subnet" do
|
||||
ip_ban = create(:ip_ban, ip_addr: "1.2.3.4/24")
|
||||
|
||||
assert_equal("1.2.3.0/24", ip_ban.subnetted_ip)
|
||||
assert(IpBan.is_banned?("1.2.3.0"))
|
||||
assert(IpBan.is_banned?("1.2.3.255"))
|
||||
assert(IpBan.ip_matches("1.2.3.0").exists?)
|
||||
assert(IpBan.ip_matches("1.2.3.255").exists?)
|
||||
end
|
||||
|
||||
context "validation" do
|
||||
setup { create(:ip_ban: ip_addr: "5.6.7.8") }
|
||||
subject { build(:ip_ban) }
|
||||
|
||||
should allow_value("1.2.3.4").for(:ip_addr)
|
||||
@@ -26,6 +27,7 @@ class IpBanTest < ActiveSupport::TestCase
|
||||
|
||||
should_not allow_value("").for(:ip_addr)
|
||||
should_not allow_value("foo").for(:ip_addr)
|
||||
should_not allow_value("5.6.7.8").for(:ip_addr)
|
||||
should_not allow_value("10.0.0.1").for(:ip_addr)
|
||||
should_not allow_value("127.0.0.1").for(:ip_addr)
|
||||
should_not allow_value("1.2.3.4/16").for(:ip_addr)
|
||||
|
||||
Reference in New Issue
Block a user