diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-09 21:09:19 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-09 21:09:19 +0000 |
commit | b5944525b015e4efb4cd2c1d09ec37566d7691a0 (patch) | |
tree | 23134355a45b69298483e6c08b65ef6b23b8bd26 /spec/controllers | |
parent | 16cfd85bcf0046ae97d7ea84dae7eea3eafafe99 (diff) | |
download | gitlab-ce-b5944525b015e4efb4cd2c1d09ec37566d7691a0.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/projects/notes_controller_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/controllers/projects/notes_controller_spec.rb b/spec/controllers/projects/notes_controller_spec.rb index 6b77794c66d..64bff82f59f 100644 --- a/spec/controllers/projects/notes_controller_spec.rb +++ b/spec/controllers/projects/notes_controller_spec.rb @@ -727,6 +727,42 @@ RSpec.describe Projects::NotesController do end end end + + context 'when the endpoint receives requests above the limit' do + before do + stub_application_setting(notes_create_limit: 5) + end + + it 'prevents from creating more notes', :request_store do + 5.times { create! } + + expect { create! } + .to change { Gitlab::GitalyClient.get_request_count }.by(0) + + create! + expect(response.body).to eq(_('This endpoint has been requested too many times. Try again later.')) + expect(response).to have_gitlab_http_status(:too_many_requests) + end + + it 'logs the event in auth.log' do + attributes = { + message: 'Application_Rate_Limiter_Request', + env: :notes_create_request_limit, + remote_ip: '0.0.0.0', + request_method: 'POST', + path: "/#{project.full_path}/notes", + user_id: user.id, + username: user.username + } + + expect(Gitlab::AuthLogger).to receive(:error).with(attributes).once + + project.add_developer(user) + sign_in(user) + + 6.times { create! } + end + end end describe 'PUT update' do |