diff --git a/ee/app/services/security/report_summary_service.rb b/ee/app/services/security/report_summary_service.rb index 48cc2717646aceaa57363df3c8e55019dce7012a..f199102f3e04c73322aed2832709c65492b3fa86 100644 --- a/ee/app/services/security/report_summary_service.rb +++ b/ee/app/services/security/report_summary_service.rb @@ -20,6 +20,8 @@ def execute private def summary_counts_for_report_type(report_type, summary_types) + return unless report_exists?(report_type) + summary_types.each_with_object({}) do |summary_type, response| case summary_type when :vulnerabilities_count @@ -46,5 +48,9 @@ def scanned_resources_counts ::Security::ScannedResourcesCountingService.new(@pipeline, requested_report_types(:scanned_resources_count)).execute end end + + def report_exists?(report_type) + @pipeline&.security_reports&.reports&.key?(report_type.to_s) + end end end diff --git a/ee/changelogs/unreleased/hide_scans_that_have_not_run_223673.yml b/ee/changelogs/unreleased/hide_scans_that_have_not_run_223673.yml new file mode 100644 index 0000000000000000000000000000000000000000..5b616adb69a9c4e88170f8f00fe7f1102a330ad8 --- /dev/null +++ b/ee/changelogs/unreleased/hide_scans_that_have_not_run_223673.yml @@ -0,0 +1,5 @@ +--- +title: Return null in securityReportSummary when the report didn't run +merge_request: 35218 +author: +type: changed diff --git a/ee/spec/services/security/report_summary_service_spec.rb b/ee/spec/services/security/report_summary_service_spec.rb index 9a844816ea53a5b3b34912fa97ad40454f23886f..74db2ec7594e02939728e7a199a87a1490f65e8a 100644 --- a/ee/spec/services/security/report_summary_service_spec.rb +++ b/ee/spec/services/security/report_summary_service_spec.rb @@ -98,15 +98,11 @@ )) end - context 'When ran no security scans' do + context 'When no security scans ran' do let(:pipeline) { create(:ci_pipeline, :success) } - it 'returns 0 vulnerabilities' do - expect(result[:dast][:vulnerabilities_count]).to be(0) - end - - it 'returns 0 scanned resources' do - expect(result[:dast][:scanned_resources_count]).to be(0) + it 'returns nil' do + expect(result[:dast]).to be_nil end end end