Commit be94515f authored by James Fargher's avatar James Fargher

Merge branch 'fix_default_value' into 'master'

Set default for current_value in SAST config UI

See merge request gitlab-org/gitlab!39504
parents 67d753f4 026f586d
......@@ -12,9 +12,14 @@ module Security
end
def configuration
config = Gitlab::Json.parse(File.read(Rails.root.join(SAST_UI_SCHEMA_PATH))).with_indifferent_access
populate_values(config)
config
result = Gitlab::Json.parse(File.read(Rails.root.join(SAST_UI_SCHEMA_PATH))).with_indifferent_access
populate_default_value_for(result, :global)
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
private
......@@ -23,16 +28,21 @@ module Security
Gitlab::Template::GitlabCiYmlTemplate.find('SAST').content
end
def populate_values(config)
set_each(config[:global], key: :default_value, with: sast_template_attributes)
set_each(config[:global], key: :value, with: gitlab_ci_yml_attributes)
set_each(config[:pipeline], key: :default_value, with: sast_template_attributes)
set_each(config[:pipeline], key: :value, with: gitlab_ci_yml_attributes)
def populate_default_value_for(config, level)
set_each(config[level], key: :default_value, with: sast_template_attributes)
end
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
def set_each(config_attributes, key:, with:)
config_attributes.each do |entity|
entity[key] = with[entity[:field]]
entity[key] = with[entity[:field]] if with[entity[:field]]
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
expect(secure_analyzers_prefix['field']).to eq('SECURE_ANALYZERS_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['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
end
......@@ -97,7 +97,7 @@ RSpec.describe GitlabSchema.types['Project'] do
expect(pipeline_stage['field']).to eq('stage')
expect(pipeline_stage['label']).to eq('Stage')
expect(pipeline_stage['defaultValue']).to eq('test')
expect(pipeline_stage['value']).to be_nil
expect(pipeline_stage['value']).to eq('test')
end
it "returns the project's sast configuration for analyzer variables" do
......
......@@ -34,11 +34,13 @@ RSpec.describe Security::CiConfiguration::SastParserService do
end
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)
expect(secure_analyzers_prefix['value']).to be_nil
expect(sast_excluded_paths['value']).to be_nil
expect(sast_analyzer_image_tag['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 eql('spec, test, tests, tmp')
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
......
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