mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Acceptance test plain redis as a cache store backend
This commit is contained in:
parent
6fbb6c8b1c
commit
e50bfbebaa
4 changed files with 52 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
7
gemfiles/redis_4.gemfile
Normal file
7
gemfiles/redis_4.gemfile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# This file was generated by Appraisal
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "redis", "~> 4.0"
|
||||
|
||||
gemspec path: "../"
|
||||
40
spec/acceptance/stores/redis_spec.rb
Normal file
40
spec/acceptance/stores/redis_spec.rb
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue