summaryrefslogtreecommitdiff
path: root/spec/migrations
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-24 21:06:18 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-24 21:06:18 +0000
commit150effab274651b3a8d2041e64ced734d1f3a349 (patch)
tree7f887964a56bd15a87d58cd367ccc1fa45f98554 /spec/migrations
parent2ed368929ab5094fec5da8038f723463596a80cf (diff)
downloadgitlab-ce-150effab274651b3a8d2041e64ced734d1f3a349.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/update_cs_vulnerability_confidence_column_spec.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/spec/migrations/update_cs_vulnerability_confidence_column_spec.rb b/spec/migrations/update_cs_vulnerability_confidence_column_spec.rb
new file mode 100644
index 00000000000..b8575dd9467
--- /dev/null
+++ b/spec/migrations/update_cs_vulnerability_confidence_column_spec.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20190909141517_update_cs_vulnerability_confidence_column.rb')
+
+describe UpdateCsVulnerabilityConfidenceColumn, :migration, :sidekiq do
+ let(:vulnerabilities) { table(:vulnerability_occurrences) }
+ let(:identifiers) { table(:vulnerability_identifiers) }
+ let(:scanners) { table(:vulnerability_scanners) }
+ let(:projects) { table(:projects) }
+ let(:vul1) { attributes_for(:vulnerabilities_occurrence, id: 1, report_type: 2, confidence: 5) }
+ let(:vul2) { attributes_for(:vulnerabilities_occurrence, id: 2, report_type: 2, confidence: 5) }
+
+ before do
+ stub_const("#{described_class}::BATCH_SIZE", 2)
+ end
+
+ it 'updates confidence levels for container scanning reports' do
+ projects.create!(id: 123, namespace_id: 12, name: 'gitlab', path: 'gitlab')
+
+ identifiers.create!(id: 1,
+ project_id: 123,
+ fingerprint: 'd432c2ad2953e8bd587a3a43b3ce309b5b0154c2',
+ external_type: 'SECURITY_ID',
+ external_id: 'SECURITY_0',
+ name: 'SECURITY_IDENTIFIER 0')
+
+ identifiers.create!(id: 2,
+ project_id: 123,
+ fingerprint: 'd432c2ad2953e8bd587a3a43b3ce309b5b0154c3',
+ external_type: 'SECURITY_ID',
+ external_id: 'SECURITY_0',
+ name: 'SECURITY_IDENTIFIER 0')
+
+ scanners.create!(id: 6, project_id: 123, external_id: 'clair', name: 'Security Scanner')
+
+ vulnerabilities.create!(id: vul1[:id],
+ severity: 2,
+ confidence: 5,
+ report_type: 2,
+ project_id: 123,
+ scanner_id: 6,
+ primary_identifier_id: 1,
+ project_fingerprint: vul1[:project_fingerprint],
+ location_fingerprint: vul1[:location_fingerprint],
+ uuid: vul1[:uuid],
+ name: vul1[:name],
+ metadata_version: '1.3',
+ raw_metadata: vul1[:raw_metadata])
+
+ vulnerabilities.create!(id: vul2[:id],
+ severity: 2,
+ confidence: 5,
+ report_type: 2,
+ project_id: 123,
+ scanner_id: 6,
+ primary_identifier_id: 2,
+ project_fingerprint: vul2[:project_fingerprint],
+ location_fingerprint: vul2[:location_fingerprint],
+ uuid: vul2[:uuid],
+ name: vul2[:name],
+ metadata_version: '1.3',
+ raw_metadata: vul2[:raw_metadata])
+
+ expect(vulnerabilities.where(report_type: 2, confidence: 2).count). to eq(0)
+ expect(vulnerabilities.exists?(report_type: 2, confidence: 5)).to be_truthy
+
+ migrate!
+
+ expect(vulnerabilities.exists?(report_type: 2, confidence: 5)).to be_falsy
+ expect(vulnerabilities.where(report_type: 2, confidence: 2).count). to eq(2)
+ end
+end