mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
More log suppressions for rate limit exceeded
This commit is contained in:
parent
4986ebcf24
commit
63bdc4056d
3 changed files with 45 additions and 1 deletions
|
@ -49,6 +49,9 @@ if (Rails.env.production? && SiteSetting.logging_provider == 'lograge') || ENV["
|
||||||
end
|
end
|
||||||
|
|
||||||
output
|
output
|
||||||
|
rescue RateLimiter::LimitExceeded
|
||||||
|
# no idea who this is, but they are limited
|
||||||
|
{}
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.warn("Failed to append custom options: #{e.message}\n#{e.backtrace.join("\n")}")
|
Rails.logger.warn("Failed to append custom options: #{e.message}\n#{e.backtrace.join("\n")}")
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -35,7 +35,11 @@ if Rails.env.production?
|
||||||
/^ActionController::BadRequest/,
|
/^ActionController::BadRequest/,
|
||||||
|
|
||||||
# we can't do anything about invalid parameters
|
# we can't do anything about invalid parameters
|
||||||
/Rack::QueryParser::InvalidParameterError/
|
/Rack::QueryParser::InvalidParameterError/,
|
||||||
|
|
||||||
|
# we handle this cleanly in the message bus middleware
|
||||||
|
# no point logging to logster
|
||||||
|
/RateLimiter::LimitExceeded.*/m
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
37
spec/integration/rate_limiting_spec.rb
Normal file
37
spec/integration/rate_limiting_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe 'admin rate limit' do
|
||||||
|
|
||||||
|
before do
|
||||||
|
RateLimiter.enable
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
RateLimiter.disable
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can cleanly limit requests' do
|
||||||
|
|
||||||
|
admin = Fabricate(:admin)
|
||||||
|
api_key = Fabricate(:api_key, key: SecureRandom.hex, user: admin)
|
||||||
|
|
||||||
|
global_setting :max_admin_api_reqs_per_key_per_minute, 1
|
||||||
|
|
||||||
|
get '/admin/users.json', params: {
|
||||||
|
api_key: api_key.key,
|
||||||
|
api_username: admin.username
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
|
get '/admin/users.json', params: {
|
||||||
|
api_key: api_key.key,
|
||||||
|
api_username: admin.username
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response.status).to eq(429)
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue