mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
style: fix Style/BlockDelimiters cop check
This commit is contained in:
parent
c0328707b1
commit
8fafa7602b
5 changed files with 9 additions and 10 deletions
|
|
@ -37,6 +37,7 @@ Security:
|
||||||
|
|
||||||
Style/BlockDelimiters:
|
Style/BlockDelimiters:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
IgnoredMethods: [] # Workaround rubocop bug: https://github.com/rubocop-hq/rubocop/issues/6179
|
||||||
|
|
||||||
Style/BracesAroundHashParameters:
|
Style/BracesAroundHashParameters:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
|
||||||
|
|
@ -138,10 +138,10 @@ module Rack
|
||||||
@anonymous_safelists = []
|
@anonymous_safelists = []
|
||||||
@notifier = ActiveSupport::Notifications if defined?(ActiveSupport::Notifications)
|
@notifier = ActiveSupport::Notifications if defined?(ActiveSupport::Notifications)
|
||||||
@blocklisted_response = lambda { |_env| [403, { 'Content-Type' => 'text/plain' }, ["Forbidden\n"]] }
|
@blocklisted_response = lambda { |_env| [403, { 'Content-Type' => 'text/plain' }, ["Forbidden\n"]] }
|
||||||
@throttled_response = lambda { |env|
|
@throttled_response = lambda do |env|
|
||||||
retry_after = (env['rack.attack.match_data'] || {})[:period]
|
retry_after = (env['rack.attack.match_data'] || {})[:period]
|
||||||
[429, { 'Content-Type' => 'text/plain', 'Retry-After' => retry_after.to_s }, ["Retry later\n"]]
|
[429, { 'Content-Type' => 'text/plain', 'Retry-After' => retry_after.to_s }, ["Retry later\n"]]
|
||||||
}
|
end
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ if defined?(::ConnectionPool) && defined?(::Dalli)
|
||||||
Rack::Attack.cache.store.clear
|
Rack::Attack.cache.store.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
it_works_for_cache_backed_features(fetch_from_store: ->(key) {
|
it_works_for_cache_backed_features(fetch_from_store: ->(key) { Rack::Attack.cache.store.read(key) })
|
||||||
Rack::Attack.cache.store.read(key)
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ if defined?(::Dalli) && defined?(::ConnectionPool)
|
||||||
Rack::Attack.cache.store.with { |client| client.flush_all }
|
Rack::Attack.cache.store.with { |client| client.flush_all }
|
||||||
end
|
end
|
||||||
|
|
||||||
it_works_for_cache_backed_features(fetch_from_store: ->(key) {
|
it_works_for_cache_backed_features(
|
||||||
Rack::Attack.cache.store.with { |client| client.fetch(key) }
|
fetch_from_store: ->(key) { Rack::Attack.cache.store.with { |client| client.fetch(key) } }
|
||||||
})
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ describe 'Rack::Attack' do
|
||||||
Rack::Attack.blocklist("ip #{@bad_ip}") { |req| req.ip == @bad_ip }
|
Rack::Attack.blocklist("ip #{@bad_ip}") { |req| req.ip == @bad_ip }
|
||||||
end
|
end
|
||||||
|
|
||||||
it('has a blocklist') {
|
it 'has a blocklist' do
|
||||||
Rack::Attack.blocklists.key?("ip #{@bad_ip}").must_equal true
|
Rack::Attack.blocklists.key?("ip #{@bad_ip}").must_equal true
|
||||||
}
|
end
|
||||||
|
|
||||||
describe "a bad request" do
|
describe "a bad request" do
|
||||||
before { get '/', {}, 'REMOTE_ADDR' => @bad_ip }
|
before { get '/', {}, 'REMOTE_ADDR' => @bad_ip }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue