mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
commit
f2a3a25e98
6 changed files with 39 additions and 9 deletions
27
.rubocop.yml
27
.rubocop.yml
|
|
@ -1,8 +1,18 @@
|
|||
inherit_mode:
|
||||
merge:
|
||||
- Exclude
|
||||
|
||||
AllCops:
|
||||
TargetRubyVersion: 2.2
|
||||
DisabledByDefault: true
|
||||
Exclude:
|
||||
- "examples/instrumentation.rb"
|
||||
# Remove the following line once we are able to make bundler install gems to <PROJECT_ROOT>/vendor/bundle instead
|
||||
# of <PROJECT_ROOT>/gemfiles/vendor/bundle during TravisCI builds. The reason that happens for now is because
|
||||
# bundler 1.x only installs relative to the Gemfile (which during CI builds is always one inside gemfiles/ folder)
|
||||
# instead of the CWD. Bundler 2.x will add support to install relative to CWD
|
||||
# (see https://github.com/bundler/bundler/pull/5803).
|
||||
- "gemfiles/vendor/**/*"
|
||||
|
||||
Bundler:
|
||||
Enabled: true
|
||||
|
|
@ -13,6 +23,14 @@ Gemspec:
|
|||
Layout:
|
||||
Enabled: true
|
||||
|
||||
Lint:
|
||||
Enabled: true
|
||||
|
||||
Naming:
|
||||
Enabled: true
|
||||
Exclude:
|
||||
- "lib/rack/attack/path_normalizer.rb"
|
||||
|
||||
Performance:
|
||||
Enabled: true
|
||||
|
||||
|
|
@ -22,6 +40,15 @@ Security:
|
|||
Lint:
|
||||
Enabled: true
|
||||
|
||||
Style/BracesAroundHashParameters:
|
||||
Enabled: true
|
||||
|
||||
Style/FrozenStringLiteralComment:
|
||||
Enabled: true
|
||||
|
||||
Style/RedundantFreeze:
|
||||
Enabled: true
|
||||
|
||||
# TODO
|
||||
# Remove cop disabling and fix offenses
|
||||
Lint/HandleExceptions:
|
||||
|
|
|
|||
5
Rakefile
5
Rakefile
|
|
@ -2,6 +2,9 @@ require "rubygems"
|
|||
require "bundler/setup"
|
||||
require 'bundler/gem_tasks'
|
||||
require 'rake/testtask'
|
||||
require "rubocop/rake_task"
|
||||
|
||||
RuboCop::RakeTask.new
|
||||
|
||||
namespace :test do
|
||||
Rake::TestTask.new(:units) do |t|
|
||||
|
|
@ -20,4 +23,4 @@ end
|
|||
desc 'Run tests'
|
||||
task :test => %w[test:units test:integration test:acceptance]
|
||||
|
||||
task :default => :test
|
||||
task :default => [:rubocop, :test]
|
||||
|
|
|
|||
|
|
@ -38,15 +38,15 @@ class Rack::Attack
|
|||
self.blocklists[name] = Blocklist.new(name, block)
|
||||
end
|
||||
|
||||
def blocklist_ip(ip)
|
||||
def blocklist_ip(ip_address)
|
||||
@ip_blocklists ||= []
|
||||
ip_blocklist_proc = lambda { |request| IPAddr.new(ip).include?(IPAddr.new(request.ip)) }
|
||||
ip_blocklist_proc = lambda { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) }
|
||||
@ip_blocklists << Blocklist.new(nil, ip_blocklist_proc)
|
||||
end
|
||||
|
||||
def safelist_ip(ip)
|
||||
def safelist_ip(ip_address)
|
||||
@ip_safelists ||= []
|
||||
ip_safelist_proc = lambda { |request| IPAddr.new(ip).include?(IPAddr.new(request.ip)) }
|
||||
ip_safelist_proc = lambda { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) }
|
||||
@ip_safelists << Safelist.new(nil, ip_safelist_proc)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ module Rack
|
|||
end
|
||||
|
||||
def read(name, options = {})
|
||||
super(name, options.merge!({ raw: true }))
|
||||
super(name, options.merge!(raw: true))
|
||||
end
|
||||
|
||||
def write(name, value, options = {})
|
||||
super(name, value, options.merge!({ raw: true }))
|
||||
super(name, value, options.merge!(raw: true))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency 'rack-test'
|
||||
s.add_development_dependency 'rake'
|
||||
s.add_development_dependency 'redis-activesupport'
|
||||
s.add_development_dependency "rubocop", "0.55.0"
|
||||
s.add_development_dependency "rubocop", "0.57.2"
|
||||
s.add_development_dependency "timecop"
|
||||
|
||||
# Need to explicitly depend on guard because guard-minitest doesn't declare
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ describe 'Rack::Attack.throttle' do
|
|||
it 'should tag the env' do
|
||||
last_request.env['rack.attack.matched'].must_equal 'ip/sec'
|
||||
last_request.env['rack.attack.match_type'].must_equal :throttle
|
||||
last_request.env['rack.attack.match_data'].must_equal({ :count => 2, :limit => 1, :period => @period })
|
||||
last_request.env['rack.attack.match_data'].must_equal(:count => 2, :limit => 1, :period => @period)
|
||||
last_request.env['rack.attack.match_discriminator'].must_equal('1.2.3.4')
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue