Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acceptance test fail2ban #303

Merged
merged 1 commit into from
Mar 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions spec/acceptance/fail2ban_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require_relative "../spec_helper"
require "timecop"

describe "fail2ban" do
before do
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new

Rack::Attack.blocklist("fail2ban pentesters") do |request|
Rack::Attack::Fail2Ban.filter(request.ip, maxretry: 2, findtime: 30, bantime: 60) do
request.path.include?("private-place")
end
end
end

it "returns OK for many requests to non filtered path" do
get "/"
assert_equal 200, last_response.status

get "/"
assert_equal 200, last_response.status
end

it "forbids access to private path" do
get "/private-place"
assert_equal 403, last_response.status
end

it "returns OK for non filtered path if yet not reached maxretry limit" do
get "/private-place"
assert_equal 403, last_response.status

get "/"
assert_equal 200, last_response.status
end

it "forbids all access after reaching maxretry limit" do
get "/private-place"
assert_equal 403, last_response.status

get "/private-place"
assert_equal 403, last_response.status

get "/"
assert_equal 403, last_response.status
end

it "restores access after bantime elapsed" do
get "/private-place"
assert_equal 403, last_response.status

get "/private-place"
assert_equal 403, last_response.status

get "/"
assert_equal 403, last_response.status

Timecop.travel(60) do
get "/"

assert_equal 200, last_response.status
end
end

it "does not forbid all access if maxrety condition is met but not within the findtime timespan" do
get "/private-place"
assert_equal 403, last_response.status

Timecop.travel(31) do
get "/private-place"
assert_equal 403, last_response.status

get "/"
assert_equal 200, last_response.status
end
end
end