Commit 18d5d5fe authored by Michał Zając's avatar Michał Zając

Remove attributes_for from background migration spec

With https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52182 we
banned `attributes_for` in migration specs. This refactors one of the
offending migrations.
parent e3121749
...@@ -76,7 +76,8 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicatedCsFindingsWithoutVul ...@@ -76,7 +76,8 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicatedCsFindingsWithoutVul
end end
def finding_params(primary_identifier_id, project_id) def finding_params(primary_identifier_id, project_id)
attrs = attributes_for(:vulnerabilities_finding) # rubocop: disable RSpec/FactoriesInMigrationSpecs uuid = SecureRandom.uuid
{ {
severity: 0, severity: 0,
confidence: 5, confidence: 5,
...@@ -84,23 +85,32 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicatedCsFindingsWithoutVul ...@@ -84,23 +85,32 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicatedCsFindingsWithoutVul
project_id: project_id, project_id: project_id,
scanner_id: 6, scanner_id: 6,
primary_identifier_id: primary_identifier_id, primary_identifier_id: primary_identifier_id,
project_fingerprint: attrs[:project_fingerprint], project_fingerprint: SecureRandom.hex(20),
location_fingerprint: Digest::SHA1.hexdigest(SecureRandom.hex(10)), location_fingerprint: Digest::SHA1.hexdigest(SecureRandom.hex(10)),
uuid: SecureRandom.uuid, uuid: uuid,
name: attrs[:name], name: "Vulnerability Finding #{uuid}",
metadata_version: '1.3', metadata_version: '1.3',
raw_metadata: attrs[:raw_metadata] raw_metadata: raw_metadata
} }
end end
def create_identifier(number_of) def raw_metadata
(1..number_of).each do |identifier_id| { "description" => "The cipher does not provide data integrity update 1",
identifiers.create!(id: identifier_id, "message" => "The cipher does not provide data integrity",
project_id: 123, "cve" => "818bf5dacb291e15d9e6dc3c5ac32178:CIPHER",
fingerprint: 'd432c2ad2953e8bd587a3a43b3ce309b5b0154c' + identifier_id.to_s, "solution" => "GCM mode introduces an HMAC into the resulting encrypted data, providing integrity of the result.",
external_type: 'SECURITY_ID', "location" => { "file" => "maven/src/main/java/com/gitlab/security_products/tests/App.java", "start_line" => 29, "end_line" => 29, "class" => "com.gitlab.security_products.tests.App", "method" => "insecureCypher" },
external_id: 'SECURITY_0', "links" => [{ "name" => "Cipher does not check for integrity first?", "url" => "https://crypto.stackexchange.com/questions/31428/pbewithmd5anddes-cipher-does-not-check-for-integrity-first" }],
name: 'SECURITY_IDENTIFIER 0') "assets" => [{ "type" => "postman", "name" => "Test Postman Collection", "url" => "http://localhost/test.collection" }],
end "evidence" =>
{ "summary" => "Credit card detected",
"request" => { "headers" => [{ "name" => "Accept", "value" => "*/*" }], "method" => "GET", "url" => "http://goat:8080/WebGoat/logout", "body" => nil },
"response" => { "headers" => [{ "name" => "Content-Length", "value" => "0" }], "reason_phrase" => "OK", "status_code" => 200, "body" => nil },
"source" => { "id" => "assert:Response Body Analysis", "name" => "Response Body Analysis", "url" => "htpp://hostname/documentation" },
"supporting_messages" =>
[{ "name" => "Origional", "request" => { "headers" => [{ "name" => "Accept", "value" => "*/*" }], "method" => "GET", "url" => "http://goat:8080/WebGoat/logout", "body" => "" } },
{ "name" => "Recorded",
"request" => { "headers" => [{ "name" => "Accept", "value" => "*/*" }], "method" => "GET", "url" => "http://goat:8080/WebGoat/logout", "body" => "" },
"response" => { "headers" => [{ "name" => "Content-Length", "value" => "0" }], "reason_phrase" => "OK", "status_code" => 200, "body" => "" } }] } }
end end
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