Skip to content

Commit

Permalink
Update rubocop (#629)
Browse files Browse the repository at this point in the history
* Upgrade rubocop gem

* Fix obsolete parameter

* Fix Lint/MissingSuper

* Fix Lint/ConstantDefinitionInBlock

* Fix Layout/EmptyLineBetweenDefs

* Add rubocop-minitest

* Add rubocop-rake

* Upgrade rubocop-performance
  • Loading branch information
santib authored Oct 16, 2023
1 parent 9a7815c commit e9f4727
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require:
- rubocop-minitest
- rubocop-performance
- rubocop-rake

inherit_mode:
merge:
Expand Down Expand Up @@ -56,7 +58,6 @@ Security:

Style/BlockDelimiters:
Enabled: true
IgnoredMethods: [] # Workaround rubocop bug: https://github.com/rubocop-hq/rubocop/issues/6179

Style/ClassAndModuleChildren:
Enabled: true
Expand Down
3 changes: 3 additions & 0 deletions lib/rack/attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
module Rack
class Attack
class Error < StandardError; end

class MisconfiguredStoreError < Error; end

class MissingStoreError < Error; end

class IncompatibleStoreError < Error; end

autoload :Check, 'rack/attack/check'
Expand Down
1 change: 1 addition & 0 deletions lib/rack/attack/base_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def proxies
end

def inherited(klass)
super
proxies << klass
end

Expand Down
6 changes: 4 additions & 2 deletions rack-attack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ Gem::Specification.new do |s|
s.add_development_dependency "minitest-stub-const", "~> 0.6"
s.add_development_dependency 'rack-test', "~> 2.0"
s.add_development_dependency 'rake', "~> 13.0"
s.add_development_dependency "rubocop", "0.89.1"
s.add_development_dependency "rubocop-performance", "~> 1.5.0"
s.add_development_dependency "rubocop", "1.12.1"
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"

# byebug only works with MRI
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/cache_store_config_for_fail2ban_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def write(key, value); end
end

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

def initialize
Expand All @@ -100,7 +100,7 @@ def increment(key, _count, _options = {})
end
end

Rack::Attack.cache.store = FakeStore.new
Rack::Attack.cache.store = fake_store_class.new

get "/"
assert_equal 200, last_response.status
Expand Down
10 changes: 3 additions & 7 deletions spec/acceptance/extending_request_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

describe "Extending the request object" do
before do
class Rack::Attack::Request
def authorized?
env["APIKey"] == "private-secret"
end
Rack::Attack::Request.define_method :authorized? do
env["APIKey"] == "private-secret"
end

Rack::Attack.blocklist("unauthorized requests") do |request|
Expand All @@ -17,9 +15,7 @@ def authorized?

# We don't want the extension to leak to other test cases
after do
class Rack::Attack::Request
remove_method :authorized?
end
Rack::Attack::Request.undef_method :authorized?
end

it "forbids request if blocklist condition is true" do
Expand Down
6 changes: 2 additions & 4 deletions spec/rack_attack_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
describe 'Rack::Attack' do
describe 'helpers' do
before do
class Rack::Attack::Request
def remote_ip
ip
end
Rack::Attack::Request.define_method :remote_ip do
ip
end

Rack::Attack.safelist('valid IP') do |req|
Expand Down
26 changes: 14 additions & 12 deletions spec/rack_attack_track_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
require_relative 'spec_helper'

describe 'Rack::Attack.track' do
class Counter
def self.incr
@counter += 1
end
let(:counter_class) do
Class.new do
def self.incr
@counter += 1
end

def self.reset
@counter = 0
end
def self.reset
@counter = 0
end

def self.check
@counter
def self.check
@counter
end
end
end

Expand All @@ -32,19 +34,19 @@ def self.check

describe "with a notification subscriber and two tracks" do
before do
Counter.reset
counter_class.reset
# A second track
Rack::Attack.track("homepage") { |req| req.path == "/" }

ActiveSupport::Notifications.subscribe("track.rack_attack") do |*_args|
Counter.incr
counter_class.incr
end

get "/"
end

it "should notify twice" do
_(Counter.check).must_equal 2
_(counter_class.check).must_equal 2
end
end

Expand Down

0 comments on commit e9f4727

Please sign in to comment.