mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +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"
|
require_relative "../spec_helper"
|
||||||
|
|
||||||
describe "Customizing block responses" do
|
describe "Customizing block responses" do
|
||||||
it "can be customized" do
|
before do
|
||||||
Rack::Attack.blocklist("block 1.2.3.4") do |request|
|
Rack::Attack.blocklist("block 1.2.3.4") do |request|
|
||||||
request.ip == "1.2.3.4"
|
request.ip == "1.2.3.4"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can be customized" do
|
||||||
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
||||||
|
|
||||||
assert_equal 403, last_response.status
|
assert_equal 403, last_response.status
|
||||||
|
|
@ -19,4 +21,21 @@ describe "Customizing block responses" do
|
||||||
assert_equal 503, last_response.status
|
assert_equal 503, last_response.status
|
||||||
assert_equal "Blocked", last_response.body
|
assert_equal "Blocked", last_response.body
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue