Commit a1a83965 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch...

Merge branch '214564-rename-vulnerabilities-occurrenceidentifier-to-vulnerabilities-findingidentifier' into 'master'

Rename OccurrenceIdentifier to FindingIdentifier

See merge request gitlab-org/gitlab!35989
parents 28745779 1557b3d9
# frozen_string_literal: true
module Vulnerabilities
class OccurrenceIdentifier < ApplicationRecord
class FindingIdentifier < ApplicationRecord
self.table_name = "vulnerability_occurrence_identifiers"
belongs_to :occurrence, class_name: 'Vulnerabilities::Occurrence'
......
......@@ -8,8 +8,8 @@ module Vulnerabilities
sha_attribute :fingerprint
has_many :occurrence_identifiers, class_name: 'Vulnerabilities::OccurrenceIdentifier'
has_many :occurrences, through: :occurrence_identifiers, class_name: 'Vulnerabilities::Occurrence'
has_many :finding_identifiers, class_name: 'Vulnerabilities::FindingIdentifier'
has_many :occurrences, through: :finding_identifiers, class_name: 'Vulnerabilities::Occurrence'
has_many :primary_occurrences, class_name: 'Vulnerabilities::Occurrence', inverse_of: :primary_identifier
......
......@@ -20,8 +20,8 @@ module Vulnerabilities
belongs_to :primary_identifier, class_name: 'Vulnerabilities::Identifier', inverse_of: :primary_occurrences
belongs_to :vulnerability, inverse_of: :findings
has_many :occurrence_identifiers, class_name: 'Vulnerabilities::OccurrenceIdentifier'
has_many :identifiers, through: :occurrence_identifiers, class_name: 'Vulnerabilities::Identifier'
has_many :finding_identifiers, class_name: 'Vulnerabilities::FindingIdentifier'
has_many :identifiers, through: :finding_identifiers, class_name: 'Vulnerabilities::Identifier'
has_many :finding_pipelines, class_name: 'Vulnerabilities::FindingPipeline'
has_many :pipelines, through: :finding_pipelines, class_name: 'Ci::Pipeline'
......
......@@ -87,7 +87,7 @@ module Security
def create_or_update_vulnerability_identifier_object(vulnerability_finding, identifier)
identifier_object = identifiers_objects[identifier.key]
vulnerability_finding.occurrence_identifiers.find_or_create_by!(identifier: identifier_object)
vulnerability_finding.finding_identifiers.find_or_create_by!(identifier: identifier_object)
identifier_object.update!(identifier.to_hash)
rescue ActiveRecord::RecordNotUnique
end
......
# frozen_string_literal: true
FactoryBot.define do
factory :vulnerabilities_occurrence_identifier, class: 'Vulnerabilities::OccurrenceIdentifier' do
factory :vulnerabilities_finding_identifier, class: 'Vulnerabilities::FindingIdentifier' do
occurrence factory: :vulnerabilities_occurrence
identifier factory: :vulnerabilities_identifier
end
......
......@@ -2,14 +2,14 @@
require 'spec_helper'
RSpec.describe Vulnerabilities::OccurrenceIdentifier do
RSpec.describe Vulnerabilities::FindingIdentifier do
describe 'associations' do
it { is_expected.to belong_to(:identifier).class_name('Vulnerabilities::Identifier') }
it { is_expected.to belong_to(:occurrence).class_name('Vulnerabilities::Occurrence') }
end
describe 'validations' do
let!(:occurrence_identifier) { create(:vulnerabilities_occurrence_identifier) }
let!(:finding_identifier) { create(:vulnerabilities_finding_identifier) }
it { is_expected.to validate_presence_of(:occurrence) }
it { is_expected.to validate_presence_of(:identifier) }
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Vulnerabilities::Identifier do
describe 'associations' do
it { is_expected.to have_many(:occurrence_identifiers).class_name('Vulnerabilities::OccurrenceIdentifier') }
it { is_expected.to have_many(:finding_identifiers).class_name('Vulnerabilities::FindingIdentifier') }
it { is_expected.to have_many(:occurrences).class_name('Vulnerabilities::Occurrence') }
it { is_expected.to have_many(:primary_occurrences).class_name('Vulnerabilities::Occurrence') }
it { is_expected.to belong_to(:project) }
......
......@@ -15,7 +15,7 @@ RSpec.describe Vulnerabilities::Occurrence do
it { is_expected.to have_many(:pipelines).class_name('Ci::Pipeline') }
it { is_expected.to have_many(:finding_pipelines).class_name('Vulnerabilities::FindingPipeline') }
it { is_expected.to have_many(:identifiers).class_name('Vulnerabilities::Identifier') }
it { is_expected.to have_many(:occurrence_identifiers).class_name('Vulnerabilities::OccurrenceIdentifier') }
it { is_expected.to have_many(:finding_identifiers).class_name('Vulnerabilities::FindingIdentifier') }
end
describe 'validations' do
......
......@@ -25,7 +25,7 @@ RSpec.describe 'Query.vulnerabilities.identifiers' do
let_it_be(:vulnerability) { create(:vulnerability, project: project, report_type: :container_scanning) }
let_it_be(:occurrence_identifier) do
let_it_be(:finding_identifier) do
create(
:vulnerabilities_identifier,
external_type: 'CVE',
......@@ -42,8 +42,8 @@ RSpec.describe 'Query.vulnerabilities.identifiers' do
)
end
let_it_be(:vulnerabilities_occurrence_identifier) do
create(:vulnerabilities_occurrence_identifier, identifier: occurrence_identifier, occurrence: finding)
let_it_be(:vulnerabilities_finding_identifier) do
create(:vulnerabilities_finding_identifier, identifier: finding_identifier, occurrence: finding)
end
subject { graphql_data.dig('vulnerabilities', 'nodes') }
......@@ -58,9 +58,9 @@ RSpec.describe 'Query.vulnerabilities.identifiers' do
it 'returns a vulnerability identifiers' do
identifier = subject.first['identifiers'].first
expect(identifier['name']).to eq(occurrence_identifier.name)
expect(identifier['externalType']).to eq(occurrence_identifier.external_type)
expect(identifier['externalId']).to eq(occurrence_identifier.external_id)
expect(identifier['url']).to eq(occurrence_identifier.url)
expect(identifier['name']).to eq(finding_identifier.name)
expect(identifier['externalType']).to eq(finding_identifier.external_type)
expect(identifier['externalId']).to eq(finding_identifier.external_id)
expect(identifier['url']).to eq(finding_identifier.url)
end
end
......@@ -23,7 +23,7 @@ RSpec.describe Security::StoreReportService, '#execute' do
using RSpec::Parameterized::TableSyntax
where(:case_name, :report_type, :scanners, :identifiers, :occurrences, :occurrence_identifiers, :finding_pipelines) do
where(:case_name, :report_type, :scanners, :identifiers, :occurrences, :finding_identifiers, :finding_pipelines) do
'with SAST report' | :sast | 3 | 17 | 33 | 39 | 33
'with Dependency Scanning report' | :dependency_scanning | 2 | 7 | 4 | 7 | 4
'with Container Scanning report' | :container_scanning | 1 | 8 | 8 | 8 | 8
......@@ -43,7 +43,7 @@ RSpec.describe Security::StoreReportService, '#execute' do
end
it 'inserts all occurrence identifiers (join model)' do
expect { subject }.to change { Vulnerabilities::OccurrenceIdentifier.count }.by(occurrence_identifiers)
expect { subject }.to change { Vulnerabilities::FindingIdentifier.count }.by(finding_identifiers)
end
it 'inserts all finding pipelines (join model)' 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