diff options
Diffstat (limited to 'spec/services/clusters')
25 files changed, 393 insertions, 57 deletions
diff --git a/spec/services/clusters/agent_tokens/create_service_spec.rb b/spec/services/clusters/agent_tokens/create_service_spec.rb index dc7abd1504b..803bd947629 100644 --- a/spec/services/clusters/agent_tokens/create_service_spec.rb +++ b/spec/services/clusters/agent_tokens/create_service_spec.rb @@ -2,14 +2,14 @@ require 'spec_helper' -RSpec.describe Clusters::AgentTokens::CreateService do - subject(:service) { described_class.new(container: project, current_user: user, params: params) } +RSpec.describe Clusters::AgentTokens::CreateService, feature_category: :deployment_management do + subject(:service) { described_class.new(agent: cluster_agent, current_user: user, params: params) } let_it_be(:user) { create(:user) } let(:cluster_agent) { create(:cluster_agent) } let(:project) { cluster_agent.project } - let(:params) { { agent_id: cluster_agent.id, description: 'token description', name: 'token name' } } + let(:params) { { description: 'token description', name: 'token name' } } describe '#execute' do subject { service.execute } @@ -75,7 +75,7 @@ RSpec.describe Clusters::AgentTokens::CreateService do it 'returns validation errors', :aggregate_failures do expect(subject.status).to eq(:error) - expect(subject.message).to eq(["Agent must exist", "Name can't be blank"]) + expect(subject.message).to eq(["Name can't be blank"]) end end end diff --git a/spec/services/clusters/agent_tokens/revoke_service_spec.rb b/spec/services/clusters/agent_tokens/revoke_service_spec.rb new file mode 100644 index 00000000000..a1537658723 --- /dev/null +++ b/spec/services/clusters/agent_tokens/revoke_service_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Clusters::AgentTokens::RevokeService, feature_category: :deployment_management do + describe '#execute' do + subject { described_class.new(token: agent_token, current_user: user).execute } + + let(:agent) { create(:cluster_agent) } + let(:agent_token) { create(:cluster_agent_token, agent: agent) } + let(:project) { agent.project } + let(:user) { agent.created_by_user } + + before do + project.add_maintainer(user) + end + + context 'when user is authorized' do + before do + project.add_maintainer(user) + end + + context 'when user revokes agent token' do + it 'succeeds' do + subject + + expect(agent_token.revoked?).to be true + end + + it 'creates an activity event' do + expect { subject }.to change { ::Clusters::Agents::ActivityEvent.count }.by(1) + + event = agent.activity_events.last + + expect(event).to have_attributes( + kind: 'token_revoked', + level: 'info', + recorded_at: agent_token.reload.updated_at, + user: user, + agent_token: agent_token + ) + end + end + + context 'when there is a validation failure' do + before do + agent_token.name = '' # make the record invalid, as we require a name to be present + end + + it 'fails without raising an error', :aggregate_failures do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to eq(["Name can't be blank"]) + end + + it 'does not create an activity event' do + expect { subject }.not_to change { ::Clusters::Agents::ActivityEvent.count } + end + end + end + + context 'when user is not authorized' do + let(:user) { create(:user) } + + before do + project.add_guest(user) + end + + context 'when user attempts to revoke agent token' do + it 'fails' do + subject + + expect(agent_token.revoked?).to be false + end + end + end + end +end diff --git a/spec/services/clusters/agent_tokens/track_usage_service_spec.rb b/spec/services/clusters/agent_tokens/track_usage_service_spec.rb index 3350b15a5ce..6bea8afcc80 100644 --- a/spec/services/clusters/agent_tokens/track_usage_service_spec.rb +++ b/spec/services/clusters/agent_tokens/track_usage_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::AgentTokens::TrackUsageService do +RSpec.describe Clusters::AgentTokens::TrackUsageService, feature_category: :deployment_management do let_it_be(:agent) { create(:cluster_agent) } describe '#execute', :clean_gitlab_redis_cache do diff --git a/spec/services/clusters/agents/filter_authorizations_service_spec.rb b/spec/services/clusters/agents/authorizations/ci_access/filter_service_spec.rb index 62cff405d0c..45443cfd887 100644 --- a/spec/services/clusters/agents/filter_authorizations_service_spec.rb +++ b/spec/services/clusters/agents/authorizations/ci_access/filter_service_spec.rb @@ -2,16 +2,16 @@ require 'spec_helper' -RSpec.describe Clusters::Agents::FilterAuthorizationsService, feature_category: :continuous_integration do +RSpec.describe Clusters::Agents::Authorizations::CiAccess::FilterService, feature_category: :continuous_integration do describe '#execute' do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, group: group) } let(:agent_authorizations_without_env) do [ - build(:agent_project_authorization, project: project, agent: build(:cluster_agent, project: project)), - build(:agent_group_authorization, group: group, agent: build(:cluster_agent, project: project)), - ::Clusters::Agents::ImplicitAuthorization.new(agent: build(:cluster_agent, project: project)) + build(:agent_ci_access_project_authorization, project: project, agent: build(:cluster_agent, project: project)), + build(:agent_ci_access_group_authorization, group: group, agent: build(:cluster_agent, project: project)), + ::Clusters::Agents::Authorizations::CiAccess::ImplicitAuthorization.new(agent: build(:cluster_agent, project: project)) ] end @@ -31,13 +31,13 @@ RSpec.describe Clusters::Agents::FilterAuthorizationsService, feature_category: let(:agent_authorizations_with_env) do [ build( - :agent_project_authorization, + :agent_ci_access_project_authorization, project: project, agent: build(:cluster_agent, project: project), environments: ['staging', 'review/*', 'production'] ), build( - :agent_group_authorization, + :agent_ci_access_group_authorization, group: group, agent: build(:cluster_agent, project: project), environments: ['staging', 'review/*', 'production'] @@ -48,13 +48,13 @@ RSpec.describe Clusters::Agents::FilterAuthorizationsService, feature_category: let(:agent_authorizations_with_different_env) do [ build( - :agent_project_authorization, + :agent_ci_access_project_authorization, project: project, agent: build(:cluster_agent, project: project), environments: ['staging'] ), build( - :agent_group_authorization, + :agent_ci_access_group_authorization, group: group, agent: build(:cluster_agent, project: project), environments: ['staging'] diff --git a/spec/services/clusters/agents/refresh_authorization_service_spec.rb b/spec/services/clusters/agents/authorizations/ci_access/refresh_service_spec.rb index 51c054ddc98..c12592cc071 100644 --- a/spec/services/clusters/agents/refresh_authorization_service_spec.rb +++ b/spec/services/clusters/agents/authorizations/ci_access/refresh_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Agents::RefreshAuthorizationService, feature_category: :kubernetes_management do +RSpec.describe Clusters::Agents::Authorizations::CiAccess::RefreshService, feature_category: :deployment_management do describe '#execute' do let_it_be(:root_ancestor) { create(:group) } @@ -39,11 +39,11 @@ RSpec.describe Clusters::Agents::RefreshAuthorizationService, feature_category: before do default_config = { default_namespace: 'default' } - agent.group_authorizations.create!(group: removed_group, config: default_config) - agent.group_authorizations.create!(group: modified_group, config: default_config) + agent.ci_access_group_authorizations.create!(group: removed_group, config: default_config) + agent.ci_access_group_authorizations.create!(group: modified_group, config: default_config) - agent.project_authorizations.create!(project: removed_project, config: default_config) - agent.project_authorizations.create!(project: modified_project, config: default_config) + agent.ci_access_project_authorizations.create!(project: removed_project, config: default_config) + agent.ci_access_project_authorizations.create!(project: modified_project, config: default_config) end shared_examples 'removing authorization' do @@ -78,12 +78,12 @@ RSpec.describe Clusters::Agents::RefreshAuthorizationService, feature_category: describe 'group authorization' do it 'refreshes authorizations for the agent' do expect(subject).to be_truthy - expect(agent.authorized_groups).to contain_exactly(added_group, modified_group) + expect(agent.ci_access_authorized_groups).to contain_exactly(added_group, modified_group) - added_authorization = agent.group_authorizations.find_by(group: added_group) + added_authorization = agent.ci_access_group_authorizations.find_by(group: added_group) expect(added_authorization.config).to eq({ 'default_namespace' => 'default' }) - modified_authorization = agent.group_authorizations.find_by(group: modified_group) + modified_authorization = agent.ci_access_group_authorizations.find_by(group: modified_group) expect(modified_authorization.config).to eq({ 'default_namespace' => 'new-namespace' }) end @@ -94,24 +94,24 @@ RSpec.describe Clusters::Agents::RefreshAuthorizationService, feature_category: it 'authorizes groups up to the limit' do expect(subject).to be_truthy - expect(agent.authorized_groups).to contain_exactly(added_group) + expect(agent.ci_access_authorized_groups).to contain_exactly(added_group) end end include_examples 'removing authorization' do - let(:authorizations) { agent.authorized_groups } + let(:authorizations) { agent.ci_access_authorized_groups } end end describe 'project authorization' do it 'refreshes authorizations for the agent' do expect(subject).to be_truthy - expect(agent.authorized_projects).to contain_exactly(added_project, modified_project) + expect(agent.ci_access_authorized_projects).to contain_exactly(added_project, modified_project) - added_authorization = agent.project_authorizations.find_by(project: added_project) + added_authorization = agent.ci_access_project_authorizations.find_by(project: added_project) expect(added_authorization.config).to eq({ 'default_namespace' => 'default' }) - modified_authorization = agent.project_authorizations.find_by(project: modified_project) + modified_authorization = agent.ci_access_project_authorizations.find_by(project: modified_project) expect(modified_authorization.config).to eq({ 'default_namespace' => 'new-namespace' }) end @@ -121,7 +121,7 @@ RSpec.describe Clusters::Agents::RefreshAuthorizationService, feature_category: it 'creates an authorization record for the project' do expect(subject).to be_truthy - expect(agent.authorized_projects).to contain_exactly(added_project) + expect(agent.ci_access_authorized_projects).to contain_exactly(added_project) end end @@ -131,7 +131,7 @@ RSpec.describe Clusters::Agents::RefreshAuthorizationService, feature_category: it 'creates an authorization record for the project' do expect(subject).to be_truthy - expect(agent.authorized_projects).to contain_exactly(added_project) + expect(agent.ci_access_authorized_projects).to contain_exactly(added_project) end end @@ -142,12 +142,12 @@ RSpec.describe Clusters::Agents::RefreshAuthorizationService, feature_category: it 'authorizes projects up to the limit' do expect(subject).to be_truthy - expect(agent.authorized_projects).to contain_exactly(added_project) + expect(agent.ci_access_authorized_projects).to contain_exactly(added_project) end end include_examples 'removing authorization' do - let(:authorizations) { agent.authorized_projects } + let(:authorizations) { agent.ci_access_authorized_projects } end end end diff --git a/spec/services/clusters/agents/authorizations/user_access/refresh_service_spec.rb b/spec/services/clusters/agents/authorizations/user_access/refresh_service_spec.rb new file mode 100644 index 00000000000..da546ca44a9 --- /dev/null +++ b/spec/services/clusters/agents/authorizations/user_access/refresh_service_spec.rb @@ -0,0 +1,181 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Clusters::Agents::Authorizations::UserAccess::RefreshService, feature_category: :deployment_management do + describe '#execute' do + let_it_be(:root_ancestor) { create(:group) } + let_it_be(:agent_management_project) { create(:project, namespace: root_ancestor) } + let_it_be(:group_1) { create(:group, path: 'group-path-with-UPPERCASE', parent: root_ancestor) } + let_it_be(:group_2) { create(:group, parent: root_ancestor) } + let_it_be(:project_1) { create(:project, path: 'project-path-with-UPPERCASE', namespace: root_ancestor) } + let_it_be(:project_2) { create(:project, namespace: root_ancestor) } + + let(:agent) { create(:cluster_agent, project: agent_management_project) } + + let(:config) do + { + user_access: { + groups: [ + { id: group_2.full_path } + ], + projects: [ + { id: project_2.full_path } + ] + } + }.deep_merge(extra_config).deep_stringify_keys + end + + let(:extra_config) { {} } + + subject { described_class.new(agent, config: config).execute } + + before do + agent.user_access_group_authorizations.create!(group: group_1, config: {}) + agent.user_access_project_authorizations.create!(project: project_1, config: {}) + end + + shared_examples 'removing authorization' do + context 'when config contains no groups or projects' do + let(:config) { {} } + + it 'removes all authorizations' do + expect(subject).to be_truthy + expect(authorizations).to be_empty + end + end + + context 'when config contains groups or projects outside of the configuration project hierarchy' do + let_it_be(:agent_management_project) { create(:project, namespace: create(:group)) } + + it 'removes all authorizations' do + expect(subject).to be_truthy + expect(authorizations).to be_empty + end + end + + context 'when configuration project does not belong to a group' do + let_it_be(:agent_management_project) { create(:project) } + + it 'removes all authorizations' do + expect(subject).to be_truthy + expect(authorizations).to be_empty + end + end + end + + describe 'group authorization' do + it 'refreshes authorizations for the agent' do + expect(subject).to be_truthy + expect(agent.user_access_authorized_groups).to contain_exactly(group_2) + + added_authorization = agent.user_access_group_authorizations.find_by(group: group_2) + expect(added_authorization.config).to eq({}) + end + + context 'when config contains "access_as" keyword' do + let(:extra_config) do + { + user_access: { + access_as: { + agent: {} + } + } + } + end + + it 'refreshes authorizations for the agent' do + expect(subject).to be_truthy + expect(agent.user_access_authorized_groups).to contain_exactly(group_2) + + added_authorization = agent.user_access_group_authorizations.find_by(group: group_2) + expect(added_authorization.config).to eq({ 'access_as' => { 'agent' => {} } }) + end + end + + context 'when config contains too many groups' do + before do + stub_const("#{described_class}::AUTHORIZED_ENTITY_LIMIT", 0) + end + + it 'authorizes groups up to the limit' do + expect(subject).to be_truthy + expect(agent.user_access_authorized_groups).to be_empty + end + end + + include_examples 'removing authorization' do + let(:authorizations) { agent.user_access_authorized_groups } + end + end + + describe 'project authorization' do + it 'refreshes authorizations for the agent' do + expect(subject).to be_truthy + expect(agent.user_access_authorized_projects).to contain_exactly(project_2) + + added_authorization = agent.user_access_project_authorizations.find_by(project: project_2) + expect(added_authorization.config).to eq({}) + end + + context 'when config contains "access_as" keyword' do + let(:extra_config) do + { + user_access: { + access_as: { + agent: {} + } + } + } + end + + it 'refreshes authorizations for the agent' do + expect(subject).to be_truthy + expect(agent.user_access_authorized_projects).to contain_exactly(project_2) + + added_authorization = agent.user_access_project_authorizations.find_by(project: project_2) + expect(added_authorization.config).to eq({ 'access_as' => { 'agent' => {} } }) + end + end + + context 'when project belongs to a user namespace, and is in the same namespace as the agent' do + let_it_be(:root_ancestor) { create(:namespace) } + let_it_be(:agent_management_project) { create(:project, namespace: root_ancestor) } + let_it_be(:project_1) { create(:project, path: 'project-path-with-UPPERCASE', namespace: root_ancestor) } + let_it_be(:project_2) { create(:project, namespace: root_ancestor) } + + it 'creates an authorization record for the project' do + expect(subject).to be_truthy + expect(agent.user_access_authorized_projects).to contain_exactly(project_2) + end + end + + context 'when project belongs to a user namespace, and is authorizing itself' do + let_it_be(:root_ancestor) { create(:namespace) } + let_it_be(:agent_management_project) { create(:project, namespace: root_ancestor) } + let_it_be(:project_1) { create(:project, path: 'project-path-with-UPPERCASE', namespace: root_ancestor) } + let_it_be(:project_2) { agent_management_project } + + it 'creates an authorization record for the project' do + expect(subject).to be_truthy + expect(agent.user_access_authorized_projects).to contain_exactly(project_2) + end + end + + context 'when config contains too many projects' do + before do + stub_const("#{described_class}::AUTHORIZED_ENTITY_LIMIT", 0) + end + + it 'authorizes projects up to the limit' do + expect(subject).to be_truthy + expect(agent.user_access_authorized_projects).to be_empty + end + end + + include_examples 'removing authorization' do + let(:authorizations) { agent.user_access_authorized_projects } + end + end + end +end diff --git a/spec/services/clusters/agents/authorize_proxy_user_service_spec.rb b/spec/services/clusters/agents/authorize_proxy_user_service_spec.rb new file mode 100644 index 00000000000..2d6c79c5cb3 --- /dev/null +++ b/spec/services/clusters/agents/authorize_proxy_user_service_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Clusters::Agents::AuthorizeProxyUserService, feature_category: :deployment_management do + subject(:service_response) { service.execute } + + let(:service) { described_class.new(user, agent) } + let(:user) { create(:user) } + + let_it_be(:organization) { create(:group) } + let_it_be(:configuration_project) { create(:project, group: organization) } + let_it_be(:agent) { create(:cluster_agent, name: 'the-agent', project: configuration_project) } + let_it_be(:deployment_project) { create(:project, group: organization) } + let_it_be(:deployment_group) { create(:group, parent: organization) } + + let(:user_access_config) do + { + 'user_access' => { + 'access_as' => { 'agent' => {} }, + 'projects' => [{ 'id' => deployment_project.full_path }], + 'groups' => [{ 'id' => deployment_group.full_path }] + } + } + end + + before do + Clusters::Agents::Authorizations::UserAccess::RefreshService.new(agent, config: user_access_config).execute + end + + it 'returns forbidden when user has no access to any project', :aggregate_failures do + expect(service_response).to be_error + expect(service_response.reason).to eq :forbidden + end + + context 'when user is member of an authorized group' do + it 'authorizes developers', :aggregate_failures do + deployment_group.add_member(user, :developer) + expect(service_response).to be_success + expect(service_response.payload[:user]).to include(id: user.id, username: user.username) + expect(service_response.payload[:agent]).to include(id: agent.id, config_project: { id: agent.project.id }) + end + + it 'does not authorize reporters', :aggregate_failures do + deployment_group.add_member(user, :reporter) + expect(service_response).to be_error + expect(service_response.reason).to eq :forbidden + end + end + + context 'when user is member of an authorized project' do + it 'authorizes developers', :aggregate_failures do + deployment_project.add_member(user, :developer) + expect(service_response).to be_success + expect(service_response.payload[:user]).to include(id: user.id, username: user.username) + expect(service_response.payload[:agent]).to include(id: agent.id, config_project: { id: agent.project.id }) + end + + it 'does not authorize reporters', :aggregate_failures do + deployment_project.add_member(user, :reporter) + expect(service_response).to be_error + expect(service_response.reason).to eq :forbidden + end + end +end diff --git a/spec/services/clusters/agents/create_activity_event_service_spec.rb b/spec/services/clusters/agents/create_activity_event_service_spec.rb index 7a8f0e16d60..0d784bb69c7 100644 --- a/spec/services/clusters/agents/create_activity_event_service_spec.rb +++ b/spec/services/clusters/agents/create_activity_event_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Agents::CreateActivityEventService do +RSpec.describe Clusters::Agents::CreateActivityEventService, feature_category: :deployment_management do let_it_be(:agent) { create(:cluster_agent) } let_it_be(:token) { create(:cluster_agent_token, agent: agent) } let_it_be(:user) { create(:user) } @@ -40,5 +40,16 @@ RSpec.describe Clusters::Agents::CreateActivityEventService do subject end + + context 'when activity event creation fails' do + let(:params) { {} } + + it 'tracks the exception without raising' do + expect(Gitlab::ErrorTracking).to receive(:track_exception) + .with(instance_of(ActiveRecord::RecordInvalid), agent_id: agent.id) + + subject + end + end end end diff --git a/spec/services/clusters/agents/create_service_spec.rb b/spec/services/clusters/agents/create_service_spec.rb index 2b3bbcae13c..85607fcdf3a 100644 --- a/spec/services/clusters/agents/create_service_spec.rb +++ b/spec/services/clusters/agents/create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Agents::CreateService do +RSpec.describe Clusters::Agents::CreateService, feature_category: :deployment_management do subject(:service) { described_class.new(project, user) } let(:project) { create(:project, :public, :repository) } diff --git a/spec/services/clusters/agents/delete_expired_events_service_spec.rb b/spec/services/clusters/agents/delete_expired_events_service_spec.rb index 3dc166f54eb..7dc9c280ab4 100644 --- a/spec/services/clusters/agents/delete_expired_events_service_spec.rb +++ b/spec/services/clusters/agents/delete_expired_events_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Agents::DeleteExpiredEventsService do +RSpec.describe Clusters::Agents::DeleteExpiredEventsService, feature_category: :deployment_management do let_it_be(:agent) { create(:cluster_agent) } describe '#execute' do diff --git a/spec/services/clusters/agents/delete_service_spec.rb b/spec/services/clusters/agents/delete_service_spec.rb index abe1bdaab27..febbb7ba5c8 100644 --- a/spec/services/clusters/agents/delete_service_spec.rb +++ b/spec/services/clusters/agents/delete_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Agents::DeleteService do +RSpec.describe Clusters::Agents::DeleteService, feature_category: :deployment_management do subject(:service) { described_class.new(container: project, current_user: user) } let(:cluster_agent) { create(:cluster_agent) } diff --git a/spec/services/clusters/build_kubernetes_namespace_service_spec.rb b/spec/services/clusters/build_kubernetes_namespace_service_spec.rb index 4ee933374f6..fea17495914 100644 --- a/spec/services/clusters/build_kubernetes_namespace_service_spec.rb +++ b/spec/services/clusters/build_kubernetes_namespace_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::BuildKubernetesNamespaceService do +RSpec.describe Clusters::BuildKubernetesNamespaceService, feature_category: :deployment_management do let(:cluster) { create(:cluster, :project, :provided_by_gcp) } let(:environment) { create(:environment) } let(:project) { environment.project } diff --git a/spec/services/clusters/build_service_spec.rb b/spec/services/clusters/build_service_spec.rb index c7a64435d3b..909d3f58c48 100644 --- a/spec/services/clusters/build_service_spec.rb +++ b/spec/services/clusters/build_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::BuildService do +RSpec.describe Clusters::BuildService, feature_category: :deployment_management do describe '#execute' do subject { described_class.new(cluster_subject).execute } diff --git a/spec/services/clusters/cleanup/project_namespace_service_spec.rb b/spec/services/clusters/cleanup/project_namespace_service_spec.rb index 8d3ae217a9f..34311d6e830 100644 --- a/spec/services/clusters/cleanup/project_namespace_service_spec.rb +++ b/spec/services/clusters/cleanup/project_namespace_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Cleanup::ProjectNamespaceService do +RSpec.describe Clusters::Cleanup::ProjectNamespaceService, feature_category: :deployment_management do describe '#execute' do subject { service.execute } diff --git a/spec/services/clusters/cleanup/service_account_service_spec.rb b/spec/services/clusters/cleanup/service_account_service_spec.rb index 769762237f9..f5a3c2e8eb1 100644 --- a/spec/services/clusters/cleanup/service_account_service_spec.rb +++ b/spec/services/clusters/cleanup/service_account_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Cleanup::ServiceAccountService do +RSpec.describe Clusters::Cleanup::ServiceAccountService, feature_category: :deployment_management do describe '#execute' do subject { service.execute } @@ -55,14 +55,16 @@ RSpec.describe Clusters::Cleanup::ServiceAccountService do context 'when there is a Kubeclient::HttpError' do ['Unauthorized', 'forbidden', 'Certificate verify Failed'].each do |message| - before do - allow(kubeclient_instance_double) - .to receive(:delete_service_account) - .and_raise(Kubeclient::HttpError.new(401, message, nil)) - end + context "with error:#{message}" do + before do + allow(kubeclient_instance_double) + .to receive(:delete_service_account) + .and_raise(Kubeclient::HttpError.new(401, message, nil)) + end - it 'destroys cluster' do - expect { subject }.to change { Clusters::Cluster.where(id: cluster.id).exists? }.from(true).to(false) + it 'destroys cluster' do + expect { subject }.to change { Clusters::Cluster.where(id: cluster.id).exists? }.from(true).to(false) + end end end end diff --git a/spec/services/clusters/create_service_spec.rb b/spec/services/clusters/create_service_spec.rb index 95f10cdbd80..e130f713cb2 100644 --- a/spec/services/clusters/create_service_spec.rb +++ b/spec/services/clusters/create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::CreateService do +RSpec.describe Clusters::CreateService, feature_category: :deployment_management do let(:access_token) { 'xxx' } let(:project) { create(:project) } let(:user) { create(:user) } @@ -50,7 +50,7 @@ RSpec.describe Clusters::CreateService do end context 'when project has a cluster' do - include_context 'valid cluster create params' + include_context 'with valid cluster create params' let!(:cluster) { create(:cluster, :provided_by_gcp, :production_environment, projects: [project]) } it 'creates another cluster' do diff --git a/spec/services/clusters/destroy_service_spec.rb b/spec/services/clusters/destroy_service_spec.rb index dc600c9e830..dd3e24d0e12 100644 --- a/spec/services/clusters/destroy_service_spec.rb +++ b/spec/services/clusters/destroy_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::DestroyService do +RSpec.describe Clusters::DestroyService, feature_category: :deployment_management do describe '#execute' do subject { described_class.new(cluster.user, params).execute(cluster) } diff --git a/spec/services/clusters/integrations/create_service_spec.rb b/spec/services/clusters/integrations/create_service_spec.rb index 9104e07504d..b716e4f4651 100644 --- a/spec/services/clusters/integrations/create_service_spec.rb +++ b/spec/services/clusters/integrations/create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Integrations::CreateService, '#execute' do +RSpec.describe Clusters::Integrations::CreateService, '#execute', feature_category: :deployment_management do let_it_be(:project) { create(:project) } let_it_be_with_reload(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } diff --git a/spec/services/clusters/integrations/prometheus_health_check_service_spec.rb b/spec/services/clusters/integrations/prometheus_health_check_service_spec.rb index 526462931a6..9390d4b368b 100644 --- a/spec/services/clusters/integrations/prometheus_health_check_service_spec.rb +++ b/spec/services/clusters/integrations/prometheus_health_check_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Integrations::PrometheusHealthCheckService, '#execute' do +RSpec.describe Clusters::Integrations::PrometheusHealthCheckService, '#execute', feature_category: :deployment_management do let(:service) { described_class.new(cluster) } subject { service.execute } diff --git a/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb b/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb index 90956e7b4ea..48941792c4b 100644 --- a/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb +++ b/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' do +RSpec.describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute', feature_category: :deployment_management do include KubernetesHelpers let(:cluster) { create(:cluster, :project, :provided_by_gcp) } @@ -11,7 +11,7 @@ RSpec.describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' let(:project) { cluster.project } let(:environment) { create(:environment, project: project) } let(:cluster_project) { cluster.cluster_project } - let(:namespace) { "#{project.name}-#{project.id}-#{environment.slug}" } + let(:namespace) { "#{project.path}-#{project.id}-#{environment.slug}" } subject do described_class.new( diff --git a/spec/services/clusters/kubernetes/create_or_update_service_account_service_spec.rb b/spec/services/clusters/kubernetes/create_or_update_service_account_service_spec.rb index 37478a0bcd9..ab0c5691b06 100644 --- a/spec/services/clusters/kubernetes/create_or_update_service_account_service_spec.rb +++ b/spec/services/clusters/kubernetes/create_or_update_service_account_service_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Clusters::Kubernetes::CreateOrUpdateServiceAccountService do +RSpec.describe Clusters::Kubernetes::CreateOrUpdateServiceAccountService, feature_category: :deployment_management do include KubernetesHelpers let(:api_url) { 'http://111.111.111.111' } diff --git a/spec/services/clusters/kubernetes/fetch_kubernetes_token_service_spec.rb b/spec/services/clusters/kubernetes/fetch_kubernetes_token_service_spec.rb index 03c402fb066..439dc37e684 100644 --- a/spec/services/clusters/kubernetes/fetch_kubernetes_token_service_spec.rb +++ b/spec/services/clusters/kubernetes/fetch_kubernetes_token_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Kubernetes::FetchKubernetesTokenService do +RSpec.describe Clusters::Kubernetes::FetchKubernetesTokenService, feature_category: :deployment_management do include KubernetesHelpers describe '#execute' do diff --git a/spec/services/clusters/kubernetes_spec.rb b/spec/services/clusters/kubernetes_spec.rb index 12af63890fc..cd430f81a65 100644 --- a/spec/services/clusters/kubernetes_spec.rb +++ b/spec/services/clusters/kubernetes_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Kubernetes do +RSpec.describe Clusters::Kubernetes, feature_category: :deployment_management do it { is_expected.to be_const_defined(:GITLAB_SERVICE_ACCOUNT_NAME) } it { is_expected.to be_const_defined(:GITLAB_SERVICE_ACCOUNT_NAMESPACE) } it { is_expected.to be_const_defined(:GITLAB_ADMIN_TOKEN_NAME) } diff --git a/spec/services/clusters/management/validate_management_project_permissions_service_spec.rb b/spec/services/clusters/management/validate_management_project_permissions_service_spec.rb index a21c378d3d1..46032de600d 100644 --- a/spec/services/clusters/management/validate_management_project_permissions_service_spec.rb +++ b/spec/services/clusters/management/validate_management_project_permissions_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Management::ValidateManagementProjectPermissionsService do +RSpec.describe Clusters::Management::ValidateManagementProjectPermissionsService, feature_category: :deployment_management do describe '#execute' do subject { described_class.new(user).execute(cluster, management_project_id) } diff --git a/spec/services/clusters/update_service_spec.rb b/spec/services/clusters/update_service_spec.rb index 9aead97f41c..cc759407376 100644 --- a/spec/services/clusters/update_service_spec.rb +++ b/spec/services/clusters/update_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::UpdateService do +RSpec.describe Clusters::UpdateService, feature_category: :deployment_management do include KubernetesHelpers describe '#execute' do |
