Skip to content
Snippets Groups Projects
Verified Commit b5911b90 authored by Miki Amos's avatar Miki Amos Committed by GitLab
Browse files

Try new logic in vulnerability to get the severity override data

parent 153e41c8
No related branches found
No related tags found
2 merge requests!180858Resolve "Add Severity Overrides to Vulnerability Report API Calls",!180727Resolve "Extend job archival mechanism to the whole pipeline"
......@@ -37,7 +37,8 @@ def vulnerability_details(vulnerability, pipeline)
issue_tracking_help_path: help_page_path('user/project/issues/_index.md'),
permissions_help_path: help_page_path('user/permissions.md', anchor: 'project-members-permissions'),
dismissal_descriptions: dismissal_descriptions,
representation_information: format_vulnerability_representation_information(vulnerability.representation_information)
representation_information: format_vulnerability_representation_information(vulnerability.representation_information),
severity_override: severity_override_data(vulnerability)
}
result.merge(vulnerability_data(vulnerability), vulnerability_finding_data(vulnerability))
......@@ -47,6 +48,21 @@ def dismissal_descriptions
Vulnerabilities::DismissalReasonEnum.translated_descriptions
end
def severity_override_data(vulnerability)
severity_override = vulnerability.severity_overrides.last
return unless severity_override
{
id: severity_override.id,
original_severity: severity_override.original_severity,
new_severity: severity_override.new_severity,
author: {
name: severity_override.author.name,
web_url: user_path(severity_override.author)
}
}
end
def new_issue_url_for(vulnerability)
return unless vulnerability.project.issues_enabled?
......
......@@ -60,7 +60,6 @@ module Vulnerability
has_many :related_issues, through: :issue_links, source: :issue, disable_joins: true
has_many :state_transitions, class_name: '::Vulnerabilities::StateTransition', inverse_of: :vulnerability
has_many :severity_overrides, class_name: '::Vulnerabilities::SeverityOverride', inverse_of: :vulnerability
has_many :notes, as: :noteable
has_many :user_mentions, class_name: 'VulnerabilityUserMention'
......
......@@ -6,7 +6,7 @@
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, :public) }
let_it_be(:pipeline) { create(:ci_pipeline, :success, project: project) }
let_it_be(:finding) { create(:vulnerabilities_finding, :with_pipeline, :with_cve, project: project, severity: :high) }
let_it_be_with_refind(:finding) { create(:vulnerabilities_finding, :with_pipeline, :with_cve, project: project, severity: :high) }
let_it_be(:advisory) { create(:pm_advisory, cve: finding.cve_value) }
let_it_be(:cve_enrichment_object) { create(:pm_cve_enrichment, cve: finding.cve_value) }
......@@ -123,7 +123,7 @@
allow(helper).to receive(:can?).and_return(true)
end
subject { helper.vulnerability_details(vulnerability, pipeline) }
subject(:vulnerability_details) { helper.vulnerability_details(vulnerability, pipeline) }
describe '[:can_modify_related_issues]' do
context 'with security dashboard feature enabled' do
......@@ -219,6 +219,37 @@
end
end
end
describe '[:severity_override]' do
subject(:severity_override) { vulnerability_details[:severity_override] }
context 'when there is no severity override for the vulnerability' do
it { is_expected.to be_nil }
end
context 'when there are severity overrides for the vulnerability' do
let!(:author) { create(:user) }
let!(:old_severity_override) do
create(:vulnerability_severity_override, vulnerability: vulnerability, author: author)
end
let!(:most_recent_severity_override) do
create(:vulnerability_severity_override, vulnerability: vulnerability, author: author)
end
it 'contains the information from the most recent severity override record' do
expect(severity_override).to include(
id: most_recent_severity_override.id,
new_severity: 'critical',
original_severity: 'low',
author: {
name: author.name,
web_url: user_path(author)
}
)
end
end
end
end
describe '#create_jira_issue_url_for' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment