Commit 2227509d authored by Michał Zając's avatar Michał Zając

Add vulnerability_finding_data method

parent c8de8e68
...@@ -12,6 +12,7 @@ module VulnerabilitiesHelper ...@@ -12,6 +12,7 @@ module VulnerabilitiesHelper
finding: Vulnerabilities::OccurrenceSerializer.new({}).represent(@vulnerability.finding).to_json, finding: Vulnerabilities::OccurrenceSerializer.new({}).represent(@vulnerability.finding).to_json,
has_mr: !!@vulnerability.finding.merge_request_feedback.try(:merge_request_iid), has_mr: !!@vulnerability.finding.merge_request_feedback.try(:merge_request_iid),
vulnerability_feedback_help_path: help_page_path("user/application_security/index", anchor: "interacting-with-the-vulnerabilities"), vulnerability_feedback_help_path: help_page_path("user/application_security/index", anchor: "interacting-with-the-vulnerabilities"),
finding_json: vulnerability_finding_data(vulnerability.finding).to_json
} }
end end
...@@ -24,4 +25,18 @@ module VulnerabilitiesHelper ...@@ -24,4 +25,18 @@ module VulnerabilitiesHelper
url: pipeline_path(pipeline) url: pipeline_path(pipeline)
} }
end end
def vulnerability_finding_data(finding, current_user: nil)
occurrence = Vulnerabilities::OccurrenceSerializer.new(current_user: current_user).represent(finding)
remediation = occurrence[:remediations]&.first
{
description: occurrence[:description],
identifiers: occurrence[:identifiers],
links: occurrence[:links],
location: occurrence[:location],
name: occurrence[:name],
solution: remediation ? remediation['summary'] : occurrence[:solution]
}
end
end end
...@@ -50,4 +50,16 @@ describe VulnerabilitiesHelper do ...@@ -50,4 +50,16 @@ describe VulnerabilitiesHelper do
end end
end end
end end
describe '#vulnerability_finding_data' do
let(:vulnerability) { create(:vulnerability, :with_findings) }
let(:finding) { vulnerability.finding }
subject { helper.vulnerability_finding_data(finding) }
it "returns finding information" do
expect(subject[:name]).not_to be_nil
expect(subject[:description]).not_to be_nil
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