mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Merge pull request #187 from mferrier/spec-throttle-block-nil
add a spec to specify the behavior of non-matching throttle blocks
This commit is contained in:
commit
7860a82b5a
1 changed files with 22 additions and 0 deletions
|
|
@ -85,3 +85,25 @@ describe 'Rack::Attack.throttle with period as proc' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'Rack::Attack.throttle with block retuning nil' do
|
||||||
|
before do
|
||||||
|
@period = 60
|
||||||
|
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
|
||||||
|
Rack::Attack.throttle('ip/sec', :limit => 1, :period => @period) { |_| nil }
|
||||||
|
end
|
||||||
|
|
||||||
|
allow_ok_requests
|
||||||
|
|
||||||
|
describe 'a single request' do
|
||||||
|
before { get '/', {}, 'REMOTE_ADDR' => '1.2.3.4' }
|
||||||
|
it 'should not set the counter' do
|
||||||
|
key = "rack::attack:#{Time.now.to_i/@period}:ip/sec:1.2.3.4"
|
||||||
|
Rack::Attack.cache.store.read(key).must_equal nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not populate throttle data' do
|
||||||
|
last_request.env['rack.attack.throttle_data'].must_equal nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue