mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 08:32:26 +08:00
49ed382c2a
This also handles a general case where exceptions leak out prior to being handled by the application controller
38 lines
738 B
Ruby
38 lines
738 B
Ruby
# 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
|
|
#request.set_header("action_dispatch.show_exceptions", true)
|
|
|
|
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/api/keys.json', params: {
|
|
api_key: api_key.key,
|
|
api_username: admin.username
|
|
}
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
get '/admin/api/keys.json', params: {
|
|
api_key: api_key.key,
|
|
api_username: admin.username
|
|
}
|
|
|
|
expect(response.status).to eq(429)
|
|
end
|
|
end
|