Commit 026f586d authored by saikat sarkar's avatar saikat sarkar Committed by James Fargher

Set default for current_value in SAST config UI

parent c5576ba6
...@@ -12,9 +12,14 @@ module Security ...@@ -12,9 +12,14 @@ module Security
end end
def configuration def configuration
config = Gitlab::Json.parse(File.read(Rails.root.join(SAST_UI_SCHEMA_PATH))).with_indifferent_access result = Gitlab::Json.parse(File.read(Rails.root.join(SAST_UI_SCHEMA_PATH))).with_indifferent_access
populate_values(config) populate_default_value_for(result, :global)
config populate_default_value_for(result, :pipeline)
fill_current_value_with_default_for(result, :global)
fill_current_value_with_default_for(result, :pipeline)
populate_current_value_for(result, :global)
populate_current_value_for(result, :pipeline)
result
end end
private private
...@@ -23,16 +28,21 @@ module Security ...@@ -23,16 +28,21 @@ module Security
Gitlab::Template::GitlabCiYmlTemplate.find('SAST').content Gitlab::Template::GitlabCiYmlTemplate.find('SAST').content
end end
def populate_values(config) def populate_default_value_for(config, level)
set_each(config[:global], key: :default_value, with: sast_template_attributes) set_each(config[level], key: :default_value, with: sast_template_attributes)
set_each(config[:global], key: :value, with: gitlab_ci_yml_attributes) end
set_each(config[:pipeline], key: :default_value, with: sast_template_attributes)
set_each(config[:pipeline], key: :value, with: gitlab_ci_yml_attributes) def populate_current_value_for(config, level)
set_each(config[level], key: :value, with: gitlab_ci_yml_attributes)
end
def fill_current_value_with_default_for(config, level)
set_each(config[level], key: :value, with: sast_template_attributes)
end end
def set_each(config_attributes, key:, with:) def set_each(config_attributes, key:, with:)
config_attributes.each do |entity| config_attributes.each do |entity|
entity[key] = with[entity[:field]] entity[key] = with[entity[:field]] if with[entity[:field]]
end end
end end
......
---
title: Set default for current_value in SAST config UI
merge_request: 39504
author:
type: fixed
...@@ -87,7 +87,7 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -87,7 +87,7 @@ RSpec.describe GitlabSchema.types['Project'] do
expect(secure_analyzers_prefix['field']).to eq('SECURE_ANALYZERS_PREFIX') expect(secure_analyzers_prefix['field']).to eq('SECURE_ANALYZERS_PREFIX')
expect(secure_analyzers_prefix['label']).to eq('Image prefix') expect(secure_analyzers_prefix['label']).to eq('Image prefix')
expect(secure_analyzers_prefix['defaultValue']).to eq('registry.gitlab.com/gitlab-org/security-products/analyzers') expect(secure_analyzers_prefix['defaultValue']).to eq('registry.gitlab.com/gitlab-org/security-products/analyzers')
expect(secure_analyzers_prefix['value']).to be_nil expect(secure_analyzers_prefix['value']).to eq('registry.gitlab.com/gitlab-org/security-products/analyzers')
expect(secure_analyzers_prefix['options']).to be_nil expect(secure_analyzers_prefix['options']).to be_nil
end end
...@@ -97,7 +97,7 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -97,7 +97,7 @@ RSpec.describe GitlabSchema.types['Project'] do
expect(pipeline_stage['field']).to eq('stage') expect(pipeline_stage['field']).to eq('stage')
expect(pipeline_stage['label']).to eq('Stage') expect(pipeline_stage['label']).to eq('Stage')
expect(pipeline_stage['defaultValue']).to eq('test') expect(pipeline_stage['defaultValue']).to eq('test')
expect(pipeline_stage['value']).to be_nil expect(pipeline_stage['value']).to eq('test')
end end
it "returns the project's sast configuration for analyzer variables" do it "returns the project's sast configuration for analyzer variables" do
......
...@@ -34,11 +34,13 @@ RSpec.describe Security::CiConfiguration::SastParserService do ...@@ -34,11 +34,13 @@ RSpec.describe Security::CiConfiguration::SastParserService do
end end
context 'when .gitlab-ci.yml is absent' do context 'when .gitlab-ci.yml is absent' do
it 'assigns current values to nil' do it 'populates the current values with the default values' do
allow(project.repository).to receive(:blob_data_at).and_return(nil) allow(project.repository).to receive(:blob_data_at).and_return(nil)
expect(secure_analyzers_prefix['value']).to be_nil expect(secure_analyzers_prefix['value']).to eql('registry.gitlab.com/gitlab-org/security-products/analyzers')
expect(sast_excluded_paths['value']).to be_nil expect(sast_excluded_paths['value']).to eql('spec, test, tests, tmp')
expect(sast_analyzer_image_tag['value']).to be_nil expect(sast_analyzer_image_tag['value']).to eql('2')
expect(sast_pipeline_stage['value']).to eql('test')
expect(sast_search_max_depth['value']).to eql('4')
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