mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-26 14:57:47 +00:00
Auto include middleware for older railses
This commit is contained in:
parent
9c774b5eeb
commit
2527b37221
3 changed files with 5 additions and 27 deletions
|
|
@ -71,12 +71,7 @@ Or install it yourself as:
|
||||||
|
|
||||||
Then tell your ruby web application to use rack-attack as a middleware.
|
Then tell your ruby web application to use rack-attack as a middleware.
|
||||||
|
|
||||||
a) For __rails__ applications with versions >= 5.1 it is used by default. For older rails versions you should enable it explicitly:
|
a) For __rails__ applications it is used by default.
|
||||||
```ruby
|
|
||||||
# In config/application.rb
|
|
||||||
|
|
||||||
config.middleware.use Rack::Attack
|
|
||||||
```
|
|
||||||
|
|
||||||
You can disable it permanently (like for specific environment) or temporarily (can be useful for specific test cases) by writing:
|
You can disable it permanently (like for specific environment) or temporarily (can be useful for specific test cases) by writing:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@ module Rack
|
||||||
class Attack
|
class Attack
|
||||||
class Railtie < ::Rails::Railtie
|
class Railtie < ::Rails::Railtie
|
||||||
initializer "rack-attack.middleware" do |app|
|
initializer "rack-attack.middleware" do |app|
|
||||||
if Gem::Version.new(::Rails::VERSION::STRING) >= Gem::Version.new("5.1")
|
app.middleware.use(Rack::Attack)
|
||||||
app.middleware.use(Rack::Attack)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,24 +12,9 @@ if defined?(Rails)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("5.1")
|
it "is used by default" do
|
||||||
it "is used by default" do
|
@app.initialize!
|
||||||
@app.initialize!
|
assert @app.middleware.include?(Rack::Attack)
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue