diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-06 18:10:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-06 18:10:41 +0300 |
commit | 26e466d81eef11d3dcaecd1328e9e66c4633f5b9 (patch) | |
tree | d2403f8424d541907c1f548eddaadcd8434afc14 /spec/controllers | |
parent | e9aabbc4b5c80a569ce7e5909bd9d8def11b7a1b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/projects/deploy_keys_controller_spec.rb | 104 |
1 files changed, 69 insertions, 35 deletions
diff --git a/spec/controllers/projects/deploy_keys_controller_spec.rb b/spec/controllers/projects/deploy_keys_controller_spec.rb index 96addb4b6c5..43f089cede9 100644 --- a/spec/controllers/projects/deploy_keys_controller_spec.rb +++ b/spec/controllers/projects/deploy_keys_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::DeployKeysController do +RSpec.describe Projects::DeployKeysController, feature_category: :continuous_delivery do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:admin) { create(:admin) } @@ -13,60 +13,94 @@ RSpec.describe Projects::DeployKeysController do sign_in(user) end - describe 'GET index' do - let(:params) do - { namespace_id: project.namespace, project_id: project } - end + describe 'GET actions' do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } - context 'when html requested' do - it 'redirects to project settings with the correct anchor' do - get :index, params: params + let_it_be(:accessible_project) { create(:project, :internal).tap { |p| p.add_developer(user) } } + let_it_be(:inaccessible_project) { create(:project, :internal) } + let_it_be(:project_private) { create(:project, :private) } - expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings')) - end + let_it_be(:deploy_key_for_target_project) do + create(:deploy_keys_project, project: project, deploy_key: create(:deploy_key)) end - context 'when json requested' do - let(:project2) { create(:project, :internal) } - let(:project_private) { create(:project, :private) } + let_it_be(:deploy_key_for_accessible_project) do + create(:deploy_keys_project, project: accessible_project, deploy_key: create(:deploy_key)) + end - let(:deploy_key_internal) { create(:deploy_key) } - let(:deploy_key_actual) { create(:deploy_key) } - let!(:deploy_key_public) { create(:deploy_key, public: true) } + let_it_be(:deploy_key_for_inaccessible_project) do + create(:deploy_keys_project, project: inaccessible_project, deploy_key: create(:deploy_key)) + end - let!(:deploy_keys_project_internal) do - create(:deploy_keys_project, project: project2, deploy_key: deploy_key_internal) - end + let_it_be(:deploy_keys_project_private) do + create(:deploy_keys_project, project: project_private, deploy_key: create(:another_deploy_key)) + end - let!(:deploy_keys_project_actual) do - create(:deploy_keys_project, project: project, deploy_key: deploy_key_actual) - end + let_it_be(:deploy_key_public) { create(:deploy_key, public: true) } - let!(:deploy_keys_project_private) do - create(:deploy_keys_project, project: project_private, deploy_key: create(:another_deploy_key)) + describe 'GET index' do + let(:params) do + { namespace_id: project.namespace, project_id: project } end - context 'when user has access to all projects where deploy keys are used' do - before do - project2.add_developer(user) + context 'when html requested' do + it 'redirects to project settings with the correct anchor' do + get :index, params: params + + expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings')) end + end + context 'when json requested' do it 'returns json in a correct format' do get :index, params: params.merge(format: :json) expect(json_response.keys).to match_array(%w[enabled_keys available_project_keys public_keys]) - expect(json_response['enabled_keys'].count).to eq(1) - expect(json_response['available_project_keys'].count).to eq(1) - expect(json_response['public_keys'].count).to eq(1) + expect(json_response['enabled_keys'].pluck('id')).to match_array( + [deploy_key_for_target_project.deploy_key_id] + ) + expect(json_response['available_project_keys'].pluck('id')).to match_array( + [deploy_key_for_accessible_project.deploy_key_id] + ) + expect(json_response['public_keys'].pluck('id')).to match_array([deploy_key_public.id]) end end + end - context 'when user has no access to all projects where deploy keys are used' do - it 'returns json in a correct format' do - get :index, params: params.merge(format: :json) + describe 'GET enabled_keys' do + let(:params) do + { namespace_id: project.namespace, project_id: project } + end - expect(json_response['available_project_keys'].count).to eq(0) - end + it 'returns only enabled keys' do + get :enabled_keys, params: params.merge(format: :json) + + expect(json_response.pluck("id")).to match_array([deploy_key_for_target_project.deploy_key_id]) + end + end + + describe 'GET available_project_keys' do + let(:params) do + { namespace_id: project.namespace, project_id: project } + end + + it 'returns available project keys' do + get :available_project_keys, params: params.merge(format: :json) + + expect(json_response.pluck("id")).to match_array([deploy_key_for_accessible_project.deploy_key_id]) + end + end + + describe 'GET available_public_keys' do + let(:params) do + { namespace_id: project.namespace, project_id: project } + end + + it 'returns available public keys' do + get :available_public_keys, params: params.merge(format: :json) + + expect(json_response.pluck("id")).to match_array([deploy_key_public.id]) end end end |