Commit b686da25 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Don't try to generate url for an finding records

With this fix, we are not trying to generate URL for finding records
while building the JIRA issue description of a vulnerability.

Changelog: fixed
EE: true
parent 431bbba6
...@@ -15,6 +15,11 @@ module Vulnerabilities ...@@ -15,6 +15,11 @@ module Vulnerabilities
add_line_numbers(location['start_line'], location['end_line']) add_line_numbers(location['start_line'], location['end_line'])
end end
delegator_override :links
def links
@links ||= finding.links.map(&:with_indifferent_access)
end
private private
def add_line_numbers(start_line, end_line) def add_line_numbers(start_line, end_line)
......
...@@ -46,7 +46,7 @@ h3. <%= _("Links") %>: ...@@ -46,7 +46,7 @@ h3. <%= _("Links") %>:
<% end %> <% end %>
<% end %> <% end %>
<% if vulnerability.remediations.present? && vulnerability.remediations.any? %> <% if vulnerability.is_a?(Vulnerability) && vulnerability.remediations.present? %>
### <%= _("Remediations") %>: ### <%= _("Remediations") %>:
<%= _("See vulnerability %{vulnerability_link} for any Remediation details.".html_safe) % { vulnerability_link: "[#{vulnerability.id}|#{vulnerability_url(vulnerability)}]" } %> <%= _("See vulnerability %{vulnerability_link} for any Remediation details.".html_safe) % { vulnerability_link: "[#{vulnerability.id}|#{vulnerability_url(vulnerability)}]" } %>
......
...@@ -195,7 +195,7 @@ RSpec.describe VulnerabilitiesHelper do ...@@ -195,7 +195,7 @@ RSpec.describe VulnerabilitiesHelper do
end end
describe '#create_jira_issue_url_for' do describe '#create_jira_issue_url_for' do
subject { helper.vulnerability_details(vulnerability, pipeline) } subject { helper.create_jira_issue_url_for(vulnerability) }
let(:jira_integration) { double('Integrations::Jira', new_issue_url_with_predefined_fields: 'https://jira.example.com/new') } let(:jira_integration) { double('Integrations::Jira', new_issue_url_with_predefined_fields: 'https://jira.example.com/new') }
...@@ -210,6 +210,7 @@ RSpec.describe VulnerabilitiesHelper do ...@@ -210,6 +210,7 @@ RSpec.describe VulnerabilitiesHelper do
allow(project).to receive(:configured_to_create_issues_from_vulnerabilities?).and_return(true) allow(project).to receive(:configured_to_create_issues_from_vulnerabilities?).and_return(true)
end end
context 'when the given object is a vulnerability' do
let(:expected_jira_issue_description) do let(:expected_jira_issue_description) do
<<-JIRA.strip_heredoc <<-JIRA.strip_heredoc
Issue created from vulnerability [#{vulnerability.id}|http://localhost/#{project.full_path}/-/security/vulnerabilities/#{vulnerability.id}] Issue created from vulnerability [#{vulnerability.id}|http://localhost/#{project.full_path}/-/security/vulnerabilities/#{vulnerability.id}]
...@@ -244,10 +245,6 @@ RSpec.describe VulnerabilitiesHelper do ...@@ -244,10 +245,6 @@ RSpec.describe VulnerabilitiesHelper do
subject subject
end end
it 'generates url to create issue in Jira' do
expect(subject[:create_jira_issue_url]).to eq('https://jira.example.com/new')
end
context 'when scan property is empty' do context 'when scan property is empty' do
before do before do
vulnerability.finding.scan = nil vulnerability.finding.scan = nil
...@@ -261,13 +258,45 @@ RSpec.describe VulnerabilitiesHelper do ...@@ -261,13 +258,45 @@ RSpec.describe VulnerabilitiesHelper do
end end
end end
context 'when the given object is an unpersisted finding' do
let(:vulnerability) { build(:vulnerabilities_finding, :with_remediation, project: project) }
let(:expected_jira_issue_description) do
<<~TEXT
h3. Description:
The cipher does not provide data integrity update 1
* Severity: high
* Confidence: medium
h3. Links:
* [Cipher does not check for integrity first?|https://crypto.stackexchange.com/questions/31428/pbewithmd5anddes-cipher-does-not-check-for-integrity-first]
h3. Scanner:
* Name: Find Security Bugs
TEXT
end
it 'delegates rendering URL to Integrations::Jira' do
expect(jira_integration).to receive(:new_issue_url_with_predefined_fields).with("Investigate vulnerability: #{vulnerability.name}", expected_jira_issue_description)
subject
end
end
end
context 'with jira vulnerabilities integration disabled' do context 'with jira vulnerabilities integration disabled' do
before do before do
allow(project).to receive(:jira_vulnerabilities_integration_enabled?).and_return(false) allow(project).to receive(:jira_vulnerabilities_integration_enabled?).and_return(false)
allow(project).to receive(:configured_to_create_issues_from_vulnerabilities?).and_return(false) allow(project).to receive(:configured_to_create_issues_from_vulnerabilities?).and_return(false)
end end
it { expect(subject[:create_jira_issue_url]).to be_nil } it { is_expected.to be_nil }
end end
end end
......
...@@ -72,4 +72,18 @@ RSpec.describe Vulnerabilities::FindingPresenter do ...@@ -72,4 +72,18 @@ RSpec.describe Vulnerabilities::FindingPresenter do
end end
end end
end end
describe '#links' do
let(:link_name) { 'Cipher does not check for integrity first?' }
let(:link_url) { 'https://crypto.stackexchange.com/questions/31428/pbewithmd5anddes-cipher-does-not-check-for-integrity-first' }
subject(:links) { presenter.links }
it 'transforms the links to hash with indifferent access', :aggregate_failures do
expect(links.first['name']).to eq(link_name)
expect(links.first[:name]).to eq(link_name)
expect(links.first['url']).to eq(link_url)
expect(links.first[:url]).to eq(link_url)
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