diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /spec/services/security | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'spec/services/security')
-rw-r--r-- | spec/services/security/ci_configuration/sast_create_service_spec.rb | 51 |
1 files changed, 43 insertions, 8 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 1e6dc367146..e80fe1a42fa 100644 --- a/spec/services/security/ci_configuration/sast_create_service_spec.rb +++ b/spec/services/security/ci_configuration/sast_create_service_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' -RSpec.describe Security::CiConfiguration::SastCreateService, :snowplow, feature_category: :sast do +RSpec.describe Security::CiConfiguration::SastCreateService, :snowplow, + feature_category: :static_application_security_testing do subject(:result) { described_class.new(project, user, params).execute } let(:branch_name) { 'set-sast-config-1' } @@ -24,7 +25,45 @@ RSpec.describe Security::CiConfiguration::SastCreateService, :snowplow, feature_ include_examples 'services security ci configuration create service' - context "when committing to the default branch", :aggregate_failures do + RSpec.shared_examples_for 'commits directly to the default branch' do + it 'commits directly to the default branch' do + expect(project).to receive(:default_branch).twice.and_return('master') + + expect(result.status).to eq(:success) + expect(result.payload[:success_path]).to match(/#{Gitlab::Routing.url_helpers.project_new_merge_request_url(project, {})}(.*)description(.*)source_branch/) + expect(result.payload[:branch]).to eq('master') + end + end + + context 'when the repository is empty' do + let_it_be(:project) { create(:project_empty_repo) } + + context 'when initialize_with_sast is false' do + before do + project.add_developer(user) + end + + let(:params) { { initialize_with_sast: false } } + + it 'raises an error' do + expect { result }.to raise_error(Gitlab::Graphql::Errors::MutationError) + end + end + + context 'when initialize_with_sast is true' do + let(:params) { { initialize_with_sast: true } } + + subject(:result) { described_class.new(project, user, params, commit_on_default: true).execute } + + before do + project.add_maintainer(user) + end + + it_behaves_like 'commits directly to the default branch' + end + end + + context 'when committing to the default branch', :aggregate_failures do subject(:result) { described_class.new(project, user, params, commit_on_default: true).execute } let(:params) { {} } @@ -33,17 +72,13 @@ RSpec.describe Security::CiConfiguration::SastCreateService, :snowplow, feature_ project.add_developer(user) end - it "doesn't try to remove that branch on raised exceptions" do + it 'does not try to remove that branch on raised exceptions' do expect(Files::MultiService).to receive(:new).and_raise(StandardError, '_exception_') expect(project.repository).not_to receive(:rm_branch) expect { result }.to raise_error(StandardError, '_exception_') end - it "commits directly to the default branch" do - expect(result.status).to eq(:success) - expect(result.payload[:success_path]).to match(/#{Gitlab::Routing.url_helpers.project_new_merge_request_url(project, {})}(.*)description(.*)source_branch/) - expect(result.payload[:branch]).to eq('master') - end + it_behaves_like 'commits directly to the default branch' end end |