mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
* Acceptance test ability to customize blocked/throttled responses * Don't let customizations to blocklisted/throttled responses leak to other test cases
22 lines
529 B
Ruby
22 lines
529 B
Ruby
require_relative "../spec_helper"
|
|
|
|
describe "Customizing block responses" do
|
|
it "can be customized" do
|
|
Rack::Attack.blocklist("block 1.2.3.4") do |request|
|
|
request.ip == "1.2.3.4"
|
|
end
|
|
|
|
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
|
|
|
assert_equal 403, last_response.status
|
|
|
|
Rack::Attack.blocklisted_response = lambda do |env|
|
|
[503, {}, ["Blocked"]]
|
|
end
|
|
|
|
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
|
|
|
|
assert_equal 503, last_response.status
|
|
assert_equal "Blocked", last_response.body
|
|
end
|
|
end
|