Commit 8902b46a authored by rossfuhrman's avatar rossfuhrman

Minor bug fixes for SastBuildActions

The stage parameter should be a string, not a symbol
The call to .compact doesn't remove empty strings, and we don't want to
write variables to the YML that don't have a value set.
parent 5fa85f3e
...@@ -36,12 +36,14 @@ module Security ...@@ -36,12 +36,14 @@ module Security
end end
def sast_stage def sast_stage
@params[:stage] || 'test' @params['stage'] || 'test'
end end
# We only want to write variables that are set # We only want to write variables that are set
def parse_variables(variables) def parse_variables(variables)
variables.map { |var| [var, @params[var]] }.to_h.compact variables.map { |var| [var, @params[var]] }
.to_h
.select { |k, v| v.present? }
end end
def sast_block def sast_block
......
...@@ -6,8 +6,8 @@ RSpec.describe Security::CiConfiguration::SastBuildActions do ...@@ -6,8 +6,8 @@ RSpec.describe Security::CiConfiguration::SastBuildActions do
context 'autodevops disabled' do context 'autodevops disabled' do
let(:auto_devops_enabled) { false } let(:auto_devops_enabled) { false }
context 'with no paramaters' do context 'with one empty parameter' do
let(:params) { {} } let(:params) { { 'SECURE_ANALYZERS_PREFIX' => '' } }
subject(:result) { described_class.new(auto_devops_enabled, params).generate } subject(:result) { described_class.new(auto_devops_enabled, params).generate }
...@@ -18,7 +18,7 @@ RSpec.describe Security::CiConfiguration::SastBuildActions do ...@@ -18,7 +18,7 @@ RSpec.describe Security::CiConfiguration::SastBuildActions do
context 'with all parameters' do context 'with all parameters' do
let(:params) do let(:params) do
{ stage: 'security', { 'stage' => 'security',
'SEARCH_MAX_DEPTH' => 1, 'SEARCH_MAX_DEPTH' => 1,
'SECURE_ANALYZERS_PREFIX' => 'localhost:5000/analyzers', 'SECURE_ANALYZERS_PREFIX' => 'localhost:5000/analyzers',
'SAST_ANALYZER_IMAGE_TAG' => 2, 'SAST_ANALYZER_IMAGE_TAG' => 2,
...@@ -35,7 +35,7 @@ RSpec.describe Security::CiConfiguration::SastBuildActions do ...@@ -35,7 +35,7 @@ RSpec.describe Security::CiConfiguration::SastBuildActions do
context 'with autodevops enabled' do context 'with autodevops enabled' do
let(:auto_devops_enabled) { true } let(:auto_devops_enabled) { true }
let(:params) { { stage: 'custom stage' } } let(:params) { { 'stage' => 'custom stage' } }
subject(:result) { described_class.new(auto_devops_enabled, params).generate } subject(:result) { described_class.new(auto_devops_enabled, params).generate }
......
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