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{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||||
watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
|
watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ class Rack::Attack
|
||||||
autoload :Allow2Ban, 'rack/attack/allow2ban'
|
autoload :Allow2Ban, 'rack/attack/allow2ban'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
attr_accessor :notifier, :blocklisted_response, :throttled_response
|
attr_accessor :notifier, :blocklisted_response, :throttled_response
|
||||||
|
|
||||||
def safelist(name, &block)
|
def safelist(name, &block)
|
||||||
|
|
@ -64,8 +63,11 @@ class Rack::Attack
|
||||||
end
|
end
|
||||||
|
|
||||||
def safelists; @safelists ||= {}; end
|
def safelists; @safelists ||= {}; end
|
||||||
|
|
||||||
def blocklists; @blocklists ||= {}; end
|
def blocklists; @blocklists ||= {}; end
|
||||||
|
|
||||||
def throttles; @throttles ||= {}; end
|
def throttles; @throttles ||= {}; end
|
||||||
|
|
||||||
def tracks; @tracks ||= {}; end
|
def tracks; @tracks ||= {}; end
|
||||||
|
|
||||||
def whitelists
|
def whitelists
|
||||||
|
|
@ -126,7 +128,7 @@ class Rack::Attack
|
||||||
|
|
||||||
def blacklisted_response=(res)
|
def blacklisted_response=(res)
|
||||||
warn "[DEPRECATION] 'Rack::Attack.blacklisted_response=' is deprecated. Please use 'blocklisted_response=' instead."
|
warn "[DEPRECATION] 'Rack::Attack.blacklisted_response=' is deprecated. Please use 'blocklisted_response=' instead."
|
||||||
self.blocklisted_response=(res)
|
self.blocklisted_response = res
|
||||||
end
|
end
|
||||||
|
|
||||||
def blacklisted_response
|
def blacklisted_response
|
||||||
|
|
@ -174,8 +176,5 @@ class Rack::Attack
|
||||||
end
|
end
|
||||||
|
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
def_delegators self, :safelisted?,
|
def_delegators self, :safelisted?, :blocklisted?, :throttled?, :tracked?
|
||||||
:blocklisted?,
|
|
||||||
:throttled?,
|
|
||||||
:tracked?
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ module Rack
|
||||||
class Allow2Ban < Fail2Ban
|
class Allow2Ban < Fail2Ban
|
||||||
class << self
|
class << self
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def key_prefix
|
def key_prefix
|
||||||
'allow2ban'
|
'allow2ban'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ module Rack
|
||||||
super
|
super
|
||||||
@type = :blocklist
|
@type = :blocklist
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
module Rack
|
module Rack
|
||||||
class Attack
|
class Attack
|
||||||
class Cache
|
class Cache
|
||||||
|
|
||||||
attr_accessor :prefix
|
attr_accessor :prefix
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,3 @@ module Rack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ module Rack
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def key_prefix
|
def key_prefix
|
||||||
'fail2ban'
|
'fail2ban'
|
||||||
end
|
end
|
||||||
|
|
@ -40,8 +41,8 @@ module Rack
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def ban!(discriminator, bantime)
|
def ban!(discriminator, bantime)
|
||||||
cache.write("#{key_prefix}:ban:#{discriminator}", 1, bantime)
|
cache.write("#{key_prefix}:ban:#{discriminator}", 1, bantime)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
class Rack::Attack
|
class Rack::Attack
|
||||||
|
|
||||||
# When using Rack::Attack with a Rails app, developers expect the request path
|
# When using Rack::Attack with a Rails app, developers expect the request path
|
||||||
# to be normalized. In particular, trailing slashes are stripped.
|
# to be normalized. In particular, trailing slashes are stripped.
|
||||||
# (See https://git.io/v0rrR for implementation.)
|
# (See https://git.io/v0rrR for implementation.)
|
||||||
|
|
@ -20,5 +19,4 @@ class Rack::Attack
|
||||||
else
|
else
|
||||||
FallbackPathNormalizer
|
FallbackPathNormalizer
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ module Rack
|
||||||
super
|
super
|
||||||
@type = :safelist
|
@type = :safelist
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ module Rack
|
||||||
klass ? klass.new(client) : client
|
klass ? klass.new(client) : client
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.unwrap_active_support_stores(store)
|
def self.unwrap_active_support_stores(store)
|
||||||
# ActiveSupport::Cache::RedisStore doesn't expose any way to set an expiry,
|
# ActiveSupport::Cache::RedisStore doesn't expose any way to set an expiry,
|
||||||
# so use the raw Redis::Store instead.
|
# so use the raw Redis::Store instead.
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ module Rack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ module Rack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
lib = File.expand_path('../lib/', __FILE__)
|
lib = File.expand_path('../lib/', __FILE__)
|
||||||
$:.unshift lib unless $:.include?(lib)
|
$:.unshift lib unless $:.include?(lib)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,4 +46,3 @@ describe "Safelist an IP" do
|
||||||
assert_equal :safelist, notification_type
|
assert_equal :safelist, notification_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
require_relative 'spec_helper'
|
require_relative 'spec_helper'
|
||||||
|
|
||||||
describe Rack::Attack::StoreProxy::DalliProxy do
|
describe Rack::Attack::StoreProxy::DalliProxy do
|
||||||
|
|
||||||
it 'should stub Dalli::Client#with on older clients' do
|
it 'should stub Dalli::Client#with on older clients' do
|
||||||
proxy = Rack::Attack::StoreProxy::DalliProxy.new(Class.new)
|
proxy = Rack::Attack::StoreProxy::DalliProxy.new(Class.new)
|
||||||
proxy.with {} # will not raise an error
|
proxy.with {} # will not raise an error
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ if RUBY_ENGINE == "ruby"
|
||||||
end
|
end
|
||||||
|
|
||||||
class MiniTest::Spec
|
class MiniTest::Spec
|
||||||
|
|
||||||
include Rack::Test::Methods
|
include Rack::Test::Methods
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue