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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-28 15:10:09 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-28 15:10:09 +0300
commit0805030d634b48c8a44308330fe0d99ba8434f46 (patch)
treee4a345925e62addad4c5de4744493dc8a386c6ef /spec/services
parentd6024427e8036c93ccf04759a3725167ec6c02f4 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/security/ci_configuration/sast_create_service_spec.rb75
-rw-r--r--spec/services/security/ci_configuration/secret_detection_create_service_spec.rb19
-rw-r--r--spec/services/users/update_assigned_open_issue_count_service_spec.rb49
3 files changed, 84 insertions, 59 deletions
diff --git a/spec/services/security/ci_configuration/sast_create_service_spec.rb b/spec/services/security/ci_configuration/sast_create_service_spec.rb
index ff7ab614e08..44f8f07a5be 100644
--- a/spec/services/security/ci_configuration/sast_create_service_spec.rb
+++ b/spec/services/security/ci_configuration/sast_create_service_spec.rb
@@ -3,67 +3,24 @@
require 'spec_helper'
RSpec.describe Security::CiConfiguration::SastCreateService, :snowplow do
- describe '#execute' do
- let_it_be(:project) { create(:project, :repository) }
- let_it_be(:user) { create(:user) }
- let(:params) { {} }
+ subject(:result) { described_class.new(project, user, params).execute }
- subject(:result) { described_class.new(project, user, params).execute }
+ let(:branch_name) { 'set-sast-config-1' }
- context 'user does not belong to project' do
- it 'returns an error status' do
- expect(result[:status]).to eq(:error)
- expect(result[:success_path]).to be_nil
- end
-
- it 'does not track a snowplow event' do
- subject
-
- expect_no_snowplow_event
- end
- end
-
- context 'user belongs to project' do
- before do
- project.add_developer(user)
- end
-
- it 'does track the snowplow event' do
- subject
-
- expect_snowplow_event(
- category: 'Security::CiConfiguration::SastCreateService',
- action: 'create',
- label: 'false'
- )
- end
-
- it 'raises exception if the user does not have permission to create a new branch' do
- allow(project).to receive(:repository).and_raise(Gitlab::Git::PreReceiveError, "You are not allowed to create protected branches on this project.")
-
- expect { subject }.to raise_error(Gitlab::Git::PreReceiveError)
- end
-
- context 'with no parameters' do
- it 'returns the path to create a new merge request' do
- expect(result[:status]).to eq(:success)
- expect(result[:success_path]).to match(/#{Gitlab::Routing.url_helpers.project_new_merge_request_url(project, {})}(.*)description(.*)source_branch/)
- end
- end
-
- context 'with parameters' do
- let(:params) do
- { 'stage' => 'security',
- 'SEARCH_MAX_DEPTH' => 1,
- 'SECURE_ANALYZERS_PREFIX' => 'new_registry',
- 'SAST_EXCLUDED_PATHS' => 'spec,docs' }
- end
+ let(:non_empty_params) do
+ { 'stage' => 'security',
+ 'SEARCH_MAX_DEPTH' => 1,
+ 'SECURE_ANALYZERS_PREFIX' => 'new_registry',
+ 'SAST_EXCLUDED_PATHS' => 'spec,docs' }
+ end
- it 'returns the path to create a new merge request' do
- expect(result[:status]).to eq(:success)
- expect(result[:success_path]).to match(/#{Gitlab::Routing.url_helpers.project_new_merge_request_url(project, {})}(.*)description(.*)source_branch/)
- end
- end
- end
+ let(:snowplow_event) do
+ {
+ category: 'Security::CiConfiguration::SastCreateService',
+ action: 'create',
+ label: 'false'
+ }
end
+
+ include_examples 'services security ci configuration create service'
end
diff --git a/spec/services/security/ci_configuration/secret_detection_create_service_spec.rb b/spec/services/security/ci_configuration/secret_detection_create_service_spec.rb
new file mode 100644
index 00000000000..c1df3ebdca5
--- /dev/null
+++ b/spec/services/security/ci_configuration/secret_detection_create_service_spec.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Security::CiConfiguration::SecretDetectionCreateService, :snowplow do
+ subject(:result) { described_class.new(project, user).execute }
+
+ let(:branch_name) { 'set-secret-detection-config-1' }
+
+ let(:snowplow_event) do
+ {
+ category: 'Security::CiConfiguration::SecretDetectionCreateService',
+ action: 'create',
+ label: ''
+ }
+ end
+
+ include_examples 'services security ci configuration create service', true
+end
diff --git a/spec/services/users/update_assigned_open_issue_count_service_spec.rb b/spec/services/users/update_assigned_open_issue_count_service_spec.rb
new file mode 100644
index 00000000000..55fc60a7893
--- /dev/null
+++ b/spec/services/users/update_assigned_open_issue_count_service_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Users::UpdateAssignedOpenIssueCountService do
+ let_it_be(:user) { create(:user) }
+
+ describe '#initialize' do
+ context 'incorrect arguments provided' do
+ it 'raises an error if there are no target user' do
+ expect { described_class.new(target_user: nil) }.to raise_error(ArgumentError, /Please provide a target user/)
+ expect { described_class.new(target_user: "nonsense") }.to raise_error(ArgumentError, /Please provide a target user/)
+ end
+ end
+
+ context 'when correct arguments provided' do
+ it 'is successful' do
+ expect { described_class.new(target_user: user) }.not_to raise_error
+ end
+ end
+ end
+
+ describe "#execute", :clean_gitlab_redis_cache do
+ let(:fake_update_service) { double }
+ let(:fake_issue_count_service) { double }
+ let(:provided_value) { nil }
+
+ subject { described_class.new(target_user: user).execute }
+
+ context 'successful' do
+ it 'returns a success response' do
+ expect(subject).to be_success
+ end
+
+ it 'writes the cache with the new value' do
+ expect(Rails.cache).to receive(:write).with(['users', user.id, 'assigned_open_issues_count'], 0, expires_in: User::COUNT_CACHE_VALIDITY_PERIOD)
+
+ subject
+ end
+
+ it 'calls the issues finder to get the latest value' do
+ expect(IssuesFinder).to receive(:new).with(user, assignee_id: user.id, state: 'opened', non_archived: true).and_return(fake_issue_count_service)
+ expect(fake_issue_count_service).to receive(:execute)
+
+ subject
+ end
+ end
+ end
+end