mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
* Initial Rubocop configuration * Fix Rubocop layout offenses for lib * Fix some spec offenses * Fix leftover layout offenses
This commit is contained in:
parent
f995958f18
commit
11e9557ccb
23 changed files with 63 additions and 69 deletions
5
.rubocop.yml
Normal file
5
.rubocop.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
AllCops:
|
||||
DisabledByDefault: true
|
||||
|
||||
Layout:
|
||||
Enabled: true
|
||||
|
|
@ -7,4 +7,3 @@ guard :minitest do
|
|||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||
watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ class Rack::Attack
|
|||
autoload :Allow2Ban, 'rack/attack/allow2ban'
|
||||
|
||||
class << self
|
||||
|
||||
attr_accessor :notifier, :blocklisted_response, :throttled_response
|
||||
|
||||
def safelist(name, &block)
|
||||
|
|
@ -64,8 +63,11 @@ class Rack::Attack
|
|||
end
|
||||
|
||||
def safelists; @safelists ||= {}; end
|
||||
|
||||
def blocklists; @blocklists ||= {}; end
|
||||
|
||||
def throttles; @throttles ||= {}; end
|
||||
|
||||
def tracks; @tracks ||= {}; end
|
||||
|
||||
def whitelists
|
||||
|
|
@ -126,7 +128,7 @@ class Rack::Attack
|
|||
|
||||
def blacklisted_response=(res)
|
||||
warn "[DEPRECATION] 'Rack::Attack.blacklisted_response=' is deprecated. Please use 'blocklisted_response=' instead."
|
||||
self.blocklisted_response=(res)
|
||||
self.blocklisted_response = res
|
||||
end
|
||||
|
||||
def blacklisted_response
|
||||
|
|
@ -174,8 +176,5 @@ class Rack::Attack
|
|||
end
|
||||
|
||||
extend Forwardable
|
||||
def_delegators self, :safelisted?,
|
||||
:blocklisted?,
|
||||
:throttled?,
|
||||
:tracked?
|
||||
def_delegators self, :safelisted?, :blocklisted?, :throttled?, :tracked?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ module Rack
|
|||
class Allow2Ban < Fail2Ban
|
||||
class << self
|
||||
protected
|
||||
|
||||
def key_prefix
|
||||
'allow2ban'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ module Rack
|
|||
super
|
||||
@type = :blocklist
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
module Rack
|
||||
class Attack
|
||||
class Cache
|
||||
|
||||
attr_accessor :prefix
|
||||
|
||||
def initialize
|
||||
|
|
|
|||
|
|
@ -21,4 +21,3 @@ module Rack
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ module Rack
|
|||
end
|
||||
|
||||
protected
|
||||
|
||||
def key_prefix
|
||||
'fail2ban'
|
||||
end
|
||||
|
|
@ -40,8 +41,8 @@ module Rack
|
|||
true
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def ban!(discriminator, bantime)
|
||||
cache.write("#{key_prefix}:ban:#{discriminator}", 1, bantime)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class Rack::Attack
|
||||
|
||||
# When using Rack::Attack with a Rails app, developers expect the request path
|
||||
# to be normalized. In particular, trailing slashes are stripped.
|
||||
# (See https://git.io/v0rrR for implementation.)
|
||||
|
|
@ -20,5 +19,4 @@ class Rack::Attack
|
|||
else
|
||||
FallbackPathNormalizer
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ module Rack
|
|||
super
|
||||
@type = :safelist
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ 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.
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ module Rack
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ module Rack
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
|
||||
lib = File.expand_path('../lib/', __FILE__)
|
||||
$:.unshift lib unless $:.include?(lib)
|
||||
|
||||
|
|
|
|||
|
|
@ -46,4 +46,3 @@ describe "Safelist an IP" do
|
|||
assert_equal :safelist, notification_type
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
require_relative 'spec_helper'
|
||||
|
||||
describe Rack::Attack::StoreProxy::DalliProxy do
|
||||
|
||||
it 'should stub Dalli::Client#with on older clients' do
|
||||
proxy = Rack::Attack::StoreProxy::DalliProxy.new(Class.new)
|
||||
proxy.with {} # will not raise an error
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ if RUBY_ENGINE == "ruby"
|
|||
end
|
||||
|
||||
class MiniTest::Spec
|
||||
|
||||
include Rack::Test::Methods
|
||||
|
||||
before do
|
||||
|
|
|
|||
Loading…
Reference in a new issue