From 273e045f10c402d2d208ee585a3d651db1fb67cb Mon Sep 17 00:00:00 2001 From: Jordan Moncharmont Date: Fri, 27 Sep 2013 17:35:01 -0700 Subject: [PATCH] fix edge case, if maxretry is 1, let them get 1 request in --- lib/rack/attack/allow2ban.rb | 5 ++--- spec/allow2ban_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/rack/attack/allow2ban.rb b/lib/rack/attack/allow2ban.rb index 7feb91a..f5772c8 100644 --- a/lib/rack/attack/allow2ban.rb +++ b/lib/rack/attack/allow2ban.rb @@ -13,10 +13,9 @@ module Rack count = cache.count("#{key_prefix}:count:#{discriminator}", findtime) if count >= maxretry ban!(discriminator, bantime) - true - else - false end + # we may not block them this time, but they're banned for next time + false end end end diff --git a/spec/allow2ban_spec.rb b/spec/allow2ban_spec.rb index 14c7648..569c213 100644 --- a/spec/allow2ban_spec.rb +++ b/spec/allow2ban_spec.rb @@ -45,8 +45,8 @@ describe 'Rack::Attack.Allow2Ban' do get '/?foo=OMGHAX', {}, 'REMOTE_ADDR' => '1.2.3.4' end - it 'fails' do - last_response.status.must_equal 401 + it 'succeeds' do + last_response.status.must_equal 200 end it 'increases fail count' do