mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Add test to prevent regressions (#656)
This commit is contained in:
parent
52ce45db11
commit
b6ce502b14
1 changed files with 42 additions and 0 deletions
|
|
@ -4,6 +4,8 @@ require_relative "../spec_helper"
|
||||||
require "timecop"
|
require "timecop"
|
||||||
|
|
||||||
describe "fail2ban" do
|
describe "fail2ban" do
|
||||||
|
let(:notifications) { [] }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
|
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
|
||||||
|
|
||||||
|
|
@ -75,4 +77,44 @@ describe "fail2ban" do
|
||||||
assert_equal 200, last_response.status
|
assert_equal 200, last_response.status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "notifies when the request is blocked" do
|
||||||
|
ActiveSupport::Notifications.subscribe("rack.attack") do |_name, _start, _finish, _id, payload|
|
||||||
|
notifications.push(payload)
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/"
|
||||||
|
|
||||||
|
assert_equal 200, last_response.status
|
||||||
|
assert notifications.empty?
|
||||||
|
|
||||||
|
get "/private-place"
|
||||||
|
|
||||||
|
assert_equal 403, last_response.status
|
||||||
|
assert_equal 1, notifications.size
|
||||||
|
notification = notifications.pop
|
||||||
|
assert_equal 'fail2ban pentesters', notification[:request].env["rack.attack.matched"]
|
||||||
|
assert_equal :blocklist, notification[:request].env["rack.attack.match_type"]
|
||||||
|
|
||||||
|
get "/"
|
||||||
|
|
||||||
|
assert_equal 200, last_response.status
|
||||||
|
assert notifications.empty?
|
||||||
|
|
||||||
|
get "/private-place"
|
||||||
|
|
||||||
|
assert_equal 403, last_response.status
|
||||||
|
assert_equal 1, notifications.size
|
||||||
|
notification = notifications.pop
|
||||||
|
assert_equal 'fail2ban pentesters', notification[:request].env["rack.attack.matched"]
|
||||||
|
assert_equal :blocklist, notification[:request].env["rack.attack.match_type"]
|
||||||
|
|
||||||
|
get "/"
|
||||||
|
|
||||||
|
assert_equal 403, last_response.status
|
||||||
|
assert_equal 1, notifications.size
|
||||||
|
notification = notifications.pop
|
||||||
|
assert_equal 'fail2ban pentesters', notification[:request].env["rack.attack.matched"]
|
||||||
|
assert_equal :blocklist, notification[:request].env["rack.attack.match_type"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue