Commit db42ce92 authored by Jarka Košanová's avatar Jarka Košanová

Merge branch 'log-extra' into 'master'

Log parameters when saving invalid occurrence

See merge request gitlab-org/gitlab!29723
parents 84ccec12 6a14394d
...@@ -65,6 +65,8 @@ module Security ...@@ -65,6 +65,8 @@ module Security
.find_or_create_by!(find_params) .find_or_create_by!(find_params)
rescue ActiveRecord::RecordNotUnique rescue ActiveRecord::RecordNotUnique
project.vulnerability_findings.find_by!(find_params) project.vulnerability_findings.find_by!(find_params)
rescue ActiveRecord::RecordInvalid => e
Gitlab::ErrorTracking.track_and_raise_exception(e, create_params: create_params&.dig(:raw_metadata))
end end
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -54,6 +54,28 @@ describe Security::StoreReportService, '#execute' do ...@@ -54,6 +54,28 @@ describe Security::StoreReportService, '#execute' do
expect { subject }.to change { Vulnerability.count }.by(occurrences) expect { subject }.to change { Vulnerability.count }.by(occurrences)
end end
end end
context 'invalid data' do
let(:artifact) { create(:ee_ci_job_artifact, :sast) }
let(:occurrence_without_name) { build(:ci_reports_security_occurrence, name: nil) }
let(:report) { Gitlab::Ci::Reports::Security::Report.new('container_scanning', nil, nil) }
before do
allow(Gitlab::ErrorTracking).to receive(:track_and_raise_exception).and_call_original
report.add_occurrence(occurrence_without_name)
end
it 'raises invalid record error' do
expect { subject.execute }.to raise_error(ActiveRecord::RecordInvalid)
end
it 'reports the error correctly' do
expected_params = occurrence_without_name.to_hash.dig(:raw_metadata)
expect { subject.execute }.to raise_error { |error|
expect(Gitlab::ErrorTracking).to have_received(:track_and_raise_exception).with(error, create_params: expected_params)
}
end
end
end end
context 'with existing data from previous pipeline' do context 'with existing data from previous pipeline' do
......
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