Commit 477b82f1 authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Stan Hu

Make post migration EE-specific

Fixes https://gitlab.com/gitlab-org/gitlab/issues/32725
parent ecb4d009
......@@ -14,6 +14,9 @@ class UpdateCsVulnerabilityConfidenceColumn < ActiveRecord::Migration[5.2]
# 137_424 records to be updated on GitLab.com,
# giving us an estimated runtime of 12 hours.
def up
# no-op in CE
return unless Gitlab.ee?
migration = Gitlab::BackgroundMigration::UpdateVulnerabilityConfidence
migration_name = migration.to_s.demodulize
relation = migration::Occurrence.container_scanning_reports_with_medium_confidence
......
# frozen_string_literal: true
# rubocop:disable Style/Documentation
module Gitlab
module BackgroundMigration
class UpdateVulnerabilityConfidence
......
......@@ -7,9 +7,6 @@ describe Gitlab::BackgroundMigration::UpdateVulnerabilityConfidence, :migration,
let(:identifiers) { table(:vulnerability_identifiers) }
let(:scanners) { table(:vulnerability_scanners) }
let(:projects) { table(:projects) }
let(:vul1) { attributes_for(:vulnerabilities_occurrence) }
let(:vul2) { attributes_for(:vulnerabilities_occurrence) }
let(:vul3) { attributes_for(:vulnerabilities_occurrence) }
it 'updates confidence level for container scanning reports' do
projects.create!(id: 123, namespace_id: 12, name: 'gitlab', path: 'gitlab')
......@@ -25,34 +22,35 @@ describe Gitlab::BackgroundMigration::UpdateVulnerabilityConfidence, :migration,
scanners.create!(id: 6, project_id: 123, external_id: 'clair', name: 'Security Scanner')
vulnerabilities.create!(container_scanning_vuln_params(vul1, 1))
vulnerabilities.create!(container_scanning_vuln_params(vul2, 2))
vulnerabilities.create!(container_scanning_vuln_params(vul3, 3).merge(report_type: 1))
vul1 = vulnerabilities.create!(container_scanning_vuln_params(1))
vulnerabilities.create!(container_scanning_vuln_params(2))
vul3 = vulnerabilities.create!(container_scanning_vuln_params(3).merge(report_type: 1))
expect(vulnerabilities.where(report_type: 2, confidence: 2).count). to eq(0)
expect(vulnerabilities.exists?(report_type: 2, confidence: 5)).to be_truthy
described_class.new.perform(1, 3)
described_class.new.perform(vul1.id, vul3.id)
expect(vulnerabilities.exists?(report_type: 2, confidence: 5)).to be_falsy
expect(vulnerabilities.where(report_type: 2, confidence: 2).count). to eq(2)
end
def container_scanning_vuln_params(vul, primary_identifier_id)
def container_scanning_vuln_params(primary_identifier_id)
attrs = attributes_for(:vulnerabilities_occurrence)
{
id: vul[:id],
severity: 2,
confidence: 5,
report_type: 2,
project_id: 123,
scanner_id: 6,
primary_identifier_id: primary_identifier_id,
project_fingerprint: vul[:project_fingerprint],
location_fingerprint: vul[:location_fingerprint],
uuid: vul[:uuid],
name: vul[:name],
project_fingerprint: attrs[:project_fingerprint],
location_fingerprint: attrs[:location_fingerprint],
uuid: attrs[:uuid],
name: attrs[:name],
metadata_version: '1.3',
raw_metadata: vul3[:raw_metadata]
raw_metadata: attrs[:raw_metadata]
}
end
end
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