Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/services')
-rw-r--r--spec/support/shared_examples/services/container_registry_auth_service_shared_examples.rb28
-rw-r--r--spec/support/shared_examples/services/import_csv_service_shared_examples.rb12
-rw-r--r--spec/support/shared_examples/services/issuable/issuable_update_service_shared_examples.rb81
-rw-r--r--spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb80
-rw-r--r--spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb21
-rw-r--r--spec/support/shared_examples/services/namespace_package_settings_shared_examples.rb4
-rw-r--r--spec/support/shared_examples/services/notification_service_shared_examples.rb10
-rw-r--r--spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb30
8 files changed, 183 insertions, 83 deletions
diff --git a/spec/support/shared_examples/services/container_registry_auth_service_shared_examples.rb b/spec/support/shared_examples/services/container_registry_auth_service_shared_examples.rb
index 493a96b8dae..34188a8d18a 100644
--- a/spec/support/shared_examples/services/container_registry_auth_service_shared_examples.rb
+++ b/spec/support/shared_examples/services/container_registry_auth_service_shared_examples.rb
@@ -58,6 +58,12 @@ RSpec.shared_examples 'with auth_type' do
let(:current_params) { super().merge(auth_type: :foo) }
it { expect(payload['auth_type']).to eq('foo') }
+
+ it "contains the auth_type as part of the encoded user information in the payload" do
+ user_info = decode_user_info_from_payload(payload)
+
+ expect(user_info["token_type"]).to eq("foo")
+ end
end
RSpec.shared_examples 'a browsable' do
@@ -971,7 +977,16 @@ RSpec.shared_examples 'a container registry auth service' do
let(:authentication_abilities) { [:read_container_image] }
it_behaves_like 'an authenticated'
+
it { expect(payload['auth_type']).to eq('deploy_token') }
+
+ it "has encoded user information in the payload" do
+ user_info = decode_user_info_from_payload(payload)
+
+ expect(user_info["token_type"]).to eq('deploy_token')
+ expect(user_info["username"]).to eq(deploy_token.username)
+ expect(user_info["deploy_token_id"]).to eq(deploy_token.id)
+ end
end
end
@@ -1198,6 +1213,15 @@ RSpec.shared_examples 'a container registry auth service' do
it_behaves_like 'a pushable'
it_behaves_like 'container repository factory'
end
+
+ it "has encoded user information in the payload" do
+ user_info = decode_user_info_from_payload(payload)
+
+ expect(user_info["username"]).to eq(current_user.username)
+ expect(user_info["user_id"]).to eq(current_user.id)
+ end
+
+ it_behaves_like 'with auth_type'
end
end
@@ -1293,4 +1317,8 @@ RSpec.shared_examples 'a container registry auth service' do
end
end
end
+
+ def decode_user_info_from_payload(payload)
+ JWT.decode(payload["user"], nil, false)[0]["user_info"]
+ end
end
diff --git a/spec/support/shared_examples/services/import_csv_service_shared_examples.rb b/spec/support/shared_examples/services/import_csv_service_shared_examples.rb
index 1555497ae48..b09d087f518 100644
--- a/spec/support/shared_examples/services/import_csv_service_shared_examples.rb
+++ b/spec/support/shared_examples/services/import_csv_service_shared_examples.rb
@@ -36,3 +36,15 @@ RSpec.shared_examples 'correctly handles invalid files' do
it_behaves_like 'invalid file'
end
end
+
+RSpec.shared_examples 'performs a spam check' do |perform_check|
+ it 'initializes issue create service with expected spam check parameter' do
+ expect(Issues::CreateService)
+ .to receive(:new)
+ .at_least(:once)
+ .with(hash_including(perform_spam_check: perform_check))
+ .and_call_original
+
+ subject
+ end
+end
diff --git a/spec/support/shared_examples/services/issuable/issuable_update_service_shared_examples.rb b/spec/support/shared_examples/services/issuable/issuable_update_service_shared_examples.rb
index 85a05bbe56d..3f95d6060ea 100644
--- a/spec/support/shared_examples/services/issuable/issuable_update_service_shared_examples.rb
+++ b/spec/support/shared_examples/services/issuable/issuable_update_service_shared_examples.rb
@@ -64,6 +64,87 @@ RSpec.shared_examples 'issuable update service' do
end
end
+RSpec.shared_examples 'updating issuable labels' do
+ context 'when add_label_ids and label_ids are passed' do
+ let(:params) { { label_ids: [label_a.id], add_label_ids: [label_c.id] } }
+
+ it 'replaces the labels with the ones in label_ids and adds those in add_label_ids' do
+ issuable.update!(labels: [label_b])
+ update_issuable(params)
+
+ expect(issuable.label_ids).to contain_exactly(label_a.id, label_c.id)
+ end
+ end
+
+ context 'when remove_label_ids and label_ids are passed' do
+ let(:params) { { label_ids: [label_a.id, label_b.id, label_c.id], remove_label_ids: [label_a.id] } }
+
+ it 'replaces the labels with the ones in label_ids and removes those in remove_label_ids' do
+ issuable.update!(labels: [label_a, label_c])
+ update_issuable(params)
+
+ expect(issuable.label_ids).to contain_exactly(label_b.id, label_c.id)
+ end
+ end
+
+ context 'when add_label_ids and remove_label_ids are passed' do
+ let(:params) { { add_label_ids: [label_c.id], remove_label_ids: [label_a.id] } }
+
+ before do
+ issuable.update!(labels: [label_a])
+ update_issuable(params)
+ end
+
+ it 'adds the passed labels' do
+ expect(issuable.label_ids).to include(label_c.id)
+ end
+
+ it 'removes the passed labels' do
+ expect(issuable.label_ids).not_to include(label_a.id)
+ end
+ end
+
+ context 'when same id is passed as add_label_ids and remove_label_ids' do
+ let(:params) { { add_label_ids: [label_a.id], remove_label_ids: [label_a.id] } }
+
+ context 'for a label assigned to an issue' do
+ it 'removes the label' do
+ issuable.update!(labels: [label_a])
+ update_issuable(params)
+
+ expect(issuable.label_ids).to be_empty
+ end
+ end
+
+ context 'for a label not assigned to an issue' do
+ it 'does not add the label' do
+ expect(issuable.label_ids).to be_empty
+ end
+ end
+ end
+
+ context 'when duplicate label titles are given' do
+ let(:params) { { labels: [label_c.title, label_c.title] } }
+
+ it 'assigns the label once' do
+ update_issuable(params)
+
+ expect(issuable.labels).to contain_exactly(label_c)
+ end
+ end
+
+ context 'when remove_label_ids contains a locked label' do
+ let(:params) { { remove_label_ids: [label_locked.id] } }
+
+ it 'removes locked labels for non-merged issuables' do
+ issuable.update!(labels: [label_a, label_locked])
+ update_issuable(params)
+
+ expect(issuable.label_ids).to contain_exactly(label_a.id)
+ end
+ end
+end
+
RSpec.shared_examples 'keeps issuable labels sorted after update' do
before do
update_issuable(label_ids: [label_b.id])
diff --git a/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb b/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb
index 0bf8bc4ff04..83a2f3136b4 100644
--- a/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb
+++ b/spec/support/shared_examples/services/issuable_links/create_links_shared_examples.rb
@@ -1,16 +1,30 @@
# frozen_string_literal: true
-RSpec.shared_examples 'issuable link creation' do
+RSpec.shared_examples 'issuable link creation' do |use_references: true|
+ let(:items_param) { use_references ? :issuable_references : :target_issuable }
+ let(:response_keys) { [:status, :created_references] }
+ let(:already_assigned_error_msg) { "#{issuable_type.capitalize}(s) already assigned" }
+ let(:permission_error_status) { issuable_type == :issue ? 403 : 404 }
+ let(:permission_error_msg) do
+ if issuable_type == :issue
+ "Couldn't link issue. You must have at least the Reporter role in both projects."
+ else
+ no_found_error_msg
+ end
+ end
+
+ let(:no_found_error_msg) do
+ "No matching #{issuable_type} found. Make sure that you are adding a valid #{issuable_type} URL."
+ end
+
describe '#execute' do
subject { described_class.new(issuable, user, params).execute }
- context 'when the reference list is empty' do
- let(:params) do
- { issuable_references: [] }
- end
+ context 'when the items list is empty' do
+ let(:params) { set_params([]) }
it 'returns error' do
- is_expected.to eq(message: "No matching #{issuable_type} found. Make sure that you are adding a valid #{issuable_type} URL.", status: :error, http_status: 404)
+ is_expected.to eq(message: no_found_error_msg, status: :error, http_status: 404)
end
end
@@ -20,7 +34,7 @@ RSpec.shared_examples 'issuable link creation' do
end
it 'returns error' do
- is_expected.to eq(message: "No matching #{issuable_type} found. Make sure that you are adding a valid #{issuable_type} URL.", status: :error, http_status: 404)
+ is_expected.to eq(message: no_found_error_msg, status: :error, http_status: 404)
end
it 'no relationship is created' do
@@ -29,16 +43,10 @@ RSpec.shared_examples 'issuable link creation' do
end
context 'when user has no permission to target issuable' do
- let(:params) do
- { issuable_references: [restricted_issuable.to_reference(issuable_parent)] }
- end
+ let(:params) { set_params([restricted_issuable]) }
it 'returns error' do
- if issuable_type == :issue
- is_expected.to eq(message: "Couldn't link #{issuable_type}. You must have at least the Reporter role in both projects.", status: :error, http_status: 403)
- else
- is_expected.to eq(message: "No matching #{issuable_type} found. Make sure that you are adding a valid #{issuable_type} URL.", status: :error, http_status: 404)
- end
+ is_expected.to eq(message: permission_error_msg, status: :error, http_status: permission_error_status)
end
it 'no relationship is created' do
@@ -47,9 +55,7 @@ RSpec.shared_examples 'issuable link creation' do
end
context 'source and target are the same issuable' do
- let(:params) do
- { issuable_references: [issuable.to_reference] }
- end
+ let(:params) { set_params([issuable]) }
it 'does not create notes' do
expect(SystemNoteService).not_to receive(:relate_issuable)
@@ -63,9 +69,7 @@ RSpec.shared_examples 'issuable link creation' do
end
context 'when there is an issuable to relate' do
- let(:params) do
- { issuable_references: [issuable2.to_reference, issuable3.to_reference(issuable_parent)] }
- end
+ let(:params) { set_params([issuable2, issuable3]) }
it 'creates relationships' do
expect { subject }.to change { issuable_link_class.count }.by(2)
@@ -75,7 +79,7 @@ RSpec.shared_examples 'issuable link creation' do
end
it 'returns success status and created links', :aggregate_failures do
- expect(subject.keys).to match_array([:status, :created_references])
+ expect(subject.keys).to match_array(response_keys)
expect(subject[:status]).to eq(:success)
expect(subject[:created_references].map(&:target_id)).to match_array([issuable2.id, issuable3.id])
end
@@ -98,15 +102,7 @@ RSpec.shared_examples 'issuable link creation' do
end
context 'when reference of any already related issue is present' do
- let(:params) do
- {
- issuable_references: [
- issuable_a.to_reference,
- issuable_b.to_reference
- ],
- link_type: IssueLink::TYPE_RELATES_TO
- }
- end
+ let(:params) { set_params([issuable_a, issuable_b]) }
it 'creates notes only for new relations' do
expect(SystemNoteService).to receive(:relate_issuable).with(issuable, issuable_a, anything)
@@ -118,22 +114,18 @@ RSpec.shared_examples 'issuable link creation' do
end
end
- context 'when there are invalid references' do
- let(:params) do
- { issuable_references: [issuable.to_reference, issuable_a.to_reference] }
- end
-
- it 'creates links only for valid references' do
- expect { subject }.to change { issuable_link_class.count }.by(1)
- end
+ context 'when reference of all related issue are present' do
+ let(:params) { set_params([issuable_b]) }
it 'returns error status' do
- expect(subject).to eq(
- status: :error,
- http_status: 422,
- message: "#{issuable.to_reference} cannot be added: cannot be related to itself"
- )
+ expect(subject).to eq(status: :error, http_status: 409, message: already_assigned_error_msg)
end
end
end
+
+ def set_params(items)
+ items_list = items_param == :issuable_references ? items.map { |item| item.to_reference(issuable_parent) } : items
+
+ { items_param => items_list }
+ end
end
diff --git a/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb b/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb
index bdb01b12607..9b2e038a331 100644
--- a/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb
+++ b/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb
@@ -124,27 +124,6 @@ RSpec.shared_examples 'valid dashboard cloning process' do |dashboard_template,
end
end
-RSpec.shared_examples 'valid dashboard update process' do
- let(:dashboard_attrs) do
- {
- commit_message: commit_message,
- branch_name: branch,
- start_branch: project.default_branch,
- encoding: 'text',
- file_path: ".gitlab/dashboards/#{file_name}",
- file_content: ::PerformanceMonitoring::PrometheusDashboard.from_json(file_content_hash).to_yaml
- }
- end
-
- it 'delegates commit creation to Files::UpdateService', :aggregate_failures do
- service_instance = instance_double(::Files::UpdateService)
- expect(::Files::UpdateService).to receive(:new).with(project, user, dashboard_attrs).and_return(service_instance)
- expect(service_instance).to receive(:execute).and_return(status: :success)
-
- service_call
- end
-end
-
RSpec.shared_examples 'misconfigured dashboard service response with stepable' do |status_code, message = nil|
it 'returns an appropriate message and status code', :aggregate_failures do
result = service_call
diff --git a/spec/support/shared_examples/services/namespace_package_settings_shared_examples.rb b/spec/support/shared_examples/services/namespace_package_settings_shared_examples.rb
index 11a786fdefb..6f0fd1aa4ed 100644
--- a/spec/support/shared_examples/services/namespace_package_settings_shared_examples.rb
+++ b/spec/support/shared_examples/services/namespace_package_settings_shared_examples.rb
@@ -9,6 +9,8 @@ RSpec.shared_examples 'updating the namespace package setting attributes' do |to
.and change { namespace.package_settings.reload.maven_duplicate_exception_regex }.from(from[:maven_duplicate_exception_regex]).to(to[:maven_duplicate_exception_regex])
.and change { namespace.package_settings.reload.generic_duplicates_allowed }.from(from[:generic_duplicates_allowed]).to(to[:generic_duplicates_allowed])
.and change { namespace.package_settings.reload.generic_duplicate_exception_regex }.from(from[:generic_duplicate_exception_regex]).to(to[:generic_duplicate_exception_regex])
+ .and change { namespace.package_settings.reload.nuget_duplicates_allowed }.from(from[:nuget_duplicates_allowed]).to(to[:nuget_duplicates_allowed])
+ .and change { namespace.package_settings.reload.nuget_duplicate_exception_regex }.from(from[:nuget_duplicate_exception_regex]).to(to[:nuget_duplicate_exception_regex])
end
end
@@ -30,6 +32,8 @@ RSpec.shared_examples 'creating the namespace package setting' do
expect(namespace.package_setting_relation.maven_duplicate_exception_regex).to eq(package_settings[:maven_duplicate_exception_regex])
expect(namespace.package_setting_relation.generic_duplicates_allowed).to eq(package_settings[:generic_duplicates_allowed])
expect(namespace.package_setting_relation.generic_duplicate_exception_regex).to eq(package_settings[:generic_duplicate_exception_regex])
+ expect(namespace.package_setting_relation.nuget_duplicates_allowed).to eq(package_settings[:nuget_duplicates_allowed])
+ expect(namespace.package_setting_relation.nuget_duplicate_exception_regex).to eq(package_settings[:nuget_duplicate_exception_regex])
end
it_behaves_like 'returning a success'
diff --git a/spec/support/shared_examples/services/notification_service_shared_examples.rb b/spec/support/shared_examples/services/notification_service_shared_examples.rb
index cfd674e3c43..df1ae67a590 100644
--- a/spec/support/shared_examples/services/notification_service_shared_examples.rb
+++ b/spec/support/shared_examples/services/notification_service_shared_examples.rb
@@ -8,16 +8,16 @@ RSpec.shared_examples 'project emails are disabled' do |check_delivery_jobs_queu
before do
reset_delivered_emails!
- target_project.clear_memoization(:emails_disabled)
+ target_project.project_setting.clear_memoization(:emails_enabled?)
end
it 'sends no emails with project emails disabled' do
- target_project.update_attribute(:emails_disabled, true)
+ target_project.project_setting.update_attribute(:emails_enabled, false)
notification_trigger
if check_delivery_jobs_queue
- # Only check enqueud jobs, not delivered emails
+ # Only check enqueued jobs, not delivered emails
expect_no_delivery_jobs
else
# Deprecated: Check actual delivered emails
@@ -26,12 +26,12 @@ RSpec.shared_examples 'project emails are disabled' do |check_delivery_jobs_queu
end
it 'sends emails to someone' do
- target_project.update_attribute(:emails_disabled, false)
+ target_project.project_setting.update_attribute(:emails_enabled, true)
notification_trigger
if check_delivery_jobs_queue
- # Only check enqueud jobs, not delivered emails
+ # Only check enqueued jobs, not delivered emails
expect_any_delivery_jobs
else
# Deprecated: Check actual delivered emails
diff --git a/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb b/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb
index 21dc3c2bf70..fd2c7455c5f 100644
--- a/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb
+++ b/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb
@@ -111,11 +111,14 @@ RSpec.shared_examples_for 'services security ci configuration create service' do
YAML
end
- it 'fails with error' do
+ it 'returns a ServiceResponse error' do
expect(project).to receive(:ci_config_for).and_return(unsupported_yaml)
- expect { result }.to raise_error(Gitlab::Graphql::Errors::MutationError, Gitlab::Utils::ErrorMessage.to_user_facing(
- _(".gitlab-ci.yml with aliases/anchors is not supported. Please change the CI configuration manually.")))
+ expect(result).to be_kind_of(ServiceResponse)
+ expect(result.status).to eq(:error)
+ expect(result.message).to eq(
+ _(".gitlab-ci.yml with aliases/anchors is not supported. Please change the CI configuration manually.")
+ )
end
end
@@ -133,11 +136,13 @@ RSpec.shared_examples_for 'services security ci configuration create service' do
YAML
end
- it 'fails with error' do
+ it 'returns a ServiceResponse error' do
expect(project).to receive(:ci_config_for).and_return(invalid_yaml)
expect(YAML).to receive(:safe_load).and_raise(Psych::Exception)
- expect { result }.to raise_error(Gitlab::Graphql::Errors::MutationError, /merge request creation mutation failed/)
+ expect(result).to be_kind_of(ServiceResponse)
+ expect(result.status).to eq(:error)
+ expect(result.message).to match(/merge request creation failed/)
end
end
@@ -166,14 +171,13 @@ RSpec.shared_examples_for 'services security ci configuration create service' do
let(:params) { nil }
let_it_be(:project) { create(:project_empty_repo) }
- it 'returns an error' do
- expect { result }.to raise_error { |error|
- expect(error).to be_a(Gitlab::Graphql::Errors::MutationError)
- expect(error.message).to eq('UF You must <a target="_blank" rel="noopener noreferrer" ' \
- 'href="http://localhost/help/user/project/repository/index.md' \
- '#add-files-to-a-repository">add at least one file to the repository' \
- '</a> before using Security features.')
- }
+ it 'returns a ServiceResponse error' do
+ expect(result).to be_kind_of(ServiceResponse)
+ expect(result.status).to eq(:error)
+ expect(result.message).to eq('You must <a target="_blank" rel="noopener noreferrer" ' \
+ 'href="http://localhost/help/user/project/repository/index.md' \
+ '#add-files-to-a-repository">add at least one file to the repository' \
+ '</a> before using Security features.')
end
end
end