Commit 3ca91553 authored by Michał Zając's avatar Michał Zając

Load EE factories when seeding Vulnerabilities

parent 42a4f238
...@@ -5,6 +5,8 @@ class Gitlab::Seeder::Vulnerabilities ...@@ -5,6 +5,8 @@ class Gitlab::Seeder::Vulnerabilities
def initialize(project) def initialize(project)
@project = project @project = project
FactoryBot.definition_file_paths << Rails.root.join('ee', 'spec', 'factories')
FactoryBot.reload # rubocop:disable Cop/ActiveRecordAssociationReload
end end
def seed! def seed!
...@@ -63,10 +65,12 @@ class Gitlab::Seeder::Vulnerabilities ...@@ -63,10 +65,12 @@ class Gitlab::Seeder::Vulnerabilities
end end
def create_occurrence(vulnerability, rank, primary_identifier) def create_occurrence(vulnerability, rank, primary_identifier)
scanner = FactoryBot.create(:vulnerabilities_scanner, project: vulnerability.project)
FactoryBot.create( FactoryBot.create(
:vulnerabilities_occurrence, :vulnerabilities_occurrence,
project: project, project: project,
vulnerability: vulnerability, vulnerability: vulnerability,
scanner: scanner,
severity: random_severity_level, severity: random_severity_level,
confidence: random_confidence_level, confidence: random_confidence_level,
primary_identifier: primary_identifier, primary_identifier: primary_identifier,
...@@ -78,7 +82,7 @@ class Gitlab::Seeder::Vulnerabilities ...@@ -78,7 +82,7 @@ class Gitlab::Seeder::Vulnerabilities
def create_identifier(rank) def create_identifier(rank)
FactoryBot.create( FactoryBot.create(
:vulnerability_identifier, :vulnerabilities_identifier,
external_type: "SECURITY_ID", external_type: "SECURITY_ID",
external_id: "SECURITY_#{rank}", external_id: "SECURITY_#{rank}",
fingerprint: random_fingerprint, fingerprint: random_fingerprint,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
FactoryBot.define do FactoryBot.define do
sequence :vulnerability_occurrence_uuid do |n| sequence :vulnerability_occurrence_uuid do |n|
Digest::SHA1.hexdigest("uuid-#{n}")[0..35] SecureRandom.uuid
end end
factory :vulnerabilities_occurrence, class: 'Vulnerabilities::Occurrence', aliases: [:vulnerabilities_finding] do factory :vulnerabilities_occurrence, class: 'Vulnerabilities::Occurrence', aliases: [:vulnerabilities_finding] do
......
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
sequence(:vulnerability_scanner_external_id) do |n|
"find_sec_bugs ##{n}"
end
factory :vulnerabilities_scanner, class: 'Vulnerabilities::Scanner' do factory :vulnerabilities_scanner, class: 'Vulnerabilities::Scanner' do
external_id { 'find_sec_bugs' } sequence(:external_id) { generate(:vulnerability_scanner_external_id) }
name { 'Find Security Bugs' } name { 'Find Security Bugs' }
project project
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