Merge pull request #408 from grzuy/style

style: prefer ruby 1.9+ hash syntax
This commit is contained in:
Gonzalo Rodriguez 2019-02-28 21:07:20 -03:00 committed by GitHub
commit bf4e902407
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 23 additions and 20 deletions

View file

@ -44,6 +44,9 @@ Style/BracesAroundHashParameters:
Style/FrozenStringLiteralComment:
Enabled: true
Style/HashSyntax:
Enabled: true
Style/RedundantFreeze:
Enabled: true

View file

@ -26,4 +26,4 @@ Rake::TestTask.new(:test) do |t|
t.pattern = "spec/**/*_spec.rb"
end
task :default => [:rubocop, :test]
task default: [:rubocop, :test]

View file

@ -29,7 +29,7 @@ module Rack
end
def write(unprefixed_key, value, expires_in)
store.write("#{prefix}:#{unprefixed_key}", value, :expires_in => expires_in)
store.write("#{prefix}:#{unprefixed_key}", value, expires_in: expires_in)
end
def reset_count(unprefixed_key, period)
@ -54,13 +54,13 @@ module Rack
enforce_store_presence!
enforce_store_method_presence!(:increment)
result = store.increment(key, 1, :expires_in => expires_in)
result = store.increment(key, 1, expires_in: expires_in)
# NB: Some stores return nil when incrementing uninitialized values
if result.nil?
enforce_store_method_presence!(:write)
store.write(key, 1, :expires_in => expires_in)
store.write(key, 1, expires_in: expires_in)
end
result || 1
end

View file

@ -31,10 +31,10 @@ module Rack
epoch_time = cache.last_epoch_time
data = {
:count => count,
:period => current_period,
:limit => current_limit,
:epoch_time => epoch_time
count: count,
period: current_period,
limit: current_limit,
epoch_time: epoch_time
}
(request.env['rack.attack.throttle_data'] ||= {})[name] = data

View file

@ -9,7 +9,7 @@ describe 'Rack::Attack.Allow2Ban' do
@findtime = 60
@bantime = 60
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
@f2b_options = { :bantime => @bantime, :findtime => @findtime, :maxretry => 2 }
@f2b_options = { bantime: @bantime, findtime: @findtime, maxretry: 2 }
Rack::Attack.blocklist('pentest') do |req|
Rack::Attack::Allow2Ban.filter(req.ip, @f2b_options) { req.query_string =~ /OMGHAX/ }

View file

@ -9,7 +9,7 @@ describe 'Rack::Attack.Fail2Ban' do
@findtime = 60
@bantime = 60
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
@f2b_options = { :bantime => @bantime, :findtime => @findtime, :maxretry => 2 }
@f2b_options = { bantime: @bantime, findtime: @findtime, maxretry: 2 }
Rack::Attack.blocklist('pentest') do |req|
Rack::Attack::Fail2Ban.filter(req.ip, @f2b_options) { req.query_string =~ /OMGHAX/ }

View file

@ -24,7 +24,7 @@ if defined?(::ActiveSupport::Cache::RedisStore)
before do
@cache = Rack::Attack::Cache.new
# Use presumably unused port for Redis client
@cache.store = ActiveSupport::Cache::RedisStore.new(:host => '127.0.0.1', :port => 3333)
@cache.store = ActiveSupport::Cache::RedisStore.new(host: '127.0.0.1', port: 3333)
end
end
end

View file

@ -6,7 +6,7 @@ describe 'Rack::Attack.throttle' 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 => 1, :period => @period) { |req| req.ip }
Rack::Attack.throttle('ip/sec', limit: 1, period: @period) { |req| req.ip }
end
it('should have a throttle') { Rack::Attack.throttles.key?('ip/sec') }
@ -22,7 +22,7 @@ describe 'Rack::Attack.throttle' do
end
it 'should populate throttle data' do
data = { :count => 1, :limit => 1, :period => @period, epoch_time: Rack::Attack.cache.last_epoch_time.to_i }
data = { count: 1, limit: 1, period: @period, epoch_time: Rack::Attack.cache.last_epoch_time.to_i }
last_request.env['rack.attack.throttle_data']['ip/sec'].must_equal data
end
end
@ -39,7 +39,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, epoch_time: Rack::Attack.cache.last_epoch_time.to_i)
last_request.env['rack.attack.match_data'].must_equal(count: 2, limit: 1, period: @period, epoch_time: Rack::Attack.cache.last_epoch_time.to_i)
last_request.env['rack.attack.match_discriminator'].must_equal('1.2.3.4')
end
@ -53,7 +53,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
@ -67,7 +67,7 @@ describe 'Rack::Attack.throttle with limit as proc' do
end
it 'should populate throttle data' do
data = { :count => 1, :limit => 1, :period => @period, epoch_time: Rack::Attack.cache.last_epoch_time.to_i }
data = { count: 1, limit: 1, period: @period, epoch_time: Rack::Attack.cache.last_epoch_time.to_i }
last_request.env['rack.attack.throttle_data']['ip/sec'].must_equal data
end
end
@ -77,7 +77,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
@ -91,7 +91,7 @@ describe 'Rack::Attack.throttle with period as proc' do
end
it 'should populate throttle data' do
data = { :count => 1, :limit => 1, :period => @period, epoch_time: Rack::Attack.cache.last_epoch_time.to_i }
data = { count: 1, limit: 1, period: @period, epoch_time: Rack::Attack.cache.last_epoch_time.to_i }
last_request.env['rack.attack.throttle_data']['ip/sec'].must_equal data
end
end
@ -101,7 +101,7 @@ describe 'Rack::Attack.throttle with block retuning nil' do
before do
@period = 60
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
Rack::Attack.throttle('ip/sec', :limit => 1, :period => @period) { |_| nil }
Rack::Attack.throttle('ip/sec', limit: 1, period: @period) { |_| nil }
end
it_allows_ok_requests

View file

@ -56,7 +56,7 @@ describe 'Rack::Attack.track' do
describe "with limit and period options" do
it "should assign the track filter to a Throttle instance" do
track = Rack::Attack.track("homepage", :limit => 10, :period => 10) { |req| req.path == "/" }
track = Rack::Attack.track("homepage", limit: 10, period: 10) { |req| req.path == "/" }
track.filter.class.must_equal Rack::Attack::Throttle
end
end