Commit ebb1fc93 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix_security_finding_comparison_method' into 'master'

Fix security finding comparison method

See merge request gitlab-org/gitlab!39871
parents 76cae36c b255590d
...@@ -74,17 +74,23 @@ module Gitlab ...@@ -74,17 +74,23 @@ module Gitlab
def eql?(other) def eql?(other)
report_type == other.report_type && report_type == other.report_type &&
location.fingerprint == other.location.fingerprint && location.fingerprint == other.location.fingerprint &&
primary_identifier.fingerprint == other.primary_identifier.fingerprint primary_fingerprint == other.primary_fingerprint
end end
def hash def hash
report_type.hash ^ location.fingerprint.hash ^ primary_identifier.fingerprint.hash report_type.hash ^ location.fingerprint.hash ^ primary_fingerprint.hash
end end
def valid? def valid?
scanner.present? && primary_identifier.present? && location.present? scanner.present? && primary_identifier.present? && location.present?
end end
protected
def primary_fingerprint
primary_identifier&.fingerprint
end
private private
def generate_project_fingerprint def generate_project_fingerprint
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
FactoryBot.define do FactoryBot.define do
factory :ci_reports_security_finding, class: '::Gitlab::Ci::Reports::Security::Finding' do factory :ci_reports_security_finding, class: '::Gitlab::Ci::Reports::Security::Finding' do
compare_key { "#{identifiers.first.external_type}:#{identifiers.first.external_id}:#{location.fingerprint}" } compare_key { "#{identifiers.first&.external_type}:#{identifiers.first&.external_id}:#{location.fingerprint}" }
confidence { :medium } confidence { :medium }
identifiers { Array.new(1) { FactoryBot.build(:ci_reports_security_identifier) } } identifiers { Array.new(1) { FactoryBot.build(:ci_reports_security_identifier) } }
location factory: :ci_reports_security_locations_sast location factory: :ci_reports_security_locations_sast
......
...@@ -170,6 +170,14 @@ RSpec.describe Gitlab::Ci::Reports::Security::Finding do ...@@ -170,6 +170,14 @@ RSpec.describe Gitlab::Ci::Reports::Security::Finding do
subject { finding.eql?(other_finding) } subject { finding.eql?(other_finding) }
context 'when the primary_identifier is nil' do
let(:identifier) { nil }
it 'does not raise an exception' do
expect { subject }.not_to raise_error
end
end
context 'when the other finding has same `report_type`' do context 'when the other finding has same `report_type`' do
let(:report_type) { :sast } let(:report_type) { :sast }
......
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