mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Enable Lint rubocop cops
This commit is contained in:
parent
d01c3e61d4
commit
52ec80692d
13 changed files with 27 additions and 19 deletions
10
.rubocop.yml
10
.rubocop.yml
|
|
@ -1,6 +1,8 @@
|
|||
AllCops:
|
||||
TargetRubyVersion: 2.2
|
||||
DisabledByDefault: true
|
||||
Exclude:
|
||||
- "examples/instrumentation.rb"
|
||||
|
||||
Bundler:
|
||||
Enabled: true
|
||||
|
|
@ -16,3 +18,11 @@ Performance:
|
|||
|
||||
Security:
|
||||
Enabled: true
|
||||
|
||||
Lint:
|
||||
Enabled: true
|
||||
|
||||
# TODO
|
||||
# Remove cop disabling and fix offenses
|
||||
Lint/HandleExceptions:
|
||||
Enabled: false
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class Rack::Attack
|
|||
end
|
||||
|
||||
def throttled?(req)
|
||||
throttles.any? do |name, throttle|
|
||||
throttles.any? do |_name, throttle|
|
||||
throttle[req]
|
||||
end
|
||||
end
|
||||
|
|
@ -149,7 +149,7 @@ class Rack::Attack
|
|||
|
||||
# Set defaults
|
||||
@notifier = ActiveSupport::Notifications if defined?(ActiveSupport::Notifications)
|
||||
@blocklisted_response = lambda { |env| [403, { 'Content-Type' => 'text/plain' }, ["Forbidden\n"]] }
|
||||
@blocklisted_response = lambda { |_env| [403, { 'Content-Type' => 'text/plain' }, ["Forbidden\n"]] }
|
||||
@throttled_response = lambda { |env|
|
||||
retry_after = (env['rack.attack.match_data'] || {})[:period]
|
||||
[429, { 'Content-Type' => 'text/plain', 'Retry-After' => retry_after.to_s }, ["Retry later\n"]]
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ module Rack
|
|||
klass ? klass.new(client) : client
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.unwrap_active_support_stores(store)
|
||||
# ActiveSupport::Cache::RedisStore doesn't expose any way to set an expiry,
|
||||
# so use the raw Redis::Store instead.
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ module Rack
|
|||
rescue MemCache::MemCacheError
|
||||
end
|
||||
|
||||
def increment(key, amount, options = {})
|
||||
def increment(key, amount, _options = {})
|
||||
incr(key, amount)
|
||||
rescue MemCache::MemCacheError
|
||||
end
|
||||
|
||||
def delete(key, options = {})
|
||||
def delete(key, _options = {})
|
||||
with do |client|
|
||||
client.delete(key)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ module Rack
|
|||
rescue Redis::BaseError
|
||||
end
|
||||
|
||||
def delete(key, options = {})
|
||||
def delete(key, _options = {})
|
||||
del(key)
|
||||
rescue Redis::BaseError
|
||||
end
|
||||
|
|
|
|||
|
|
@ -81,11 +81,11 @@ describe "Cache store config when using allow2ban" do
|
|||
@backend[key]
|
||||
end
|
||||
|
||||
def write(key, value, options = {})
|
||||
def write(key, value, _options = {})
|
||||
@backend[key] = value
|
||||
end
|
||||
|
||||
def increment(key, count, options = {})
|
||||
def increment(key, _count, _options = {})
|
||||
@backend[key] ||= 0
|
||||
@backend[key] += 1
|
||||
end
|
||||
|
|
|
|||
|
|
@ -81,11 +81,11 @@ describe "Cache store config when using fail2ban" do
|
|||
@backend[key]
|
||||
end
|
||||
|
||||
def write(key, value, options = {})
|
||||
def write(key, value, _options = {})
|
||||
@backend[key] = value
|
||||
end
|
||||
|
||||
def increment(key, count, options = {})
|
||||
def increment(key, _count, _options = {})
|
||||
@backend[key] ||= 0
|
||||
@backend[key] += 1
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ describe "Cache store config when throttling without Rails" do
|
|||
@counts = {}
|
||||
end
|
||||
|
||||
def increment(key, count, options)
|
||||
def increment(key, _count, _options)
|
||||
@counts[key] ||= 0
|
||||
@counts[key] += 1
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ describe "Customizing block responses" do
|
|||
|
||||
assert_equal 403, last_response.status
|
||||
|
||||
Rack::Attack.blocklisted_response = lambda do |env|
|
||||
Rack::Attack.blocklisted_response = lambda do |_env|
|
||||
[503, {}, ["Blocked"]]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ describe "Customizing throttled response" do
|
|||
|
||||
assert_equal 429, last_response.status
|
||||
|
||||
Rack::Attack.throttled_response = lambda do |env|
|
||||
Rack::Attack.throttled_response = lambda do |_env|
|
||||
[503, {}, ["Throttled"]]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ describe 'Rack::Attack.throttle with limit as proc' do
|
|||
before do
|
||||
@period = 60 # Use a long period; failures due to cache key rotation less likely
|
||||
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
|
||||
Rack::Attack.throttle('ip/sec', :limit => lambda { |req| 1 }, :period => @period) { |req| req.ip }
|
||||
Rack::Attack.throttle('ip/sec', :limit => lambda { |_req| 1 }, :period => @period) { |req| req.ip }
|
||||
end
|
||||
|
||||
it_allows_ok_requests
|
||||
|
|
@ -75,7 +75,7 @@ describe 'Rack::Attack.throttle with period as proc' do
|
|||
before do
|
||||
@period = 60 # Use a long period; failures due to cache key rotation less likely
|
||||
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
|
||||
Rack::Attack.throttle('ip/sec', :limit => lambda { |req| 1 }, :period => lambda { |req| @period }) { |req| req.ip }
|
||||
Rack::Attack.throttle('ip/sec', :limit => lambda { |_req| 1 }, :period => lambda { |_req| @period }) { |req| req.ip }
|
||||
end
|
||||
|
||||
it_allows_ok_requests
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ describe 'Rack::Attack.track' do
|
|||
end
|
||||
|
||||
before do
|
||||
Rack::Attack.track("everything") { |req| true }
|
||||
Rack::Attack.track("everything") { |_req| true }
|
||||
end
|
||||
|
||||
it_allows_ok_requests
|
||||
|
|
@ -33,7 +33,7 @@ describe 'Rack::Attack.track' do
|
|||
# A second track
|
||||
Rack::Attack.track("homepage") { |req| req.path == "/" }
|
||||
|
||||
ActiveSupport::Notifications.subscribe("rack.attack") do |*args|
|
||||
ActiveSupport::Notifications.subscribe("rack.attack") do |*_args|
|
||||
Counter.incr
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class MiniTest::Spec
|
|||
use Rack::Attack
|
||||
use Rack::Lint
|
||||
|
||||
run lambda { |env| [200, {}, ['Hello World']] }
|
||||
run lambda { |_env| [200, {}, ['Hello World']] }
|
||||
}.to_app
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue