Commit b676d825 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'revert-2beec806' into 'master'

Revert !50283 to fix a broken master

See merge request gitlab-org/gitlab!52150
parents e12af2f3 5f9d7214
...@@ -80,25 +80,15 @@ module Security ...@@ -80,25 +80,15 @@ module Security
} }
begin begin
# Look for existing Findings using UUID vulnerability_finding = project
vulnerability_finding = project.vulnerability_findings.find_by(uuid: finding.uuid) .vulnerability_findings
.create_with(create_params)
# If there's no Finding then we're dealing with one of two cases: .find_or_initialize_by(find_params)
# 1. The Finding is a new one
# 2. The Finding is already saved but has UUIDv4
unless vulnerability_finding
vulnerability_finding = project.vulnerability_findings
.create_with(create_params)
.find_or_initialize_by(find_params)
vulnerability_finding.uuid = finding.uuid
end
vulnerability_finding.save! vulnerability_finding.save!
vulnerability_finding vulnerability_finding
rescue ActiveRecord::RecordNotUnique => e rescue ActiveRecord::RecordNotUnique
Gitlab::ErrorTracking.track_and_raise_exception(e, find_params: find_params, uuid: finding.uuid) project.vulnerability_findings.find_by!(find_params)
vulnerability_finding
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
Gitlab::ErrorTracking.track_and_raise_exception(e, create_params: create_params&.dig(:raw_metadata)) Gitlab::ErrorTracking.track_and_raise_exception(e, create_params: create_params&.dig(:raw_metadata))
end end
......
...@@ -31,9 +31,7 @@ FactoryBot.define do ...@@ -31,9 +31,7 @@ FactoryBot.define do
scanner factory: :ci_reports_security_scanner scanner factory: :ci_reports_security_scanner
severity { :high } severity { :high }
scan factory: :ci_reports_security_scan scan factory: :ci_reports_security_scan
sequence(:uuid) do |n| sequence(:uuid) { generate(:vulnerability_finding_uuid) }
Gitlab::UUID.v5("#{report_type}-#{identifiers.first&.fingerprint}-#{location.fingerprint}-#{n}")
end
skip_create skip_create
......
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.define do FactoryBot.define do
sequence :vulnerability_finding_uuid do |n|
SecureRandom.uuid
end
factory :vulnerabilities_finding_with_remediation, parent: :vulnerabilities_finding do factory :vulnerabilities_finding_with_remediation, parent: :vulnerabilities_finding do
transient do transient do
summary { nil } summary { nil }
...@@ -43,13 +47,11 @@ FactoryBot.define do ...@@ -43,13 +47,11 @@ FactoryBot.define do
factory :vulnerabilities_finding, class: 'Vulnerabilities::Finding' do factory :vulnerabilities_finding, class: 'Vulnerabilities::Finding' do
name { 'Cipher with no integrity' } name { 'Cipher with no integrity' }
project project
sequence(:uuid) { generate(:vulnerability_finding_uuid) }
project_fingerprint { generate(:project_fingerprint) } project_fingerprint { generate(:project_fingerprint) }
primary_identifier factory: :vulnerabilities_identifier primary_identifier factory: :vulnerabilities_identifier
location_fingerprint { SecureRandom.hex(20) } location_fingerprint { '4e5b6966dd100170b4b1ad599c7058cce91b57b4' }
report_type { :sast } report_type { :sast }
sequence(:uuid) do
Gitlab::UUID.v5("#{report_type}-#{primary_identifier.fingerprint}-#{location_fingerprint}-#{project_id}")
end
severity { :high } severity { :high }
confidence { :medium } confidence { :medium }
scanner factory: :vulnerabilities_scanner scanner factory: :vulnerabilities_scanner
......
...@@ -124,16 +124,9 @@ RSpec.describe Security::StoreReportService, '#execute' do ...@@ -124,16 +124,9 @@ RSpec.describe Security::StoreReportService, '#execute' do
primary_identifier: identifier, primary_identifier: identifier,
scanner: scanner, scanner: scanner,
project: project, project: project,
uuid: "80571acf-8660-4bc8-811a-1d8dec9ab6f4",
location_fingerprint: 'd869ba3f0b3347eb2749135a437dc07c8ae0f420') location_fingerprint: 'd869ba3f0b3347eb2749135a437dc07c8ae0f420')
end end
let(:uuid_v5_components) do
"#{finding.report_type}-#{finding.primary_identifier.fingerprint}-#{finding.location_fingerprint}-#{finding.project_id}"
end
let(:desired_uuid) { Gitlab::UUID.v5(uuid_v5_components) }
let!(:vulnerability) { create(:vulnerability, findings: [finding], project: project) } let!(:vulnerability) { create(:vulnerability, findings: [finding], project: project) }
before do before do
...@@ -143,12 +136,6 @@ RSpec.describe Security::StoreReportService, '#execute' do ...@@ -143,12 +136,6 @@ RSpec.describe Security::StoreReportService, '#execute' do
subject { described_class.new(new_pipeline, new_report).execute } subject { described_class.new(new_pipeline, new_report).execute }
it 'updates UUIDv4 to UUIDv5' do
subject
expect(finding.reload.uuid).to eq(desired_uuid)
end
it 'inserts only new scanners and reuse existing ones' do it 'inserts only new scanners and reuse existing ones' do
expect { subject }.to change { Vulnerabilities::Scanner.count }.by(2) expect { subject }.to change { Vulnerabilities::Scanner.count }.by(2)
end end
...@@ -171,13 +158,11 @@ RSpec.describe Security::StoreReportService, '#execute' do ...@@ -171,13 +158,11 @@ RSpec.describe Security::StoreReportService, '#execute' do
it 'updates existing findings with new data' do it 'updates existing findings with new data' do
subject subject
expect(finding.reload).to have_attributes(severity: 'medium', name: 'Probable insecure usage of temp file/directory.') expect(finding.reload).to have_attributes(severity: 'medium', name: 'Probable insecure usage of temp file/directory.')
end end
it 'updates existing vulnerability with new data' do it 'updates existing vulnerability with new data' do
subject subject
expect(vulnerability.reload).to have_attributes(severity: 'medium', title: 'Probable insecure usage of temp file/directory.', title_html: 'Probable insecure usage of temp file/directory.') expect(vulnerability.reload).to have_attributes(severity: 'medium', title: 'Probable insecure usage of temp file/directory.', title_html: 'Probable insecure usage of temp file/directory.')
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