Skip to content
Snippets Groups Projects
Commit d8703071 authored by Michael Kozono's avatar Michael Kozono Committed by Francisco Javier López
Browse files

Allow throttling code in test environment

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