Commit 47fda363 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'fix-support-for-multiple-reports' into 'master'

Store reports fix exception

See merge request gitlab-org/gitlab-ee!8237
parents b5527d26 a4d8d27a
...@@ -57,10 +57,14 @@ module EE ...@@ -57,10 +57,14 @@ module EE
def collect_security_reports!(security_reports) def collect_security_reports!(security_reports)
each_report(::Ci::JobArtifact::SECURITY_REPORT_FILE_TYPES) do |file_type, blob| 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| 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) ::Gitlab::Ci::Parsers::Security.fabricate!(file_type).parse!(blob, security_report)
rescue => e
security_report.error = e
end
end end
end end
end end
......
...@@ -9,6 +9,7 @@ module Gitlab ...@@ -9,6 +9,7 @@ module Gitlab
attr_reader :occurrences attr_reader :occurrences
attr_reader :scanners attr_reader :scanners
attr_reader :identifiers attr_reader :identifiers
attr_accessor :error
def initialize(type) def initialize(type)
@type = type @type = type
...@@ -17,6 +18,10 @@ module Gitlab ...@@ -17,6 +18,10 @@ module Gitlab
@identifiers = {} @identifiers = {}
end end
def errored?
error.present?
end
def add_scanner(params) def add_scanner(params)
scanner_key(params).tap do |key| scanner_key(params).tap do |key|
scanners[key] ||= params scanners[key] ||= params
......
...@@ -234,7 +234,7 @@ describe Ci::Build do ...@@ -234,7 +234,7 @@ describe Ci::Build do
end end
it 'parses blobs and add the results to the report' do 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) expect(security_reports.get_report('sast').occurrences.size).to eq(3)
end end
...@@ -245,9 +245,24 @@ describe Ci::Build do ...@@ -245,9 +245,24 @@ describe Ci::Build do
create(:ee_ci_job_artifact, :sast_with_corrupted_data, job: job, project: job.project) create(:ee_ci_job_artifact, :sast_with_corrupted_data, job: job, project: job.project)
end end
it 'raises an error' do it 'stores an error' do
expect { subject }.to raise_error(::Gitlab::Ci::Parsers::Security::Sast::SastParserError) 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 end
it 'stores an error' do
subject
expect(security_reports.get_report('codequality')).to be_errored
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