diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/controllers/projects_controller_spec.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/controllers/projects_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects_controller_spec.rb | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index c098ea71f7a..07bd198137a 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -473,28 +473,6 @@ RSpec.describe ProjectsController do end end end - - context 'with new_project_sast_enabled', :experiment do - let(:params) do - { - path: 'foo', - description: 'bar', - namespace_id: user.namespace.id, - initialize_with_sast: '1' - } - end - - it 'tracks an event on project creation' do - expect(experiment(:new_project_sast_enabled)).to track(:created, - property: 'blank', - checked: true, - project: an_instance_of(Project), - namespace: user.namespace - ).on_next_instance.with_context(user: user) - - post :create, params: { project: params } - end - end end describe 'GET edit' do @@ -1159,16 +1137,15 @@ RSpec.describe ProjectsController do context 'when gitaly is unavailable' do before do expect_next_instance_of(TagsFinder) do |finder| - allow(finder).to receive(:execute).and_raise(Gitlab::Git::CommandError) + allow(finder).to receive(:execute).and_raise(Gitlab::Git::CommandError, 'something went wrong') end end - it 'gets an empty list of tags' do + it 'responds with 503 error' do get :refs, params: { namespace_id: project.namespace, id: project, ref: "123456" } - expect(json_response["Branches"]).to include("master") - expect(json_response["Tags"]).to eq([]) - expect(json_response["Commits"]).to include("123456") + expect(response).to have_gitlab_http_status(:service_unavailable) + expect(json_response['error']).to eq 'Unable to load refs' end end @@ -1466,14 +1443,15 @@ RSpec.describe ProjectsController do end describe '#download_export', :clean_gitlab_redis_rate_limiting do + let(:project) { create(:project, :with_export, service_desk_enabled: false) } let(:action) { :download_export } context 'object storage enabled' do context 'when project export is enabled' do - it 'returns 302' do + it 'returns 200' do get action, params: { namespace_id: project.namespace, id: project } - expect(response).to have_gitlab_http_status(:found) + expect(response).to have_gitlab_http_status(:ok) end end @@ -1513,14 +1491,37 @@ RSpec.describe ProjectsController do 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 + end + + context 'applies correct scope when throttling', :clean_gitlab_redis_rate_limiting do + before do + stub_application_setting(project_download_export_limit: 1) + end - it 'applies correct scope when throttling' do + it 'applies throttle per namespace' do expect(Gitlab::ApplicationRateLimiter) .to receive(:throttled?) - .with(:project_download_export, scope: [user, project]) + .with(:project_download_export, scope: [user, project.namespace]) post action, params: { namespace_id: project.namespace, id: project } end + + it 'throttles downloads within same namespaces' do + # simulate prior request to the same namespace, which increments the rate limit counter for that scope + Gitlab::ApplicationRateLimiter.throttled?(:project_download_export, scope: [user, project.namespace]) + + get action, params: { namespace_id: project.namespace, id: project } + expect(response).to have_gitlab_http_status(:too_many_requests) + end + + it 'allows downloads from different namespaces' do + # simulate prior request to a different namespace, which increments the rate limit counter for that scope + Gitlab::ApplicationRateLimiter.throttled?(:project_download_export, + scope: [user, create(:project, :with_export).namespace]) + + get action, params: { namespace_id: project.namespace, id: project } + expect(response).to have_gitlab_http_status(:ok) + end end end end |