Commit d8703071 authored by Michael Kozono's avatar Michael Kozono Committed by Francisco Lopez

Allow throttling code in test environment

This code should not break other tests because the rate limits are off by default.
parent 143369e4
...@@ -21,27 +21,23 @@ class Rack::Attack ...@@ -21,27 +21,23 @@ class Rack::Attack
{ limit: limit_proc, period: period_proc } { limit: limit_proc, period: period_proc }
end end
def self.define_throttles throttle('throttle_unauthenticated', throttle_unauthenticated_options) do |req|
throttle('throttle_unauthenticated', throttle_unauthenticated_options) do |req| settings.throttle_unauthenticated_enabled &&
settings.throttle_unauthenticated_enabled && req.unauthenticated? &&
req.unauthenticated? && req.ip
req.ip end
end
throttle('throttle_authenticated_api', throttle_authenticated_api_options) do |req|
settings.throttle_authenticated_api_enabled &&
req.api_request? &&
req.authenticated_user_id
end
throttle('throttle_authenticated_web', throttle_authenticated_web_options) do |req| throttle('throttle_authenticated_api', throttle_authenticated_api_options) do |req|
settings.throttle_authenticated_web_enabled && settings.throttle_authenticated_api_enabled &&
req.web_request? && req.api_request? &&
req.authenticated_user_id req.authenticated_user_id
end
end end
define_throttles unless Rails.env.test? throttle('throttle_authenticated_web', throttle_authenticated_web_options) do |req|
settings.throttle_authenticated_web_enabled &&
req.web_request? &&
req.authenticated_user_id
end
class Request class Request
def unauthenticated? def unauthenticated?
......
...@@ -4,9 +4,6 @@ describe Rack::Attack do ...@@ -4,9 +4,6 @@ describe Rack::Attack do
let(:settings) { Gitlab::CurrentSettings.current_application_settings } let(:settings) { Gitlab::CurrentSettings.current_application_settings }
before do before do
# Ensure throttles are defined, because this is normally skipped for tests
described_class.define_throttles
# Instead of test environment's :null_store # Instead of test environment's :null_store
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment