Commit c240bb1b authored by Michał Zając's avatar Michał Zając

Rename OccurrencePipeline to FindingPipeline

This rename is a part of an attempt to consolidate the terminology used
throughout Standalone Vulnerabilities feature.
parent 34cbb7cd
...@@ -14,8 +14,8 @@ module EE ...@@ -14,8 +14,8 @@ module EE
prepended do prepended do
include UsageStatistics include UsageStatistics
has_many :vulnerabilities_occurrence_pipelines, class_name: 'Vulnerabilities::OccurrencePipeline' has_many :vulnerabilities_finding_pipelines, class_name: 'Vulnerabilities::FindingPipeline'
has_many :vulnerability_findings, source: :occurrence, through: :vulnerabilities_occurrence_pipelines, class_name: 'Vulnerabilities::Occurrence' has_many :vulnerability_findings, source: :occurrence, through: :vulnerabilities_finding_pipelines, class_name: 'Vulnerabilities::Occurrence'
has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id' has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id'
has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id' has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id'
...@@ -32,7 +32,7 @@ module EE ...@@ -32,7 +32,7 @@ module EE
end end
scope :with_vulnerabilities, -> do scope :with_vulnerabilities, -> do
where('EXISTS (?)', ::Vulnerabilities::OccurrencePipeline.where('ci_pipelines.id=vulnerability_occurrence_pipelines.pipeline_id').select(1)) where('EXISTS (?)', ::Vulnerabilities::FindingPipeline.where('ci_pipelines.id=vulnerability_occurrence_pipelines.pipeline_id').select(1))
end end
# This structure describes feature levels # This structure describes feature levels
......
# frozen_string_literal: true # frozen_string_literal: true
module Vulnerabilities module Vulnerabilities
class OccurrencePipeline < ApplicationRecord class FindingPipeline < ApplicationRecord
self.table_name = "vulnerability_occurrence_pipelines" self.table_name = "vulnerability_occurrence_pipelines"
belongs_to :occurrence, class_name: 'Vulnerabilities::Occurrence' belongs_to :occurrence, class_name: 'Vulnerabilities::Occurrence'
......
...@@ -22,8 +22,8 @@ module Vulnerabilities ...@@ -22,8 +22,8 @@ module Vulnerabilities
has_many :occurrence_identifiers, class_name: 'Vulnerabilities::OccurrenceIdentifier' has_many :occurrence_identifiers, class_name: 'Vulnerabilities::OccurrenceIdentifier'
has_many :identifiers, through: :occurrence_identifiers, class_name: 'Vulnerabilities::Identifier' has_many :identifiers, through: :occurrence_identifiers, class_name: 'Vulnerabilities::Identifier'
has_many :occurrence_pipelines, class_name: 'Vulnerabilities::OccurrencePipeline' has_many :finding_pipelines, class_name: 'Vulnerabilities::FindingPipeline'
has_many :pipelines, through: :occurrence_pipelines, class_name: 'Ci::Pipeline' has_many :pipelines, through: :finding_pipelines, class_name: 'Ci::Pipeline'
attr_writer :sha attr_writer :sha
...@@ -103,12 +103,12 @@ module Vulnerabilities ...@@ -103,12 +103,12 @@ module Vulnerabilities
end end
def self.for_pipelines(pipelines) def self.for_pipelines(pipelines)
joins(:occurrence_pipelines) joins(:finding_pipelines)
.where(vulnerability_occurrence_pipelines: { pipeline_id: pipelines }) .where(vulnerability_occurrence_pipelines: { pipeline_id: pipelines })
end end
def self.count_by_day_and_severity(period) def self.count_by_day_and_severity(period)
joins(:occurrence_pipelines) joins(:finding_pipelines)
.select('CAST(vulnerability_occurrence_pipelines.created_at AS DATE) AS day', :severity, 'COUNT(distinct vulnerability_occurrences.id) as count') .select('CAST(vulnerability_occurrence_pipelines.created_at AS DATE) AS day', :severity, 'COUNT(distinct vulnerability_occurrences.id) as count')
.where(['vulnerability_occurrence_pipelines.created_at >= ?', Time.zone.now.beginning_of_day - period]) .where(['vulnerability_occurrence_pipelines.created_at >= ?', Time.zone.now.beginning_of_day - period])
.group(:day, :severity) .group(:day, :severity)
......
...@@ -89,7 +89,7 @@ module Security ...@@ -89,7 +89,7 @@ module Security
end end
def create_vulnerability_pipeline_object(vulnerability_finding, pipeline) def create_vulnerability_pipeline_object(vulnerability_finding, pipeline)
vulnerability_finding.occurrence_pipelines.find_or_create_by!(pipeline: pipeline) vulnerability_finding.finding_pipelines.find_or_create_by!(pipeline: pipeline)
rescue ActiveRecord::RecordNotUnique rescue ActiveRecord::RecordNotUnique
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -16,7 +16,7 @@ class Gitlab::Seeder::Vulnerabilities ...@@ -16,7 +16,7 @@ class Gitlab::Seeder::Vulnerabilities
primary_identifier = create_identifier(rank) primary_identifier = create_identifier(rank)
vulnerability = create_vulnerability vulnerability = create_vulnerability
occurrence = create_occurrence(vulnerability, rank, primary_identifier) occurrence = create_occurrence(vulnerability, rank, primary_identifier)
# Create occurrence_pipeline join model # Create finding_pipeline join model
occurrence.pipelines << pipeline occurrence.pipelines << pipeline
# Create occurrence_identifier join models # Create occurrence_identifier join models
occurrence.identifiers << primary_identifier occurrence.identifiers << primary_identifier
......
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
factory :vulnerabilities_occurrence_pipeline, class: 'Vulnerabilities::OccurrencePipeline' do factory :vulnerabilities_finding_pipeline, class: 'Vulnerabilities::FindingPipeline' do
occurrence factory: :vulnerabilities_occurrence occurrence factory: :vulnerabilities_occurrence
pipeline factory: :ci_pipeline pipeline factory: :ci_pipeline
end end
......
...@@ -14,8 +14,8 @@ RSpec.describe Ci::Pipeline do ...@@ -14,8 +14,8 @@ RSpec.describe Ci::Pipeline do
it { is_expected.to have_many(:security_scans).through(:builds).class_name('Security::Scan') } it { is_expected.to have_many(:security_scans).through(:builds).class_name('Security::Scan') }
it { is_expected.to have_many(:downstream_bridges) } it { is_expected.to have_many(:downstream_bridges) }
it { is_expected.to have_many(:vulnerability_findings).through(:vulnerabilities_occurrence_pipelines).class_name('Vulnerabilities::Occurrence') } it { is_expected.to have_many(:vulnerability_findings).through(:vulnerabilities_finding_pipelines).class_name('Vulnerabilities::Occurrence') }
it { is_expected.to have_many(:vulnerabilities_occurrence_pipelines).class_name('Vulnerabilities::OccurrencePipeline') } it { is_expected.to have_many(:vulnerabilities_finding_pipelines).class_name('Vulnerabilities::FindingPipeline') }
describe '.failure_reasons' do describe '.failure_reasons' do
it 'contains failure reasons about exceeded limits' do it 'contains failure reasons about exceeded limits' do
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Vulnerabilities::OccurrencePipeline do RSpec.describe Vulnerabilities::FindingPipeline do
describe 'associations' do describe 'associations' do
it { is_expected.to belong_to(:pipeline).class_name('Ci::Pipeline') } it { is_expected.to belong_to(:pipeline).class_name('Ci::Pipeline') }
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_pipeline) { create(:vulnerabilities_occurrence_pipeline) } let!(:finding_pipeline) { create(:vulnerabilities_finding_pipeline) }
it { is_expected.to validate_presence_of(:occurrence) } it { is_expected.to validate_presence_of(:occurrence) }
it { is_expected.to validate_presence_of(:pipeline) } it { is_expected.to validate_presence_of(:pipeline) }
......
...@@ -13,7 +13,7 @@ RSpec.describe Vulnerabilities::Occurrence do ...@@ -13,7 +13,7 @@ RSpec.describe Vulnerabilities::Occurrence do
it { is_expected.to belong_to(:scanner).class_name('Vulnerabilities::Scanner') } it { is_expected.to belong_to(:scanner).class_name('Vulnerabilities::Scanner') }
it { is_expected.to belong_to(:vulnerability).inverse_of(:findings) } it { is_expected.to belong_to(:vulnerability).inverse_of(:findings) }
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(:occurrence_pipelines).class_name('Vulnerabilities::OccurrencePipeline') } 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(:occurrence_identifiers).class_name('Vulnerabilities::OccurrenceIdentifier') }
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, :occurrence_pipelines) do where(:case_name, :report_type, :scanners, :identifiers, :occurrences, :occurrence_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
...@@ -46,8 +46,8 @@ RSpec.describe Security::StoreReportService, '#execute' do ...@@ -46,8 +46,8 @@ RSpec.describe Security::StoreReportService, '#execute' do
expect { subject }.to change { Vulnerabilities::OccurrenceIdentifier.count }.by(occurrence_identifiers) expect { subject }.to change { Vulnerabilities::OccurrenceIdentifier.count }.by(occurrence_identifiers)
end end
it 'inserts all occurrence pipelines (join model)' do it 'inserts all finding pipelines (join model)' do
expect { subject }.to change { Vulnerabilities::OccurrencePipeline.count }.by(occurrence_pipelines) expect { subject }.to change { Vulnerabilities::FindingPipeline.count }.by(finding_pipelines)
end end
it 'inserts all vulnerabilties' do it 'inserts all vulnerabilties' do
...@@ -119,7 +119,7 @@ RSpec.describe Security::StoreReportService, '#execute' do ...@@ -119,7 +119,7 @@ RSpec.describe Security::StoreReportService, '#execute' do
end end
it 'inserts all occurrence pipelines (join model) for this new pipeline' do it 'inserts all occurrence pipelines (join model) for this new pipeline' do
expect { subject }.to change { Vulnerabilities::OccurrencePipeline.where(pipeline: new_pipeline).count }.by(33) expect { subject }.to change { Vulnerabilities::FindingPipeline.where(pipeline: new_pipeline).count }.by(33)
end end
it 'inserts new vulnerabilities with data from findings from this new pipeline' do it 'inserts new vulnerabilities with data from findings from this new pipeline' do
......
...@@ -220,7 +220,7 @@ ci_pipelines: ...@@ -220,7 +220,7 @@ ci_pipelines:
- parent_pipeline - parent_pipeline
- downstream_bridges - downstream_bridges
- job_artifacts - job_artifacts
- vulnerabilities_occurrence_pipelines - vulnerabilities_finding_pipelines
- vulnerability_findings - vulnerability_findings
- pipeline_config - pipeline_config
- security_scans - security_scans
......
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