mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Acceptance test cache store config when Rails is present
This commit is contained in:
parent
d3404a7a91
commit
330d25c832
2 changed files with 33 additions and 0 deletions
|
|
@ -23,7 +23,9 @@ Gem::Specification.new do |s|
|
|||
s.required_ruby_version = '>= 2.0.0'
|
||||
|
||||
s.add_dependency 'rack'
|
||||
|
||||
s.add_development_dependency 'minitest'
|
||||
s.add_development_dependency "minitest-stub-const"
|
||||
s.add_development_dependency 'rack-test'
|
||||
s.add_development_dependency 'rake'
|
||||
s.add_development_dependency 'appraisal'
|
||||
|
|
|
|||
31
spec/acceptance/cache_store_config_with_rails_spec.rb
Normal file
31
spec/acceptance/cache_store_config_with_rails_spec.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
require_relative "../spec_helper"
|
||||
require "minitest/stub_const"
|
||||
require "ostruct"
|
||||
|
||||
describe "Cache store config with Rails" do
|
||||
before do
|
||||
Rack::Attack.throttle("by ip", limit: 1, period: 60) do |request|
|
||||
request.ip
|
||||
end
|
||||
end
|
||||
|
||||
it "fails when Rails.cache is not set" do
|
||||
Object.stub_const(:Rails, OpenStruct.new(cache: nil)) do
|
||||
assert_raises(Rack::Attack::MissingStoreError) do
|
||||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "works when Rails.cache is set" do
|
||||
Object.stub_const(:Rails, OpenStruct.new(cache: ActiveSupport::Cache::MemoryStore.new)) do
|
||||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
||||
|
||||
assert_equal 200, last_response.status
|
||||
|
||||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
||||
|
||||
assert_equal 429, last_response.status
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue