Acceptance test that tracking throttles doesn't actually throttle requests

This commit is contained in:
Gonzalo Rodriguez 2018-03-13 18:27:19 -03:00
parent 066434973f
commit 564cbedb36
No known key found for this signature in database
GPG key ID: 5DB8B81B049B8AB1

View file

@ -2,7 +2,7 @@ require_relative "../spec_helper"
require "timecop"
describe "#track with throttle-ish options" do
it "notifies when throttle goes over the limit" do
it "notifies when throttle goes over the limit without actually throttling requests" do
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
Rack::Attack.track("by ip", limit: 1, period: 60) do |request|
@ -22,16 +22,22 @@ describe "#track with throttle-ish options" do
assert_nil notification_matched
assert_nil notification_type
assert_equal 200, last_response.status
get "/", {}, "REMOTE_ADDR" => "5.6.7.8"
assert_nil notification_matched
assert_nil notification_type
assert_equal 200, last_response.status
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
assert_equal "by ip", notification_matched
assert_equal :track, notification_type
assert_equal 200, last_response.status
Timecop.travel(60) do
notification_matched = nil
notification_type = nil
@ -40,6 +46,8 @@ describe "#track with throttle-ish options" do
assert_nil notification_matched
assert_nil notification_type
assert_equal 200, last_response.status
end
end
end