Commit de4fcbbf authored by Lucas Charles's avatar Lucas Charles

chore: Update security parser specs with programmatic UUID generation

Previously, hardcoded UUIDs were difficult to read and work with. Since
these are generated programmatically, we can do so to improve
readability and maintainability of our code.
parent 460736b1
...@@ -282,21 +282,23 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do ...@@ -282,21 +282,23 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do
end end
describe 'setting the uuid' do describe 'setting the uuid' do
let(:location) { build(:ci_reports_security_locations_sast) }
let(:finding_uuids) { report.findings.map(&:uuid) } let(:finding_uuids) { report.findings.map(&:uuid) }
let(:uuid_1) do let(:uuid_1) do
Security::VulnerabilityUUID.generate( Security::VulnerabilityUUID.generate(
report_type: "dependency_scanning", report_type: "sast",
primary_identifier_fingerprint: "4ff8184cd18485b6e85d5b101e341b12eacd1b3b", primary_identifier_fingerprint: report.findings[0].identifiers.first.fingerprint,
location_fingerprint: "33dc9f32c77dde16d39c69d3f78f27ca3114a7c5", location_fingerprint: location.fingerprint,
project_id: pipeline.project_id project_id: pipeline.project_id
) )
end end
let(:uuid_2) do let(:uuid_2) do
Security::VulnerabilityUUID.generate( Security::VulnerabilityUUID.generate(
report_type: "dependency_scanning", report_type: "sast",
primary_identifier_fingerprint: "d55f9e66e79882ae63af9fd55cc822ab75307e31", primary_identifier_fingerprint: report.findings[1].identifiers.first.fingerprint,
location_fingerprint: "33dc9f32c77dde16d39c69d3f78f27ca3114a7c5", location_fingerprint: location.fingerprint,
project_id: pipeline.project_id project_id: pipeline.project_id
) )
end end
...@@ -304,9 +306,13 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do ...@@ -304,9 +306,13 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Common do
let(:expected_uuids) { [uuid_1, uuid_2, nil] } let(:expected_uuids) { [uuid_1, uuid_2, nil] }
it 'sets the UUIDv5 for findings', :aggregate_failures do it 'sets the UUIDv5 for findings', :aggregate_failures do
allow_next_instance_of(Gitlab::Ci::Reports::Security::Report) do |report|
allow(report).to receive(:type).and_return('sast')
expect(finding_uuids).to match_array(expected_uuids) expect(finding_uuids).to match_array(expected_uuids)
end end
end end
end
describe 'parsing tracking' do describe 'parsing tracking' do
let(:tracking_data) do let(:tracking_data) do
......
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