diff --git a/.travis.yml b/.travis.yml index 46bb12f..6b99df2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ gemfile: - gemfiles/rails_5_1.gemfile - gemfiles/rails_4_2.gemfile - gemfiles/dalli2.gemfile + - gemfiles/redis_4.gemfile - gemfiles/connection_pool_dalli.gemfile - gemfiles/active_support_redis_cache_store.gemfile - gemfiles/active_support_redis_cache_store_pooled.gemfile diff --git a/Appraisals b/Appraisals index 2cabba7..1328254 100644 --- a/Appraisals +++ b/Appraisals @@ -40,6 +40,10 @@ appraise 'dalli2' do gem 'dalli', '~> 2.0' end +appraise 'redis_4' do + gem 'redis', '~> 4.0' +end + appraise "connection_pool_dalli" do gem "connection_pool", "~> 2.2" gem "dalli", "~> 2.7" diff --git a/gemfiles/redis_4.gemfile b/gemfiles/redis_4.gemfile new file mode 100644 index 0000000..701e936 --- /dev/null +++ b/gemfiles/redis_4.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "redis", "~> 4.0" + +gemspec path: "../" diff --git a/spec/acceptance/stores/redis_spec.rb b/spec/acceptance/stores/redis_spec.rb new file mode 100644 index 0000000..8524db6 --- /dev/null +++ b/spec/acceptance/stores/redis_spec.rb @@ -0,0 +1,40 @@ +require_relative "../../spec_helper" + +if defined?(::Redis) + require_relative "../../support/cache_store_helper" + require "timecop" + + describe "Plain redis as a cache backend" do + before do + Rack::Attack.cache.store = Redis.new + end + + after do + Rack::Attack.cache.store.flushdb + end + + it_works_for_cache_backed_features + + it "doesn't leak keys" do + Rack::Attack.throttle("by ip", limit: 1, period: 1) do |request| + request.ip + end + + key = nil + + # Freeze time during these statement to be sure that the key used by rack attack is the same + # we pre-calculate in local variable `key` + Timecop.freeze do + key = "rack::attack:#{Time.now.to_i}:by ip:1.2.3.4" + + get "/", {}, "REMOTE_ADDR" => "1.2.3.4" + end + + assert Rack::Attack.cache.store.get(key) + + sleep 2.1 + + assert_nil Rack::Attack.cache.store.get(key) + end + end +end