diff options
Diffstat (limited to 'spec/controllers/projects_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects_controller_spec.rb | 137 |
1 files changed, 78 insertions, 59 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index d16201fff5a..a1f9b98dc2c 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -1055,45 +1055,34 @@ describe ProjectsController do end end - describe '#export' do + describe 'project export' do before do sign_in(user) project.add_maintainer(user) end - context 'when project export is enabled' do - it 'returns 302' do - get :export, params: { namespace_id: project.namespace, id: project } - - expect(response).to have_gitlab_http_status(302) - end - end - - context 'when project export is disabled' do + shared_examples 'rate limits project export endpoint' do before do - stub_application_setting(project_export_enabled?: false) + allow(::Gitlab::ApplicationRateLimiter) + .to receive(:throttled?) + .and_return(true) end - it 'returns 404' do - get :export, params: { namespace_id: project.namespace, id: project } + it 'prevents requesting project export' do + get action, params: { namespace_id: project.namespace, id: project } - expect(response).to have_gitlab_http_status(404) + expect(flash[:alert]).to eq('This endpoint has been requested too many times. Try again later.') + expect(response).to have_gitlab_http_status(302) end end - end - describe '#download_export' do - before do - sign_in(user) + describe '#export' do + let(:action) { :export } - project.add_maintainer(user) - end - - context 'object storage enabled' do context 'when project export is enabled' do it 'returns 302' do - get :download_export, params: { namespace_id: project.namespace, id: project } + get action, params: { namespace_id: project.namespace, id: project } expect(response).to have_gitlab_http_status(302) end @@ -1105,66 +1094,96 @@ describe ProjectsController do end it 'returns 404' do - get :download_export, params: { namespace_id: project.namespace, id: project } + get action, params: { namespace_id: project.namespace, id: project } expect(response).to have_gitlab_http_status(404) end end + + context 'when the endpoint receives requests above the limit', :clean_gitlab_redis_cache do + include_examples 'rate limits project export endpoint' + end end - end - describe '#remove_export' do - before do - sign_in(user) + describe '#download_export' do + let(:action) { :download_export } - project.add_maintainer(user) - end + context 'object storage enabled' do + context 'when project export is enabled' do + it 'returns 302' do + get action, params: { namespace_id: project.namespace, id: project } - context 'when project export is enabled' do - it 'returns 302' do - post :remove_export, params: { namespace_id: project.namespace, id: project } + expect(response).to have_gitlab_http_status(302) + end + end - expect(response).to have_gitlab_http_status(302) - end - end + context 'when project export is disabled' do + before do + stub_application_setting(project_export_enabled?: false) + end - context 'when project export is disabled' do - before do - stub_application_setting(project_export_enabled?: false) - end + it 'returns 404' do + get action, params: { namespace_id: project.namespace, id: project } - it 'returns 404' do - post :remove_export, params: { namespace_id: project.namespace, id: project } + expect(response).to have_gitlab_http_status(404) + end + end - expect(response).to have_gitlab_http_status(404) + context 'when the endpoint receives requests above the limit', :clean_gitlab_redis_cache do + include_examples 'rate limits project export endpoint' + end end end - end - describe '#generate_new_export' do - before do - sign_in(user) + describe '#remove_export' do + let(:action) { :remove_export } - project.add_maintainer(user) - end + context 'when project export is enabled' do + it 'returns 302' do + post action, params: { namespace_id: project.namespace, id: project } - context 'when project export is enabled' do - it 'returns 302' do - post :generate_new_export, params: { namespace_id: project.namespace, id: project } + expect(response).to have_gitlab_http_status(302) + end + end - expect(response).to have_gitlab_http_status(302) + context 'when project export is disabled' do + before do + stub_application_setting(project_export_enabled?: false) + end + + it 'returns 404' do + post action, params: { namespace_id: project.namespace, id: project } + + expect(response).to have_gitlab_http_status(404) + end end end - context 'when project export is disabled' do - before do - stub_application_setting(project_export_enabled?: false) + describe '#generate_new_export' do + let(:action) { :generate_new_export } + + context 'when project export is enabled' do + it 'returns 302' do + post action, params: { namespace_id: project.namespace, id: project } + + expect(response).to have_gitlab_http_status(302) + end end - it 'returns 404' do - post :generate_new_export, params: { namespace_id: project.namespace, id: project } + context 'when project export is disabled' do + before do + stub_application_setting(project_export_enabled?: false) + end - expect(response).to have_gitlab_http_status(404) + it 'returns 404' do + post action, params: { namespace_id: project.namespace, id: project } + + expect(response).to have_gitlab_http_status(404) + end + end + + context 'when the endpoint receives requests above the limit', :clean_gitlab_redis_cache do + include_examples 'rate limits project export endpoint' end end end |