forked from rack/rack-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR removes the
rescuing
blocks from Dalli/RedisProxy classes a…
…nd instead catches errors at the top level.
- Loading branch information
1 parent
d9fedfa
commit bbe3fee
Showing
7 changed files
with
91 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../spec_helper" | ||
|
||
describe "error handling" do | ||
|
||
let(:store) do | ||
ActiveSupport::Cache::MemoryStore.new | ||
end | ||
|
||
before do | ||
Rack::Attack.cache.store = store | ||
|
||
Rack::Attack.blocklist("fail2ban pentesters") do |request| | ||
Rack::Attack::Fail2Ban.filter(request.ip, maxretry: 0, bantime: 600, findtime: 30) { true } | ||
end | ||
end | ||
|
||
describe '.call' do | ||
before do | ||
allow(store).to receive(:read).and_raise(raised_error) | ||
end | ||
|
||
describe 'when raising Dalli::DalliError' do | ||
let(:raised_error) { stub_const('Dalli::DalliError', Class.new(StandardError)) } | ||
|
||
it 'allows the response' do | ||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4" | ||
|
||
assert_equal 200, last_response.status | ||
end | ||
end | ||
|
||
describe 'when raising Redis::BaseError' do | ||
let(:raised_error) { stub_const('Redis::BaseError', Class.new(StandardError)) } | ||
|
||
it 'allows the response' do | ||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4" | ||
|
||
assert_equal 200, last_response.status | ||
end | ||
end | ||
|
||
describe 'when raising other error' do | ||
let(:raised_error) { RuntimeError } | ||
|
||
it 'raises error if not ignored' do | ||
assert_raises(RuntimeError) do | ||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters