Commit 356e004a authored by Lucas Charles's avatar Lucas Charles

fix: VulnerabilityFinding equality should exclude other record types

Our previous comparison between finding records did not properly check
the class type to ensure non-finding records are properly excluded. This
can occur when multiple records are created within a transaction (such
as `Vulnerabilities::CreateService` and a simple `Array#uniq` check is
performed.

https://gitlab.com/gitlab-org/gitlab/-/issues/332825

Changelog: fixed
EE: true
parent 655791a5
......@@ -336,6 +336,7 @@ module Vulnerabilities
alias_method :==, :eql?
def eql?(other)
return false unless other.is_a?(self.class)
return false unless other.report_type == report_type && other.primary_identifier_fingerprint == primary_identifier_fingerprint
if ::Feature.enabled?(:vulnerability_finding_tracking_signatures, project) && project.licensed_feature_available?(:vulnerability_finding_signatures)
......
......@@ -1055,6 +1055,11 @@ RSpec.describe Vulnerabilities::Finding do
expect(finding1.eql?(finding2)).to be(vulnerability_finding_signatures_enabled)
end
it 'wont match other record types' do
historical_stat = build(:vulnerability_historical_statistic, project: project)
expect(finding1.eql?(historical_stat)).to be(false)
end
context 'short circuits on the highest priority signature match' do
using RSpec::Parameterized::TableSyntax
......
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