mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-30 10:16:07 +00:00
Because of the sort algorithm rails uses to satisfy `after` and `before`
constraints, gems can have unintended effects on others. See
0a120a818d
Prefer making rack-attack middleware idempotent instead of relying on
the load order and the contents of the middleware stack too much.
closes #452
closes #456
35 lines
1 KiB
Ruby
35 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../spec_helper"
|
|
|
|
if defined?(Rails)
|
|
describe "Middleware for Rails" do
|
|
before do
|
|
@app = Class.new(Rails::Application) do
|
|
config.eager_load = false
|
|
config.logger = Logger.new(nil) # avoid creating the log/ directory automatically
|
|
config.cache_store = :null_store # avoid creating tmp/ directory for cache
|
|
end
|
|
end
|
|
|
|
if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("5.1")
|
|
it "is used by default" do
|
|
@app.initialize!
|
|
assert_equal 1, @app.middleware.count(Rack::Attack)
|
|
end
|
|
|
|
it "is not added when it was explicitly deleted" do
|
|
@app.config.middleware.delete(Rack::Attack)
|
|
@app.initialize!
|
|
refute @app.middleware.include?(Rack::Attack)
|
|
end
|
|
end
|
|
|
|
if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new("5.1")
|
|
it "is not used by default" do
|
|
@app.initialize!
|
|
assert_equal 0, @app.middleware.count(Rack::Attack)
|
|
end
|
|
end
|
|
end
|
|
end
|