Commit 07c68983 authored by Furkan Ayhan's avatar Furkan Ayhan Committed by Fabio Pitino

Fix SAST parser for no-sast pipelines

parent 4c75c7d2
...@@ -112,7 +112,9 @@ module Gitlab ...@@ -112,7 +112,9 @@ module Gitlab
end end
def yaml_variables_for(job_name) def yaml_variables_for(job_name)
job = jobs.fetch(job_name) job = jobs[job_name]
return [] unless job
Gitlab::Ci::Variables::Helpers.inherit_yaml_variables( Gitlab::Ci::Variables::Helpers.inherit_yaml_variables(
from: root_variables, from: root_variables,
...@@ -122,9 +124,7 @@ module Gitlab ...@@ -122,9 +124,7 @@ module Gitlab
end end
def stage_for(job_name) def stage_for(job_name)
job = jobs.fetch(job_name) jobs.dig(job_name, :stage)
job[:stage]
end end
private private
......
...@@ -54,14 +54,22 @@ module Gitlab ...@@ -54,14 +54,22 @@ module Gitlab
YAML YAML
end end
subject(:yaml_variables_for) { result.yaml_variables_for(:job) } let(:job_name) { :job }
it do subject(:yaml_variables_for) { result.yaml_variables_for(job_name) }
it 'returns calculated variables with root and job variables' do
is_expected.to match_array([ is_expected.to match_array([
{ key: 'VAR1', value: 'value 11', public: true }, { key: 'VAR1', value: 'value 11', public: true },
{ key: 'VAR2', value: 'value 2', public: true } { key: 'VAR2', value: 'value 2', public: true }
]) ])
end end
context 'when an absent job is sent' do
let(:job_name) { :invalid_job }
it { is_expected.to eq([]) }
end
end end
describe '#stage_for' do describe '#stage_for' do
...@@ -72,10 +80,16 @@ module Gitlab ...@@ -72,10 +80,16 @@ module Gitlab
YAML YAML
end end
subject(:stage_for) { result.stage_for(:job) } let(:job_name) { :job }
subject(:stage_for) { result.stage_for(job_name) }
it { is_expected.to eq('test') }
context 'when an absent job is sent' do
let(:job_name) { :invalid_job }
it do it { is_expected.to be_nil }
is_expected.to eq('test')
end end
end end
end end
......
...@@ -67,6 +67,23 @@ RSpec.describe Security::CiConfiguration::SastParserService do ...@@ -67,6 +67,23 @@ RSpec.describe Security::CiConfiguration::SastParserService do
expect(sast_brakeman_level['value']).to eql('1') expect(sast_brakeman_level['value']).to eql('1')
end end
end end
context 'when .gitlab-ci.yml does not include the sast job' do
before do
allow(project.repository).to receive(:blob_data_at).and_return(
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
)
end
it 'populates the current values with the default values' do
expect(secure_analyzers_prefix['value']).to eql('registry.gitlab.com/gitlab-org/security-products/analyzers')
expect(sast_excluded_paths['value']).to eql('spec, test, tests, tmp')
expect(sast_pipeline_stage['value']).to eql('test')
expect(sast_search_max_depth['value']).to eql('4')
expect(brakeman['enabled']).to be(true)
expect(sast_brakeman_level['value']).to eql('1')
end
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment