Acceptance test ability to access match data in #blocklisted_response

This commit is contained in:
Gonzalo Rodriguez 2018-03-22 11:44:41 -03:00
parent 6614d0b6ee
commit da1f54b6fc
No known key found for this signature in database
GPG key ID: 5DB8B81B049B8AB1

View file

@ -1,11 +1,13 @@
require_relative "../spec_helper"
describe "Customizing block responses" do
it "can be customized" do
before do
Rack::Attack.blocklist("block 1.2.3.4") do |request|
request.ip == "1.2.3.4"
end
end
it "can be customized" do
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
assert_equal 403, last_response.status
@ -19,4 +21,21 @@ describe "Customizing block responses" do
assert_equal 503, last_response.status
assert_equal "Blocked", last_response.body
end
it "exposes match data" do
matched = nil
match_type = nil
Rack::Attack.blocklisted_response = lambda do |env|
matched = env['rack.attack.matched']
match_type = env['rack.attack.match_type']
[503, {}, ["Blocked"]]
end
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
assert_equal "block 1.2.3.4", matched
assert_equal :blocklist, match_type
end
end