Update rubocop (#629)

* Upgrade rubocop gem

* Fix obsolete parameter

* Fix Lint/MissingSuper

* Fix Lint/ConstantDefinitionInBlock

* Fix Layout/EmptyLineBetweenDefs

* Add rubocop-minitest

* Add rubocop-rake

* Upgrade rubocop-performance
This commit is contained in:
Santiago Bartesaghi 2023-10-16 20:04:35 -03:00 committed by GitHub
parent 9a7815c332
commit e9f472786a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 28 deletions

View file

@ -1,5 +1,7 @@
require: require:
- rubocop-minitest
- rubocop-performance - rubocop-performance
- rubocop-rake
inherit_mode: inherit_mode:
merge: merge:
@ -56,7 +58,6 @@ Security:
Style/BlockDelimiters: Style/BlockDelimiters:
Enabled: true Enabled: true
IgnoredMethods: [] # Workaround rubocop bug: https://github.com/rubocop-hq/rubocop/issues/6179
Style/ClassAndModuleChildren: Style/ClassAndModuleChildren:
Enabled: true Enabled: true

View file

@ -17,8 +17,11 @@ require 'rack/attack/railtie' if defined?(::Rails)
module Rack module Rack
class Attack class Attack
class Error < StandardError; end class Error < StandardError; end
class MisconfiguredStoreError < Error; end class MisconfiguredStoreError < Error; end
class MissingStoreError < Error; end class MissingStoreError < Error; end
class IncompatibleStoreError < Error; end class IncompatibleStoreError < Error; end
autoload :Check, 'rack/attack/check' autoload :Check, 'rack/attack/check'

View file

@ -11,6 +11,7 @@ module Rack
end end
def inherited(klass) def inherited(klass)
super
proxies << klass proxies << klass
end end

View file

@ -34,8 +34,10 @@ Gem::Specification.new do |s|
s.add_development_dependency "minitest-stub-const", "~> 0.6" s.add_development_dependency "minitest-stub-const", "~> 0.6"
s.add_development_dependency 'rack-test', "~> 2.0" s.add_development_dependency 'rack-test', "~> 2.0"
s.add_development_dependency 'rake', "~> 13.0" s.add_development_dependency 'rake', "~> 13.0"
s.add_development_dependency "rubocop", "0.89.1" s.add_development_dependency "rubocop", "1.12.1"
s.add_development_dependency "rubocop-performance", "~> 1.5.0" s.add_development_dependency "rubocop-minitest", "~> 0.11.1"
s.add_development_dependency "rubocop-performance", "~> 1.10.2"
s.add_development_dependency "rubocop-rake", "~> 0.5.1"
s.add_development_dependency "timecop", "~> 0.9.1" s.add_development_dependency "timecop", "~> 0.9.1"
# byebug only works with MRI # byebug only works with MRI

View file

@ -79,7 +79,7 @@ describe "Cache store config when using fail2ban" do
end end
it "works with any object that responds to #read, #write and #increment" do it "works with any object that responds to #read, #write and #increment" do
FakeStore = Class.new do fake_store_class = Class.new do
attr_accessor :backend attr_accessor :backend
def initialize def initialize
@ -100,7 +100,7 @@ describe "Cache store config when using fail2ban" do
end end
end end
Rack::Attack.cache.store = FakeStore.new Rack::Attack.cache.store = fake_store_class.new
get "/" get "/"
assert_equal 200, last_response.status assert_equal 200, last_response.status

View file

@ -4,10 +4,8 @@ require_relative "../spec_helper"
describe "Extending the request object" do describe "Extending the request object" do
before do before do
class Rack::Attack::Request Rack::Attack::Request.define_method :authorized? do
def authorized? env["APIKey"] == "private-secret"
env["APIKey"] == "private-secret"
end
end end
Rack::Attack.blocklist("unauthorized requests") do |request| Rack::Attack.blocklist("unauthorized requests") do |request|
@ -17,9 +15,7 @@ describe "Extending the request object" do
# We don't want the extension to leak to other test cases # We don't want the extension to leak to other test cases
after do after do
class Rack::Attack::Request Rack::Attack::Request.undef_method :authorized?
remove_method :authorized?
end
end end
it "forbids request if blocklist condition is true" do it "forbids request if blocklist condition is true" do

View file

@ -5,10 +5,8 @@ require_relative 'spec_helper'
describe 'Rack::Attack' do describe 'Rack::Attack' do
describe 'helpers' do describe 'helpers' do
before do before do
class Rack::Attack::Request Rack::Attack::Request.define_method :remote_ip do
def remote_ip ip
ip
end
end end
Rack::Attack.safelist('valid IP') do |req| Rack::Attack.safelist('valid IP') do |req|

View file

@ -3,17 +3,19 @@
require_relative 'spec_helper' require_relative 'spec_helper'
describe 'Rack::Attack.track' do describe 'Rack::Attack.track' do
class Counter let(:counter_class) do
def self.incr Class.new do
@counter += 1 def self.incr
end @counter += 1
end
def self.reset def self.reset
@counter = 0 @counter = 0
end end
def self.check def self.check
@counter @counter
end
end end
end end
@ -32,19 +34,19 @@ describe 'Rack::Attack.track' do
describe "with a notification subscriber and two tracks" do describe "with a notification subscriber and two tracks" do
before do before do
Counter.reset counter_class.reset
# A second track # A second track
Rack::Attack.track("homepage") { |req| req.path == "/" } Rack::Attack.track("homepage") { |req| req.path == "/" }
ActiveSupport::Notifications.subscribe("track.rack_attack") do |*_args| ActiveSupport::Notifications.subscribe("track.rack_attack") do |*_args|
Counter.incr counter_class.incr
end end
get "/" get "/"
end end
it "should notify twice" do it "should notify twice" do
_(Counter.check).must_equal 2 _(counter_class.check).must_equal 2
end end
end end