mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Acceptance test ability to access match data in #blocklisted_response
This commit is contained in:
parent
6614d0b6ee
commit
da1f54b6fc
1 changed files with 20 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue