diff --git a/.rubocop.yml b/.rubocop.yml index c38c69a..fc88c1c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -37,6 +37,7 @@ Security: Style/BlockDelimiters: Enabled: true + IgnoredMethods: [] # Workaround rubocop bug: https://github.com/rubocop-hq/rubocop/issues/6179 Style/BracesAroundHashParameters: Enabled: true diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index f875033..bc54a82 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -138,10 +138,10 @@ module Rack @anonymous_safelists = [] @notifier = ActiveSupport::Notifications if defined?(ActiveSupport::Notifications) @blocklisted_response = lambda { |_env| [403, { 'Content-Type' => 'text/plain' }, ["Forbidden\n"]] } - @throttled_response = lambda { |env| + @throttled_response = lambda do |env| retry_after = (env['rack.attack.match_data'] || {})[:period] [429, { 'Content-Type' => 'text/plain', 'Retry-After' => retry_after.to_s }, ["Retry later\n"]] - } + end def initialize(app) @app = app diff --git a/spec/acceptance/stores/active_support_mem_cache_store_pooled_spec.rb b/spec/acceptance/stores/active_support_mem_cache_store_pooled_spec.rb index c477380..8344b6e 100644 --- a/spec/acceptance/stores/active_support_mem_cache_store_pooled_spec.rb +++ b/spec/acceptance/stores/active_support_mem_cache_store_pooled_spec.rb @@ -15,8 +15,6 @@ if defined?(::ConnectionPool) && defined?(::Dalli) Rack::Attack.cache.store.clear end - it_works_for_cache_backed_features(fetch_from_store: ->(key) { - Rack::Attack.cache.store.read(key) - }) + it_works_for_cache_backed_features(fetch_from_store: ->(key) { Rack::Attack.cache.store.read(key) }) end end diff --git a/spec/acceptance/stores/connection_pool_dalli_client_spec.rb b/spec/acceptance/stores/connection_pool_dalli_client_spec.rb index 5689fbd..d532a29 100644 --- a/spec/acceptance/stores/connection_pool_dalli_client_spec.rb +++ b/spec/acceptance/stores/connection_pool_dalli_client_spec.rb @@ -17,8 +17,8 @@ if defined?(::Dalli) && defined?(::ConnectionPool) Rack::Attack.cache.store.with { |client| client.flush_all } end - it_works_for_cache_backed_features(fetch_from_store: ->(key) { - Rack::Attack.cache.store.with { |client| client.fetch(key) } - }) + it_works_for_cache_backed_features( + fetch_from_store: ->(key) { Rack::Attack.cache.store.with { |client| client.fetch(key) } } + ) end end diff --git a/spec/rack_attack_spec.rb b/spec/rack_attack_spec.rb index d99e89d..39a0928 100644 --- a/spec/rack_attack_spec.rb +++ b/spec/rack_attack_spec.rb @@ -22,9 +22,9 @@ describe 'Rack::Attack' do Rack::Attack.blocklist("ip #{@bad_ip}") { |req| req.ip == @bad_ip } end - it('has a blocklist') { + it 'has a blocklist' do Rack::Attack.blocklists.key?("ip #{@bad_ip}").must_equal true - } + end describe "a bad request" do before { get '/', {}, 'REMOTE_ADDR' => @bad_ip }