From 031efcd123fa161d4733812bc2e8e01d53357464 Mon Sep 17 00:00:00 2001 From: Mike Ferrier Date: Mon, 11 Jul 2016 14:35:30 -0400 Subject: [PATCH] add a spec to specify the behavior of non-matching throttle blocks --- spec/rack_attack_throttle_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/rack_attack_throttle_spec.rb b/spec/rack_attack_throttle_spec.rb index 0c65872..d64a27d 100644 --- a/spec/rack_attack_throttle_spec.rb +++ b/spec/rack_attack_throttle_spec.rb @@ -85,3 +85,25 @@ describe 'Rack::Attack.throttle with period as proc' do 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 \ No newline at end of file