Commit a4d8d27a authored by Kamil Trzciński's avatar Kamil Trzciński

Store reports fix exception

Do not fail if feature is not available, or we cannot parse report
parent 8e03b10f
......@@ -57,10 +57,14 @@ module EE
def collect_security_reports!(security_reports)
each_report(::Ci::JobArtifact::SECURITY_REPORT_FILE_TYPES) do |file_type, blob|
next unless project.feature_available?(LICENSED_PARSER_FEATURES[file_type])
security_reports.get_report(file_type).tap do |security_report|
begin
next unless project.feature_available?(LICENSED_PARSER_FEATURES.fetch(file_type))
::Gitlab::Ci::Parsers::Security.fabricate!(file_type).parse!(blob, security_report)
rescue => e
security_report.error = e
end
end
end
end
......
......@@ -9,6 +9,7 @@ module Gitlab
attr_reader :occurrences
attr_reader :scanners
attr_reader :identifiers
attr_accessor :error
def initialize(type)
@type = type
......@@ -17,6 +18,10 @@ module Gitlab
@identifiers = {}
end
def errored?
error.present?
end
def add_scanner(params)
scanner_key(params).tap do |key|
scanners[key] ||= params
......
......@@ -234,7 +234,7 @@ describe Ci::Build do
end
it 'parses blobs and add the results to the report' do
expect { subject }.not_to raise_error
subject
expect(security_reports.get_report('sast').occurrences.size).to eq(3)
end
......@@ -245,9 +245,24 @@ describe Ci::Build do
create(:ee_ci_job_artifact, :sast_with_corrupted_data, job: job, project: job.project)
end
it 'raises an error' do
expect { subject }.to raise_error(::Gitlab::Ci::Parsers::Security::Sast::SastParserError)
it 'stores an error' do
subject
expect(security_reports.get_report('sast')).to be_errored
end
end
end
context 'when there is unsupported file type' do
before do
stub_const("Ci::JobArtifact::SECURITY_REPORT_FILE_TYPES", %w[codequality])
create(:ee_ci_job_artifact, :codequality, job: job, project: job.project)
end
it 'stores an error' do
subject
expect(security_reports.get_report('codequality')).to be_errored
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