diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index de8e705cab5..30829de022b 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -36,6 +36,7 @@ def headers namespace: 'rack-attack', url: IdentityConfig.store.redis_throttle_url, expires_in: 2.weeks.to_i, + pool_size: IdentityConfig.store.redis_throttle_pool_size, ) ### Configure Safelisting ### diff --git a/spec/config/initializers/rack_attack_spec.rb b/spec/config/initializers/rack_attack_spec.rb new file mode 100644 index 00000000000..c3b20295db2 --- /dev/null +++ b/spec/config/initializers/rack_attack_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Rack::Attack do + describe '::cache.store' do + it 'is a pool, not just a plain redis instance' do + expect(Rack::Attack.cache.store.redis).to be_kind_of(ConnectionPool) + end + end +end diff --git a/spec/requests/rack_attack_spec.rb b/spec/requests/rack_attack_spec.rb index c186f48f0fe..4123df71fc0 100644 --- a/spec/requests/rack_attack_spec.rb +++ b/spec/requests/rack_attack_spec.rb @@ -1,8 +1,14 @@ require 'rails_helper' describe 'throttling requests' do - before(:all) { Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new } - before(:each) { Rack::Attack.cache.store.clear } + around do |ex| + original_store = Rack::Attack.cache.store + Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new + Rack::Attack.cache.store.clear + ex.run + ensure + Rack::Attack.cache.store = original_store + end let(:requests_per_ip_limit) { IdentityConfig.store.requests_per_ip_limit } let(:logins_per_ip_limit) { IdentityConfig.store.logins_per_ip_limit }