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