Welcome to mirror list, hosted at ThFree Co, Russian Federation.

vulnerability_finding_helpers.rb « concerns « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a656856487d31f7d464a3fce73edbf8bcf1e90ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

module VulnerabilityFindingHelpers
  extend ActiveSupport::Concern
  def matches_signatures(other_signatures, other_uuid)
    other_signature_types = other_signatures.index_by(&:algorithm_type)

    # highest first
    match_result = nil
    signatures.sort_by(&:priority).reverse_each do |signature|
      matching_other_signature = other_signature_types[signature.algorithm_type]
      next if matching_other_signature.nil?

      match_result = matching_other_signature == signature
      break
    end

    if match_result.nil?
      [uuid, *signature_uuids].include?(other_uuid)
    else
      match_result
    end
  end

  def signature_uuids
    signatures.map do |signature|
      hex_sha = signature.signature_hex
      ::Security::VulnerabilityUUID.generate(
        report_type: report_type,
        location_fingerprint: hex_sha,
        primary_identifier_fingerprint: primary_identifier&.fingerprint,
        project_id: project_id
      )
    end
  end
end