Allow throttling code in test environment
This code should not break other tests because the rate limits are off by default.
This commit is contained in:
parent
143369e45b
commit
d87030714a
2 changed files with 15 additions and 22 deletions
|
@ -21,7 +21,6 @@ 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? &&
|
||||||
|
@ -39,9 +38,6 @@ class Rack::Attack
|
||||||
req.web_request? &&
|
req.web_request? &&
|
||||||
req.authenticated_user_id
|
req.authenticated_user_id
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
define_throttles unless Rails.env.test?
|
|
||||||
|
|
||||||
class Request
|
class Request
|
||||||
def unauthenticated?
|
def unauthenticated?
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue