summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-10-12 17:49:22 -0700
committerFrancisco Lopez <fjlopez@gitlab.com>2017-11-17 09:58:18 +0100
commitd87030714a654b0dfa47aa6b38eb970731e7a04e (patch)
treec6657d86eebd10aea3372826e42712394c339735
parent143369e45b5c32c21d9abd315662eca186d95ab6 (diff)
downloadgitlab-ce-d87030714a654b0dfa47aa6b38eb970731e7a04e.tar.gz
Allow throttling code in test environment
This code should not break other tests because the rate limits are off by default.
-rw-r--r--config/initializers/rack_attack_global.rb32
-rw-r--r--spec/requests/rack_attack_spec.rb3
2 files changed, 14 insertions, 21 deletions
diff --git a/config/initializers/rack_attack_global.rb b/config/initializers/rack_attack_global.rb
index 0b51fadbd02..3073ba06ac1 100644
--- a/config/initializers/rack_attack_global.rb
+++ b/config/initializers/rack_attack_global.rb
@@ -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?
diff --git a/spec/requests/rack_attack_spec.rb b/spec/requests/rack_attack_spec.rb
index 4f406f03993..97108476e00 100644
--- a/spec/requests/rack_attack_spec.rb
+++ b/spec/requests/rack_attack_spec.rb
@@ -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