From c9bd363a69faedaf0590be6ba191db46db387a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=A4ppler?= Date: Thu, 24 Aug 2023 13:46:14 +0200 Subject: [PATCH 01/10] Add Ruby 3.2.2 to CI build matrix, update older Rubies (#622) * Add Ruby 3.2.2 to CI build matrix * CI: Update older Rubies to latest versions --- .github/workflows/build.yml | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 18e768ae..4047aeab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,9 +17,10 @@ jobs: strategy: matrix: ruby: - - 3.1.2 - - 3.0.4 - - 2.7.6 + - 3.2.2 + - 3.1.4 + - 3.0.6 + - 2.7.8 - 2.6.10 - 2.5.8 gemfile: @@ -42,25 +43,33 @@ jobs: - active_support_redis_store exclude: - gemfile: rack_1 - ruby: 3.1.2 + ruby: 3.2.2 - gemfile: rails_5_2 - ruby: 3.1.2 + ruby: 3.2.2 - gemfile: rails_4_2 - ruby: 3.1.2 + ruby: 3.2.2 - gemfile: dalli2 - ruby: 3.1.2 + ruby: 3.2.2 - gemfile: rack_1 - ruby: 3.0.4 + ruby: 3.1.4 - gemfile: rails_5_2 - ruby: 3.0.4 + ruby: 3.1.4 - gemfile: rails_4_2 - ruby: 3.0.4 + ruby: 3.1.4 - gemfile: dalli2 - ruby: 3.0.4 + ruby: 3.1.4 - gemfile: rack_1 - ruby: 2.7.6 + ruby: 3.0.6 + - gemfile: rails_5_2 + ruby: 3.0.6 + - gemfile: rails_4_2 + ruby: 3.0.6 + - gemfile: dalli2 + ruby: 3.0.6 + - gemfile: rack_1 + ruby: 2.7.8 - gemfile: rails_4_2 - ruby: 2.7.6 + ruby: 2.7.8 - gemfile: rails_7_0 ruby: 2.6.10 - gemfile: rails_7_0 From 9a7815c3322670fcc850bb7661e107eaa573f49a Mon Sep 17 00:00:00 2001 From: Mitchell Henke Date: Sat, 14 Oct 2023 09:29:19 -0500 Subject: [PATCH 02/10] Remove support for unmaintained ActiveSupport::Cache::RedisStore (#625) * remove support for unmaintained ActiveSupport::Cache::RedisStore * ci: removes active_support_redis_store matrix job * test: removes unecessary redis-activesupport require * test: removes dead code * fix typo --------- Co-authored-by: Gonzalo <456459+grzuy@users.noreply.github.com> --- .github/workflows/build.yml | 1 - Appraisals | 5 --- gemfiles/active_support_redis_store.gemfile | 8 ---- lib/rack/attack.rb | 1 - .../active_support_redis_store_proxy.rb | 39 ------------------- .../stores/active_support_redis_store_spec.rb | 20 ---------- spec/acceptance/stores/redis_store_spec.rb | 2 +- spec/integration/offline_spec.rb | 12 ------ spec/spec_helper.rb | 1 - 9 files changed, 1 insertion(+), 88 deletions(-) delete mode 100644 gemfiles/active_support_redis_store.gemfile delete mode 100644 lib/rack/attack/store_proxy/active_support_redis_store_proxy.rb delete mode 100644 spec/acceptance/stores/active_support_redis_store_spec.rb diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4047aeab..7afda9ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,6 @@ jobs: - active_support_redis_cache_store - active_support_redis_cache_store_pooled - redis_store - - active_support_redis_store exclude: - gemfile: rack_1 ruby: 3.2.2 diff --git a/Appraisals b/Appraisals index 2d270527..4f222a0f 100644 --- a/Appraisals +++ b/Appraisals @@ -80,8 +80,3 @@ end appraise "redis_store" do gem "redis-store", "~> 1.5" end - -appraise "active_support_redis_store" do - gem "redis-activesupport", "~> 5.0" - gem 'redis-store', '1.9.1' # remove after https://github.com/redis-store/redis-store/issues/358 is resolved -end diff --git a/gemfiles/active_support_redis_store.gemfile b/gemfiles/active_support_redis_store.gemfile deleted file mode 100644 index b3567fa3..00000000 --- a/gemfiles/active_support_redis_store.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "redis-activesupport", "~> 5.0" -gem "redis-store", "1.9.1" - -gemspec path: "../" diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index 9b134165..b3488ba2 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -11,7 +11,6 @@ require 'rack/attack/store_proxy/redis_proxy' require 'rack/attack/store_proxy/redis_store_proxy' require 'rack/attack/store_proxy/redis_cache_store_proxy' -require 'rack/attack/store_proxy/active_support_redis_store_proxy' require 'rack/attack/railtie' if defined?(::Rails) diff --git a/lib/rack/attack/store_proxy/active_support_redis_store_proxy.rb b/lib/rack/attack/store_proxy/active_support_redis_store_proxy.rb deleted file mode 100644 index d2c0e3b2..00000000 --- a/lib/rack/attack/store_proxy/active_support_redis_store_proxy.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -require 'rack/attack/base_proxy' - -module Rack - class Attack - module StoreProxy - class ActiveSupportRedisStoreProxy < BaseProxy - def self.handle?(store) - defined?(::Redis) && - defined?(::ActiveSupport::Cache::RedisStore) && - store.is_a?(::ActiveSupport::Cache::RedisStore) - end - - def increment(name, amount = 1, options = {}) - # #increment ignores options[:expires_in]. - # - # So in order to workaround this we use #write (which sets expiration) to initialize - # the counter. After that we continue using the original #increment. - if options[:expires_in] && !read(name) - write(name, amount, options) - - amount - else - super - end - end - - def read(name, options = {}) - super(name, options.merge!(raw: true)) - end - - def write(name, value, options = {}) - super(name, value, options.merge!(raw: true)) - end - end - end - end -end diff --git a/spec/acceptance/stores/active_support_redis_store_spec.rb b/spec/acceptance/stores/active_support_redis_store_spec.rb deleted file mode 100644 index 75e4d68d..00000000 --- a/spec/acceptance/stores/active_support_redis_store_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require_relative "../../spec_helper" - -if defined?(::ActiveSupport::Cache::RedisStore) - require_relative "../../support/cache_store_helper" - require "timecop" - - describe "ActiveSupport::Cache::RedisStore as a cache backend" do - before do - Rack::Attack.cache.store = ActiveSupport::Cache::RedisStore.new - end - - after do - Rack::Attack.cache.store.clear - end - - it_works_for_cache_backed_features(fetch_from_store: ->(key) { Rack::Attack.cache.store.read(key) }) - end -end diff --git a/spec/acceptance/stores/redis_store_spec.rb b/spec/acceptance/stores/redis_store_spec.rb index d7e8e115..dee35bcf 100644 --- a/spec/acceptance/stores/redis_store_spec.rb +++ b/spec/acceptance/stores/redis_store_spec.rb @@ -6,7 +6,7 @@ if defined?(::Redis::Store) require "timecop" - describe "ActiveSupport::Cache::RedisStore as a cache backend" do + describe "Redis::Store as a cache backend" do before do Rack::Attack.cache.store = ::Redis::Store.new end diff --git a/spec/integration/offline_spec.rb b/spec/integration/offline_spec.rb index d4960633..85429a42 100644 --- a/spec/integration/offline_spec.rb +++ b/spec/integration/offline_spec.rb @@ -21,18 +21,6 @@ end end -if defined?(::ActiveSupport::Cache::RedisStore) - describe 'when Redis is offline' do - include OfflineExamples - - 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) - end - end -end - if defined?(Redis) && defined?(ActiveSupport::Cache::RedisCacheStore) && Redis::VERSION >= '4' describe 'when Redis is offline' do include OfflineExamples diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5cd8d888..f529e6a1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,7 +21,6 @@ def safe_require(name) safe_require "connection_pool" safe_require "dalli" safe_require "redis" -safe_require "redis-activesupport" safe_require "redis-store" class Minitest::Spec From e9f472786afbfc3acb1b8646cf157a45863e4d9b Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Mon, 16 Oct 2023 20:04:35 -0300 Subject: [PATCH 03/10] 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 --- .rubocop.yml | 3 ++- lib/rack/attack.rb | 3 +++ lib/rack/attack/base_proxy.rb | 1 + rack-attack.gemspec | 6 +++-- .../cache_store_config_for_fail2ban_spec.rb | 4 +-- .../extending_request_object_spec.rb | 10 +++---- spec/rack_attack_request_spec.rb | 6 ++--- spec/rack_attack_track_spec.rb | 26 ++++++++++--------- 8 files changed, 31 insertions(+), 28 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 745bb907..865fea87 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,7 @@ require: + - rubocop-minitest - rubocop-performance + - rubocop-rake inherit_mode: merge: @@ -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 diff --git a/lib/rack/attack.rb b/lib/rack/attack.rb index b3488ba2..c9094b21 100644 --- a/lib/rack/attack.rb +++ b/lib/rack/attack.rb @@ -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' diff --git a/lib/rack/attack/base_proxy.rb b/lib/rack/attack/base_proxy.rb index 3e3c28af..f10af3d4 100644 --- a/lib/rack/attack/base_proxy.rb +++ b/lib/rack/attack/base_proxy.rb @@ -11,6 +11,7 @@ def proxies end def inherited(klass) + super proxies << klass end diff --git a/rack-attack.gemspec b/rack-attack.gemspec index 1cfe2b9f..41cc7a8f 100644 --- a/rack-attack.gemspec +++ b/rack-attack.gemspec @@ -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 diff --git a/spec/acceptance/cache_store_config_for_fail2ban_spec.rb b/spec/acceptance/cache_store_config_for_fail2ban_spec.rb index 6f330eee..6fd79807 100644 --- a/spec/acceptance/cache_store_config_for_fail2ban_spec.rb +++ b/spec/acceptance/cache_store_config_for_fail2ban_spec.rb @@ -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 @@ -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 diff --git a/spec/acceptance/extending_request_object_spec.rb b/spec/acceptance/extending_request_object_spec.rb index a4ea1a62..5449b90c 100644 --- a/spec/acceptance/extending_request_object_spec.rb +++ b/spec/acceptance/extending_request_object_spec.rb @@ -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| @@ -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 diff --git a/spec/rack_attack_request_spec.rb b/spec/rack_attack_request_spec.rb index 8d4d27fc..8f27301a 100644 --- a/spec/rack_attack_request_spec.rb +++ b/spec/rack_attack_request_spec.rb @@ -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| diff --git a/spec/rack_attack_track_spec.rb b/spec/rack_attack_track_spec.rb index 0db66e47..d8c53b8a 100644 --- a/spec/rack_attack_track_spec.rb +++ b/spec/rack_attack_track_spec.rb @@ -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 @@ -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 From 3543f61b640555f161b6d7f76fdbd622ead32dd3 Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Tue, 17 Oct 2023 21:19:29 -0300 Subject: [PATCH 04/10] Fix #588 don't fail if request.ip is missing (#630) * Fix #588 don't fail if request.ip is missing * Fix Rails 4 suite * Improve tests --------- Co-authored-by: Gonzalo <456459+grzuy@users.noreply.github.com> --- lib/rack/attack/configuration.rb | 8 ++++++-- spec/acceptance/blocking_ip_spec.rb | 6 ++++++ spec/acceptance/safelisting_ip_spec.rb | 6 ++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/rack/attack/configuration.rb b/lib/rack/attack/configuration.rb index c90fdee6..a4bdc987 100644 --- a/lib/rack/attack/configuration.rb +++ b/lib/rack/attack/configuration.rb @@ -61,11 +61,15 @@ def blocklist(name = nil, &block) end def blocklist_ip(ip_address) - @anonymous_blocklists << Blocklist.new { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) } + @anonymous_blocklists << Blocklist.new do |request| + request.ip && !request.ip.empty? && IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) + end end def safelist_ip(ip_address) - @anonymous_safelists << Safelist.new { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) } + @anonymous_safelists << Safelist.new do |request| + request.ip && !request.ip.empty? && IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) + end end def throttle(name, options, &block) diff --git a/spec/acceptance/blocking_ip_spec.rb b/spec/acceptance/blocking_ip_spec.rb index 102a8fce..4d08042f 100644 --- a/spec/acceptance/blocking_ip_spec.rb +++ b/spec/acceptance/blocking_ip_spec.rb @@ -19,6 +19,12 @@ assert_equal 200, last_response.status end + it "succeeds if IP is missing" do + get "/", {}, "REMOTE_ADDR" => "" + + assert_equal 200, last_response.status + end + it "notifies when the request is blocked" do notified = false notification_type = nil diff --git a/spec/acceptance/safelisting_ip_spec.rb b/spec/acceptance/safelisting_ip_spec.rb index c0b8faf5..fd80dc1b 100644 --- a/spec/acceptance/safelisting_ip_spec.rb +++ b/spec/acceptance/safelisting_ip_spec.rb @@ -17,6 +17,12 @@ assert_equal 403, last_response.status end + it "forbids request if blocklist condition is true and safelist is false (missing IP)" do + get "/admin", {}, "REMOTE_ADDR" => "" + + assert_equal 403, last_response.status + end + it "succeeds if blocklist condition is false and safelist is false" do get "/", {}, "REMOTE_ADDR" => "1.2.3.4" From 8d77a5b0f1fac27951e7977c899092b1a84af891 Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Wed, 18 Oct 2023 21:50:23 -0300 Subject: [PATCH 05/10] Add Rails 7.1 to CI (#631) --- .github/workflows/build.yml | 5 +++++ Appraisals | 4 ++++ gemfiles/rails_7_1.gemfile | 7 +++++++ 3 files changed, 16 insertions(+) create mode 100644 gemfiles/rails_7_1.gemfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7afda9ae..46d67464 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,6 +27,7 @@ jobs: - rack_3 - rack_2 - rack_1 + - rails_7_1 - rails_7_0 - rails_6_1 - rails_6_0 @@ -73,6 +74,10 @@ jobs: ruby: 2.6.10 - gemfile: rails_7_0 ruby: 2.5.8 + - gemfile: rails_7_1 + ruby: 2.6.10 + - gemfile: rails_7_1 + ruby: 2.5.8 env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile steps: diff --git a/Appraisals b/Appraisals index 4f222a0f..fe499170 100644 --- a/Appraisals +++ b/Appraisals @@ -21,6 +21,10 @@ appraise "rack_1" do gem "rack-test", ">= 0.6" end +appraise 'rails_7-1' do + gem 'railties', '~> 7.1.0' +end + appraise 'rails_7-0' do gem 'railties', '~> 7.0.0' end diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile new file mode 100644 index 00000000..036d9836 --- /dev/null +++ b/gemfiles/rails_7_1.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "railties", "~> 7.1.0" + +gemspec path: "../" From 070e467ef220a4566abed7dc4c64c278d66b812f Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Tue, 24 Oct 2023 19:14:27 -0300 Subject: [PATCH 06/10] ci: test against ActiveSupport::RedisCacheStore v5 (#632) --- .github/workflows/build.yml | 14 ++++++++++++++ Appraisals | 11 +++++++++++ .../active_support_5_redis_cache_store.gemfile | 13 +++++++++++++ ...tive_support_5_redis_cache_store_pooled.gemfile | 14 ++++++++++++++ gemfiles/active_support_redis_cache_store.gemfile | 5 +++++ ...active_support_redis_cache_store_pooled.gemfile | 5 +++++ gemfiles/connection_pool_dalli.gemfile | 5 +++++ gemfiles/dalli2.gemfile | 5 +++++ gemfiles/dalli3.gemfile | 5 +++++ gemfiles/rack_1.gemfile | 5 +++++ gemfiles/rack_2.gemfile | 6 +++++- gemfiles/rack_3.gemfile | 5 +++++ gemfiles/rails_4_2.gemfile | 5 +++++ gemfiles/rails_5_2.gemfile | 5 +++++ gemfiles/rails_6_0.gemfile | 5 +++++ gemfiles/rails_6_1.gemfile | 5 +++++ gemfiles/rails_7_0.gemfile | 5 +++++ gemfiles/rails_7_1.gemfile | 5 +++++ gemfiles/redis_4.gemfile | 5 +++++ gemfiles/redis_5.gemfile | 5 +++++ gemfiles/redis_store.gemfile | 5 +++++ 21 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 gemfiles/active_support_5_redis_cache_store.gemfile create mode 100644 gemfiles/active_support_5_redis_cache_store_pooled.gemfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 46d67464..6ca20631 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,12 +40,18 @@ jobs: - connection_pool_dalli - active_support_redis_cache_store - active_support_redis_cache_store_pooled + - active_support_5_redis_cache_store + - active_support_5_redis_cache_store_pooled - redis_store exclude: - gemfile: rack_1 ruby: 3.2.2 - gemfile: rails_5_2 ruby: 3.2.2 + - gemfile: active_support_5_redis_cache_store + ruby: 3.2.2 + - gemfile: active_support_5_redis_cache_store_pooled + ruby: 3.2.2 - gemfile: rails_4_2 ruby: 3.2.2 - gemfile: dalli2 @@ -54,6 +60,10 @@ jobs: ruby: 3.1.4 - gemfile: rails_5_2 ruby: 3.1.4 + - gemfile: active_support_5_redis_cache_store + ruby: 3.1.4 + - gemfile: active_support_5_redis_cache_store_pooled + ruby: 3.1.4 - gemfile: rails_4_2 ruby: 3.1.4 - gemfile: dalli2 @@ -62,6 +72,10 @@ jobs: ruby: 3.0.6 - gemfile: rails_5_2 ruby: 3.0.6 + - gemfile: active_support_5_redis_cache_store + ruby: 3.0.6 + - gemfile: active_support_5_redis_cache_store_pooled + ruby: 3.0.6 - gemfile: rails_4_2 ruby: 3.0.6 - gemfile: dalli2 diff --git a/Appraisals b/Appraisals index fe499170..89062b53 100644 --- a/Appraisals +++ b/Appraisals @@ -81,6 +81,17 @@ appraise "active_support_redis_cache_store_pooled" do gem "redis", "~> 5.0" end +appraise "active_support_5_redis_cache_store" do + gem "activesupport", "~> 5.2.0" + gem "redis", "~> 5.0" +end + +appraise "active_support_5_redis_cache_store_pooled" do + gem "activesupport", "~> 5.2.0" + gem "connection_pool", "~> 2.2" + gem "redis", "~> 5.0" +end + appraise "redis_store" do gem "redis-store", "~> 1.5" end diff --git a/gemfiles/active_support_5_redis_cache_store.gemfile b/gemfiles/active_support_5_redis_cache_store.gemfile new file mode 100644 index 00000000..0b800a0f --- /dev/null +++ b/gemfiles/active_support_5_redis_cache_store.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 5.2.0" +gem "redis", "~> 5.0" + +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + +gemspec path: "../" diff --git a/gemfiles/active_support_5_redis_cache_store_pooled.gemfile b/gemfiles/active_support_5_redis_cache_store_pooled.gemfile new file mode 100644 index 00000000..9127da50 --- /dev/null +++ b/gemfiles/active_support_5_redis_cache_store_pooled.gemfile @@ -0,0 +1,14 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 5.2.0" +gem "connection_pool", "~> 2.2" +gem "redis", "~> 5.0" + +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + +gemspec path: "../" diff --git a/gemfiles/active_support_redis_cache_store.gemfile b/gemfiles/active_support_redis_cache_store.gemfile index 21a16e7d..72fb5b1d 100644 --- a/gemfiles/active_support_redis_cache_store.gemfile +++ b/gemfiles/active_support_redis_cache_store.gemfile @@ -5,4 +5,9 @@ source "https://rubygems.org" gem "activesupport", "~> 6.1.0" gem "redis", "~> 5.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/active_support_redis_cache_store_pooled.gemfile b/gemfiles/active_support_redis_cache_store_pooled.gemfile index f74738f2..36a40f57 100644 --- a/gemfiles/active_support_redis_cache_store_pooled.gemfile +++ b/gemfiles/active_support_redis_cache_store_pooled.gemfile @@ -6,4 +6,9 @@ gem "activesupport", "~> 6.1.0" gem "connection_pool", "~> 2.2" gem "redis", "~> 5.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/connection_pool_dalli.gemfile b/gemfiles/connection_pool_dalli.gemfile index 67c69a59..f84eb52e 100644 --- a/gemfiles/connection_pool_dalli.gemfile +++ b/gemfiles/connection_pool_dalli.gemfile @@ -5,4 +5,9 @@ source "https://rubygems.org" gem "connection_pool", "~> 2.2" gem "dalli", "~> 3.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/dalli2.gemfile b/gemfiles/dalli2.gemfile index c47d5afa..eb7e4acb 100644 --- a/gemfiles/dalli2.gemfile +++ b/gemfiles/dalli2.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "dalli", "~> 2.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/dalli3.gemfile b/gemfiles/dalli3.gemfile index 5f4d073b..3873dedf 100644 --- a/gemfiles/dalli3.gemfile +++ b/gemfiles/dalli3.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "dalli", "~> 3.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/rack_1.gemfile b/gemfiles/rack_1.gemfile index 2390b859..36b2f91b 100644 --- a/gemfiles/rack_1.gemfile +++ b/gemfiles/rack_1.gemfile @@ -7,4 +7,9 @@ gem "activesupport", ">= 4.2" gem "rack", "~> 1.6" gem "rack-test", ">= 0.6" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/rack_2.gemfile b/gemfiles/rack_2.gemfile index 41b64ab4..246c981a 100644 --- a/gemfiles/rack_2.gemfile +++ b/gemfiles/rack_2.gemfile @@ -3,6 +3,10 @@ source "https://rubygems.org" gem "rack", "~> 2.0" -gem "railties" + +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end gemspec path: "../" diff --git a/gemfiles/rack_3.gemfile b/gemfiles/rack_3.gemfile index 24e3a766..f0735014 100644 --- a/gemfiles/rack_3.gemfile +++ b/gemfiles/rack_3.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "rack", "~> 3.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/rails_4_2.gemfile b/gemfiles/rails_4_2.gemfile index 055cf9f6..4209e6dc 100644 --- a/gemfiles/rails_4_2.gemfile +++ b/gemfiles/rails_4_2.gemfile @@ -5,4 +5,9 @@ source "https://rubygems.org" gem "railties", "~> 4.2.0" gem "rack-test", ">= 0.6" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/rails_5_2.gemfile b/gemfiles/rails_5_2.gemfile index 8b2627fc..161bb698 100644 --- a/gemfiles/rails_5_2.gemfile +++ b/gemfiles/rails_5_2.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "railties", "~> 5.2.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/rails_6_0.gemfile b/gemfiles/rails_6_0.gemfile index 4cd55a81..679fea78 100644 --- a/gemfiles/rails_6_0.gemfile +++ b/gemfiles/rails_6_0.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "railties", "~> 6.0.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/rails_6_1.gemfile b/gemfiles/rails_6_1.gemfile index 4c467fec..b1e5c039 100644 --- a/gemfiles/rails_6_1.gemfile +++ b/gemfiles/rails_6_1.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "railties", "~> 6.1.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile index 495c72d0..6f490fff 100644 --- a/gemfiles/rails_7_0.gemfile +++ b/gemfiles/rails_7_0.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "railties", "~> 7.0.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile index 036d9836..fdfb546f 100644 --- a/gemfiles/rails_7_1.gemfile +++ b/gemfiles/rails_7_1.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "railties", "~> 7.1.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/redis_4.gemfile b/gemfiles/redis_4.gemfile index 701e936c..e8b82f16 100644 --- a/gemfiles/redis_4.gemfile +++ b/gemfiles/redis_4.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "redis", "~> 4.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/redis_5.gemfile b/gemfiles/redis_5.gemfile index 0aac1021..fc9b4655 100644 --- a/gemfiles/redis_5.gemfile +++ b/gemfiles/redis_5.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "redis", "~> 5.0" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" diff --git a/gemfiles/redis_store.gemfile b/gemfiles/redis_store.gemfile index 8aafc6d1..e32d1e9e 100644 --- a/gemfiles/redis_store.gemfile +++ b/gemfiles/redis_store.gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" gem "redis-store", "~> 1.5" +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + gemspec path: "../" From c7098d610b7ba5e2f868eac4d9425889095a5611 Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Wed, 25 Oct 2023 21:15:53 -0300 Subject: [PATCH 07/10] ci: improve ActiveSupport testing (#633) --- .github/workflows/build.yml | 24 +++++++++++++++-- Appraisals | 26 +++++++++++++++++-- ...ctive_support_6_redis_cache_store.gemfile} | 0 ...upport_6_redis_cache_store_pooled.gemfile} | 0 ...tive_support_7_0_redis_cache_store.gemfile | 13 ++++++++++ ...pport_7_0_redis_cache_store_pooled.gemfile | 14 ++++++++++ ...tive_support_7_1_redis_cache_store.gemfile | 13 ++++++++++ ...pport_7_1_redis_cache_store_pooled.gemfile | 14 ++++++++++ 8 files changed, 100 insertions(+), 4 deletions(-) rename gemfiles/{active_support_redis_cache_store.gemfile => active_support_6_redis_cache_store.gemfile} (100%) rename gemfiles/{active_support_redis_cache_store_pooled.gemfile => active_support_6_redis_cache_store_pooled.gemfile} (100%) create mode 100644 gemfiles/active_support_7_0_redis_cache_store.gemfile create mode 100644 gemfiles/active_support_7_0_redis_cache_store_pooled.gemfile create mode 100644 gemfiles/active_support_7_1_redis_cache_store.gemfile create mode 100644 gemfiles/active_support_7_1_redis_cache_store_pooled.gemfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6ca20631..cc3200cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,8 +38,12 @@ jobs: - redis_5 - redis_4 - connection_pool_dalli - - active_support_redis_cache_store - - active_support_redis_cache_store_pooled + - active_support_7_1_redis_cache_store + - active_support_7_1_redis_cache_store_pooled + - active_support_7_0_redis_cache_store + - active_support_7_0_redis_cache_store_pooled + - active_support_6_redis_cache_store + - active_support_6_redis_cache_store_pooled - active_support_5_redis_cache_store - active_support_5_redis_cache_store_pooled - redis_store @@ -88,10 +92,26 @@ jobs: ruby: 2.6.10 - gemfile: rails_7_0 ruby: 2.5.8 + - gemfile: active_support_7_0_redis_cache_store + ruby: 2.5.8 + - gemfile: active_support_7_0_redis_cache_store + ruby: 2.6.10 + - gemfile: active_support_7_0_redis_cache_store_pooled + ruby: 2.5.8 + - gemfile: active_support_7_0_redis_cache_store_pooled + ruby: 2.6.10 - gemfile: rails_7_1 ruby: 2.6.10 - gemfile: rails_7_1 ruby: 2.5.8 + - gemfile: active_support_7_1_redis_cache_store + ruby: 2.5.8 + - gemfile: active_support_7_1_redis_cache_store + ruby: 2.6.10 + - gemfile: active_support_7_1_redis_cache_store_pooled + ruby: 2.5.8 + - gemfile: active_support_7_1_redis_cache_store_pooled + ruby: 2.6.10 env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile steps: diff --git a/Appraisals b/Appraisals index 89062b53..185740dc 100644 --- a/Appraisals +++ b/Appraisals @@ -70,12 +70,34 @@ appraise "connection_pool_dalli" do gem "dalli", "~> 3.0" end -appraise "active_support_redis_cache_store" do +appraise "active_support_7-1_redis_cache_store" do + gem "activesupport", "~> 7.1.0" + gem "redis", "~> 5.0" +end + +appraise "active_support_7-1_redis_cache_store_pooled" do + gem "activesupport", "~> 7.1.0" + gem "connection_pool", "~> 2.2" + gem "redis", "~> 5.0" +end + +appraise "active_support_7-0_redis_cache_store" do + gem "activesupport", "~> 7.0.0" + gem "redis", "~> 5.0" +end + +appraise "active_support_7-0_redis_cache_store_pooled" do + gem "activesupport", "~> 7.0.0" + gem "connection_pool", "~> 2.2" + gem "redis", "~> 5.0" +end + +appraise "active_support_6_redis_cache_store" do gem "activesupport", "~> 6.1.0" gem "redis", "~> 5.0" end -appraise "active_support_redis_cache_store_pooled" do +appraise "active_support_6_redis_cache_store_pooled" do gem "activesupport", "~> 6.1.0" gem "connection_pool", "~> 2.2" gem "redis", "~> 5.0" diff --git a/gemfiles/active_support_redis_cache_store.gemfile b/gemfiles/active_support_6_redis_cache_store.gemfile similarity index 100% rename from gemfiles/active_support_redis_cache_store.gemfile rename to gemfiles/active_support_6_redis_cache_store.gemfile diff --git a/gemfiles/active_support_redis_cache_store_pooled.gemfile b/gemfiles/active_support_6_redis_cache_store_pooled.gemfile similarity index 100% rename from gemfiles/active_support_redis_cache_store_pooled.gemfile rename to gemfiles/active_support_6_redis_cache_store_pooled.gemfile diff --git a/gemfiles/active_support_7_0_redis_cache_store.gemfile b/gemfiles/active_support_7_0_redis_cache_store.gemfile new file mode 100644 index 00000000..a94cfe88 --- /dev/null +++ b/gemfiles/active_support_7_0_redis_cache_store.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 7.0.0" +gem "redis", "~> 5.0" + +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + +gemspec path: "../" diff --git a/gemfiles/active_support_7_0_redis_cache_store_pooled.gemfile b/gemfiles/active_support_7_0_redis_cache_store_pooled.gemfile new file mode 100644 index 00000000..bd2a6e71 --- /dev/null +++ b/gemfiles/active_support_7_0_redis_cache_store_pooled.gemfile @@ -0,0 +1,14 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 7.0.0" +gem "connection_pool", "~> 2.2" +gem "redis", "~> 5.0" + +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + +gemspec path: "../" diff --git a/gemfiles/active_support_7_1_redis_cache_store.gemfile b/gemfiles/active_support_7_1_redis_cache_store.gemfile new file mode 100644 index 00000000..a0602ba5 --- /dev/null +++ b/gemfiles/active_support_7_1_redis_cache_store.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 7.1.0" +gem "redis", "~> 5.0" + +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + +gemspec path: "../" diff --git a/gemfiles/active_support_7_1_redis_cache_store_pooled.gemfile b/gemfiles/active_support_7_1_redis_cache_store_pooled.gemfile new file mode 100644 index 00000000..ae2d6d96 --- /dev/null +++ b/gemfiles/active_support_7_1_redis_cache_store_pooled.gemfile @@ -0,0 +1,14 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activesupport", "~> 7.1.0" +gem "connection_pool", "~> 2.2" +gem "redis", "~> 5.0" + +group :maintenance, optional: true do + gem "bake" + gem "bake-gem" +end + +gemspec path: "../" From 36b830ab3ca8622f6e1acafcca1245ec0f75f1fd Mon Sep 17 00:00:00 2001 From: Gonzalo <456459+grzuy@users.noreply.github.com> Date: Wed, 25 Oct 2023 23:37:16 -0300 Subject: [PATCH 08/10] ci: update tested rails versions (#626) --- .github/workflows/build.yml | 9 ---- Appraisals | 8 ---- gemfiles/rails_4_2.gemfile | 13 ------ spec/rack_attack_instrumentation_spec.rb | 52 +++++++++++------------- 4 files changed, 24 insertions(+), 58 deletions(-) delete mode 100644 gemfiles/rails_4_2.gemfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cc3200cc..3237bd4d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,7 +32,6 @@ jobs: - rails_6_1 - rails_6_0 - rails_5_2 - - rails_4_2 - dalli3 - dalli2 - redis_5 @@ -56,8 +55,6 @@ jobs: ruby: 3.2.2 - gemfile: active_support_5_redis_cache_store_pooled ruby: 3.2.2 - - gemfile: rails_4_2 - ruby: 3.2.2 - gemfile: dalli2 ruby: 3.2.2 - gemfile: rack_1 @@ -68,8 +65,6 @@ jobs: ruby: 3.1.4 - gemfile: active_support_5_redis_cache_store_pooled ruby: 3.1.4 - - gemfile: rails_4_2 - ruby: 3.1.4 - gemfile: dalli2 ruby: 3.1.4 - gemfile: rack_1 @@ -80,14 +75,10 @@ jobs: ruby: 3.0.6 - gemfile: active_support_5_redis_cache_store_pooled ruby: 3.0.6 - - gemfile: rails_4_2 - ruby: 3.0.6 - gemfile: dalli2 ruby: 3.0.6 - gemfile: rack_1 ruby: 2.7.8 - - gemfile: rails_4_2 - ruby: 2.7.8 - gemfile: rails_7_0 ruby: 2.6.10 - gemfile: rails_7_0 diff --git a/Appraisals b/Appraisals index 185740dc..f68e8b7f 100644 --- a/Appraisals +++ b/Appraisals @@ -41,14 +41,6 @@ appraise 'rails_5-2' do gem 'railties', '~> 5.2.0' end -appraise 'rails_4-2' do - gem 'railties', '~> 4.2.0' - - # Override rack-test version constraint by making it more loose - # so it's compatible with actionpack 4.2.x - gem "rack-test", ">= 0.6" -end - appraise 'dalli2' do gem 'dalli', '~> 2.0' end diff --git a/gemfiles/rails_4_2.gemfile b/gemfiles/rails_4_2.gemfile deleted file mode 100644 index 4209e6dc..00000000 --- a/gemfiles/rails_4_2.gemfile +++ /dev/null @@ -1,13 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "railties", "~> 4.2.0" -gem "rack-test", ">= 0.6" - -group :maintenance, optional: true do - gem "bake" - gem "bake-gem" -end - -gemspec path: "../" diff --git a/spec/rack_attack_instrumentation_spec.rb b/spec/rack_attack_instrumentation_spec.rb index 111ad148..d2291f77 100644 --- a/spec/rack_attack_instrumentation_spec.rb +++ b/spec/rack_attack_instrumentation_spec.rb @@ -2,42 +2,38 @@ require_relative "spec_helper" require 'active_support' +require 'active_support/subscriber' -# ActiveSupport::Subscribers added in ~> 4.0.2.0 -if ActiveSupport::VERSION::MAJOR > 3 - require_relative 'spec_helper' - require 'active_support/subscriber' - class CustomSubscriber < ActiveSupport::Subscriber - @notification_count = 0 +class CustomSubscriber < ActiveSupport::Subscriber + @notification_count = 0 - class << self - attr_accessor :notification_count - end + class << self + attr_accessor :notification_count + end - def throttle(_event) - self.class.notification_count += 1 - end + def throttle(_event) + self.class.notification_count += 1 end +end - describe 'Rack::Attack.instrument' 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 } - end +describe 'Rack::Attack.instrument' 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 } + end - describe "with throttling" do - before do - ActiveSupport::Notifications.stub(:notifier, ActiveSupport::Notifications::Fanout.new) do - CustomSubscriber.attach_to("rack_attack") - 2.times { get '/', {}, 'REMOTE_ADDR' => '1.2.3.4' } - end + describe "with throttling" do + before do + ActiveSupport::Notifications.stub(:notifier, ActiveSupport::Notifications::Fanout.new) do + CustomSubscriber.attach_to("rack_attack") + 2.times { get '/', {}, 'REMOTE_ADDR' => '1.2.3.4' } end + end - it 'should instrument without error' do - _(last_response.status).must_equal 429 - assert_equal 1, CustomSubscriber.notification_count - end + it 'should instrument without error' do + _(last_response.status).must_equal 429 + assert_equal 1, CustomSubscriber.notification_count end end end From 4a68debb7a767ccf4e54b122d32f7741f608831d Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Thu, 26 Oct 2023 19:59:16 -0300 Subject: [PATCH 09/10] ci: automatically run with latest ruby patch version (#634) --- .github/workflows/build.yml | 68 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3237bd4d..c7950f0f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,12 +17,12 @@ jobs: strategy: matrix: ruby: - - 3.2.2 - - 3.1.4 - - 3.0.6 - - 2.7.8 - - 2.6.10 - - 2.5.8 + - '3.2' + - '3.1' + - '3.0' + - '2.7' + - '2.6' + - '2.5' gemfile: - rack_3 - rack_2 @@ -48,61 +48,61 @@ jobs: - redis_store exclude: - gemfile: rack_1 - ruby: 3.2.2 + ruby: '3.2' - gemfile: rails_5_2 - ruby: 3.2.2 + ruby: '3.2' - gemfile: active_support_5_redis_cache_store - ruby: 3.2.2 + ruby: '3.2' - gemfile: active_support_5_redis_cache_store_pooled - ruby: 3.2.2 + ruby: '3.2' - gemfile: dalli2 - ruby: 3.2.2 + ruby: '3.2' - gemfile: rack_1 - ruby: 3.1.4 + ruby: '3.1' - gemfile: rails_5_2 - ruby: 3.1.4 + ruby: '3.1' - gemfile: active_support_5_redis_cache_store - ruby: 3.1.4 + ruby: '3.1' - gemfile: active_support_5_redis_cache_store_pooled - ruby: 3.1.4 + ruby: '3.1' - gemfile: dalli2 - ruby: 3.1.4 + ruby: '3.1' - gemfile: rack_1 - ruby: 3.0.6 + ruby: '3.0' - gemfile: rails_5_2 - ruby: 3.0.6 + ruby: '3.0' - gemfile: active_support_5_redis_cache_store - ruby: 3.0.6 + ruby: '3.0' - gemfile: active_support_5_redis_cache_store_pooled - ruby: 3.0.6 + ruby: '3.0' - gemfile: dalli2 - ruby: 3.0.6 + ruby: '3.0' - gemfile: rack_1 - ruby: 2.7.8 + ruby: '2.7' - gemfile: rails_7_0 - ruby: 2.6.10 + ruby: '2.6' - gemfile: rails_7_0 - ruby: 2.5.8 + ruby: '2.5' - gemfile: active_support_7_0_redis_cache_store - ruby: 2.5.8 + ruby: '2.6' - gemfile: active_support_7_0_redis_cache_store - ruby: 2.6.10 + ruby: '2.5' - gemfile: active_support_7_0_redis_cache_store_pooled - ruby: 2.5.8 + ruby: '2.6' - gemfile: active_support_7_0_redis_cache_store_pooled - ruby: 2.6.10 + ruby: '2.5' - gemfile: rails_7_1 - ruby: 2.6.10 + ruby: '2.6' - gemfile: rails_7_1 - ruby: 2.5.8 + ruby: '2.5' - gemfile: active_support_7_1_redis_cache_store - ruby: 2.5.8 + ruby: '2.6' - gemfile: active_support_7_1_redis_cache_store - ruby: 2.6.10 + ruby: '2.5' - gemfile: active_support_7_1_redis_cache_store_pooled - ruby: 2.5.8 + ruby: '2.6' - gemfile: active_support_7_1_redis_cache_store_pooled - ruby: 2.6.10 + ruby: '2.5' env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile steps: From ffc210250f4fc7e494671068396d6b1b1db3db6c Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Fri, 27 Oct 2023 21:46:07 -0300 Subject: [PATCH 10/10] refactor: minor refactoring (#635) --- lib/rack/attack/throttle.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rack/attack/throttle.rb b/lib/rack/attack/throttle.rb index 69923393..0ec5f7aa 100644 --- a/lib/rack/attack/throttle.rb +++ b/lib/rack/attack/throttle.rb @@ -38,8 +38,9 @@ def matched_by?(request) epoch_time: cache.last_epoch_time } + annotate_request_with_throttle_data(request, data) + (count > current_limit).tap do |throttled| - annotate_request_with_throttle_data(request, data) if throttled annotate_request_with_matched_data(request, data) Rack::Attack.instrument(request)