Commit 12b4fdb1 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'expose-scan-object' into 'master'

Expose scan object in unsaved findings

See merge request gitlab-org/gitlab!44274
parents 9adada17 52b589e9
...@@ -163,6 +163,17 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle ...@@ -163,6 +163,17 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle
], ],
remediations: %i[ remediations: %i[
diff diff
],
scanner: %i[
external_id
name
vendor
],
scan: %i[
type
status
start_time
end_time
] ]
] ]
end end
......
...@@ -29,6 +29,7 @@ module Vulnerabilities ...@@ -29,6 +29,7 @@ module Vulnerabilities
has_many :pipelines, through: :finding_pipelines, class_name: 'Ci::Pipeline' has_many :pipelines, through: :finding_pipelines, class_name: 'Ci::Pipeline'
attr_writer :sha attr_writer :sha
attr_accessor :scan
CONFIDENCE_LEVELS = { CONFIDENCE_LEVELS = {
# undefined: 0, no longer applicable # undefined: 0, no longer applicable
......
...@@ -34,6 +34,7 @@ class Vulnerabilities::FindingEntity < Grape::Entity ...@@ -34,6 +34,7 @@ class Vulnerabilities::FindingEntity < Grape::Entity
end end
expose :state expose :state
expose :scan
expose :blob_path do |occurrence| expose :blob_path do |occurrence|
occurrence.present.blob_path occurrence.present.blob_path
......
---
title: Expose scan object in unsaved findings
merge_request: 44274
author:
type: other
...@@ -53,6 +53,7 @@ module Gitlab ...@@ -53,6 +53,7 @@ module Gitlab
raw_metadata raw_metadata
report_type report_type
scanner scanner
scan
severity severity
uuid uuid
].each_with_object({}) do |key, hash| ].each_with_object({}) do |key, hash|
......
...@@ -18,6 +18,8 @@ module Gitlab ...@@ -18,6 +18,8 @@ module Gitlab
links links
remediations remediations
target_branch target_branch
scanner
scan
].each { |method_name| define_method(method_name) { @data[method_name] } } ].each { |method_name| define_method(method_name) { @data[method_name] } }
# Ensure mandatory properties are defined # Ensure mandatory properties are defined
......
...@@ -136,7 +136,18 @@ RSpec.describe Projects::VulnerabilityFeedbackController do ...@@ -136,7 +136,18 @@ RSpec.describe Projects::VulnerabilityFeedbackController do
links: [{ links: [{
name: 'Awesome-security blog post', name: 'Awesome-security blog post',
url: 'https;//example.com/blog-post' url: 'https;//example.com/blog-post'
}] }],
scanner: {
external_id: 'bundler-audit',
name: 'bunlder audit',
vendor: 'bundler audit'
},
scan: {
type: 'dependency_scanning',
status: 'success',
start_time: 'placeholder',
end_time: 'placeholder'
}
} }
} }
end end
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"severity", "severity",
"report_type", "report_type",
"scanner", "scanner",
"scan",
"project" "project"
], ],
"properties" : { "properties" : {
...@@ -31,6 +32,13 @@ ...@@ -31,6 +32,13 @@
"external_id" : { "type": "string" }, "external_id" : { "type": "string" },
"name" : { "type": "string" } "name" : { "type": "string" }
}, },
"scan" : {
"end_time": { "type": "string" },
"messages": { "type": "string" },
"start_time": { "type": "string" },
"status": { "type": "string" },
"type": { "type": "string" }
},
"project" : { "project" : {
"required" : [ "required" : [
"id", "id",
......
...@@ -91,6 +91,7 @@ RSpec.describe Gitlab::Ci::Reports::Security::Finding do ...@@ -91,6 +91,7 @@ RSpec.describe Gitlab::Ci::Reports::Security::Finding do
raw_metadata: occurrence.raw_metadata, raw_metadata: occurrence.raw_metadata,
report_type: occurrence.report_type, report_type: occurrence.report_type,
scanner: occurrence.scanner, scanner: occurrence.scanner,
scan: occurrence.scan,
severity: occurrence.severity, severity: occurrence.severity,
uuid: occurrence.uuid uuid: occurrence.uuid
}) })
......
...@@ -19,7 +19,9 @@ RSpec.describe Gitlab::Vulnerabilities::BaseVulnerability do ...@@ -19,7 +19,9 @@ RSpec.describe Gitlab::Vulnerabilities::BaseVulnerability do
], ],
links: [{ name: 'Awesome-security blog post', url: 'https;//example.com/blog-post' }], links: [{ name: 'Awesome-security blog post', url: 'https;//example.com/blog-post' }],
location: { file: 'main.rb', start_line: 14, blob_path: '/bar/foo/main.rb#14' }, location: { file: 'main.rb', start_line: 14, blob_path: '/bar/foo/main.rb#14' },
solution: 'upgrade dependencies' solution: 'upgrade dependencies',
scanner: { external_id: 'gemnasium', name: 'Gemnasium' },
scan: { external_id: 'gemnasium', name: 'Gemnasium' }
} }
end end
...@@ -34,7 +36,7 @@ RSpec.describe Gitlab::Vulnerabilities::BaseVulnerability do ...@@ -34,7 +36,7 @@ RSpec.describe Gitlab::Vulnerabilities::BaseVulnerability do
end end
describe 'getters' do describe 'getters' do
where(:getter) { %i[severity confidence solution identifiers links remediations target_branch] } where(:getter) { %i[severity confidence solution identifiers links remediations target_branch scan scanner] }
let(:with_nil) { described_class.new({}) } let(:with_nil) { described_class.new({}) }
......
...@@ -52,7 +52,6 @@ RSpec.describe API::VulnerabilityFindings do ...@@ -52,7 +52,6 @@ RSpec.describe API::VulnerabilityFindings do
finding_count = (sast_report.findings.count + ds_report.findings.count - 1).to_s finding_count = (sast_report.findings.count + ds_report.findings.count - 1).to_s
get api(project_vulnerability_findings_path, user), params: pagination get api(project_vulnerability_findings_path, user), params: pagination
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(response).to match_response_schema('vulnerabilities/finding_list', dir: 'ee') expect(response).to match_response_schema('vulnerabilities/finding_list', dir: 'ee')
......
...@@ -3,36 +3,37 @@ ...@@ -3,36 +3,37 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Vulnerabilities::FindingEntity do RSpec.describe Vulnerabilities::FindingEntity do
let_it_be(:user) { create(:user) } let_it_be(:user) { build(:user) }
let_it_be(:project) { create(:project) } let_it_be(:project) { build(:project) }
let(:scanner) do let(:scanner) { build(:vulnerabilities_scanner, project: project) }
create(:vulnerabilities_scanner, project: project)
end let(:scan) { build(:ci_reports_security_scan) }
let(:identifiers) do let(:identifiers) do
[ [
create(:vulnerabilities_identifier), build(:vulnerabilities_identifier),
create(:vulnerabilities_identifier) build(:vulnerabilities_identifier)
] ]
end end
let(:occurrence) do let(:occurrence) do
create( build(
:vulnerabilities_occurrence, :vulnerabilities_occurrence,
scanner: scanner, scanner: scanner,
scan: scan,
project: project, project: project,
identifiers: identifiers identifiers: identifiers
) )
end end
let!(:dismiss_feedback) do let(:dismiss_feedback) do
create(:vulnerability_feedback, :sast, :dismissal, build(:vulnerability_feedback, :sast, :dismissal,
project: project, project_fingerprint: occurrence.project_fingerprint) project: project, project_fingerprint: occurrence.project_fingerprint)
end end
let!(:issue_feedback) do let(:issue_feedback) do
create(:vulnerability_feedback, :sast, :issue, build(:vulnerability_feedback, :sast, :issue,
project: project, project_fingerprint: occurrence.project_fingerprint) project: project, project_fingerprint: occurrence.project_fingerprint)
end end
...@@ -56,6 +57,7 @@ RSpec.describe Vulnerabilities::FindingEntity do ...@@ -56,6 +57,7 @@ RSpec.describe Vulnerabilities::FindingEntity do
expect(subject).to include(:dismissal_feedback, :issue_feedback) expect(subject).to include(:dismissal_feedback, :issue_feedback)
expect(subject).to include(:description, :links, :location, :remediations, :solution, :evidence) expect(subject).to include(:description, :links, :location, :remediations, :solution, :evidence)
expect(subject).to include(:blob_path, :request, :response) expect(subject).to include(:blob_path, :request, :response)
expect(subject).to include(:scan)
end end
context 'when not allowed to admin vulnerability feedback' do context 'when not allowed to admin vulnerability feedback' 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