Commit 10736e4f authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '284071-refactor-vulnerability-description-template' into 'master'

Resolve "Follow-up from "Remove safe navigation operator from Vulnerability description""

See merge request gitlab-org/gitlab!53192
parents e7397ee1 5945f702
...@@ -67,4 +67,8 @@ module VulnerabilitiesHelper ...@@ -67,4 +67,8 @@ module VulnerabilitiesHelper
data[:location].merge!('blob_path' => vulnerability.blob_path).compact! data[:location].merge!('blob_path' => vulnerability.blob_path).compact!
data data
end end
def vulnerability_scan_data?(vulnerability)
vulnerability.scanner.present? || vulnerability.scan.present?
end
end end
...@@ -60,25 +60,26 @@ ...@@ -60,25 +60,26 @@
</details> </details>
<% end %> <% end %>
<% end %> <% end %>
<% if vulnerability.scanner.present? || vulnerability.scan.present? %> <% if vulnerability_scan_data?(vulnerability) %>
### <%= _("Scanner") %>: ### <%= _("Scanner") %>:
<% if vulnerability.scanner.present? %> <% if vulnerability.scanner.present? %>
* <%= _("Name") %>: <%= vulnerability.scanner[:name] %> * <%= _("Name") %>: <%= vulnerability.scanner[:name] %>
<% end %> <% end %>
<% if vulnerability.scan.present? %> <%- scan_data = vulnerability.scan -%>
<% if vulnerability.scan[:type].present? %> <% if scan_data.present? %>
* <%= _("Type") %>: <%= vulnerability.scan[:type] %> <% if scan_data[:type].present? %>
* <%= _("Type") %>: <%= scan_data[:type] %>
<% end %> <% end %>
<% if vulnerability.scan[:status].present? %> <% if scan_data[:status].present? %>
* <%= _("Status") %>: <%= vulnerability.scan[:status] %> * <%= _("Status") %>: <%= scan_data[:status] %>
<% end %> <% end %>
<% if vulnerability.scan[:start_time].present? %> <% if scan_data[:start_time].present? %>
* <%= _("Start Time") %>: <%= vulnerability.scan[:start_time] %> * <%= _("Start Time") %>: <%= scan_data[:start_time] %>
<% end %> <% end %>
<% if vulnerability.scan[:end_time].present? %> <% if scan_data[:end_time].present? %>
* <%= _("End Time") %>: <%= vulnerability.scan[:end_time] %> * <%= _("End Time") %>: <%= scan_data[:end_time] %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
...@@ -52,24 +52,25 @@ h3. <%= _("Links") %>: ...@@ -52,24 +52,25 @@ h3. <%= _("Links") %>:
<%= _("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)}]" } %>
<% end %> <% end %>
<% if vulnerability.scanner.present? || vulnerability.scan.present? %> <% if vulnerability_scan_data?(vulnerability) %>
h3. <%= _("Scanner") %>: h3. <%= _("Scanner") %>:
<% if vulnerability.scanner.present? %> <% if vulnerability.scanner.present? %>
* <%= _("Name") %>: <%= vulnerability.scanner[:name] %> * <%= _("Name") %>: <%= vulnerability.scanner[:name] %>
<% end %> <% end %>
<% if vulnerability.scan.present? %> <%- scan_data = vulnerability.scan -%>
<% if vulnerability.scan.type.present? %> <% if scan_data.present? %>
* <%= _("Type") %>: <%= vulnerability.scan.type %> <% if scan_data.type.present? %>
* <%= _("Type") %>: <%= scan_data.type %>
<% end %> <% end %>
<% if vulnerability.scan.status.present? %> <% if scan_data.status.present? %>
* <%= _("Status") %>: <%= vulnerability.scan.status %> * <%= _("Status") %>: <%= scan_data.status %>
<% end %> <% end %>
<% if vulnerability.scan.start_time.present? %> <% if scan_data.start_time.present? %>
* <%= _("Start Time") %>: <%= vulnerability.scan.start_time %> * <%= _("Start Time") %>: <%= scan_data.start_time %>
<% end %> <% end %>
<% if vulnerability.scan.end_time.present? %> <% if scan_data.end_time.present? %>
* <%= _("End Time") %>: <%= vulnerability.scan.end_time %> * <%= _("End Time") %>: <%= scan_data.end_time %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
...@@ -285,4 +285,34 @@ RSpec.describe VulnerabilitiesHelper do ...@@ -285,4 +285,34 @@ RSpec.describe VulnerabilitiesHelper do
end end
end end
end end
describe '#vulnerability_scan_data?' do
subject { helper.vulnerability_scan_data?(vulnerability) }
context 'scanner present' do
before do
allow(vulnerability).to receive(:scanner).and_return(true)
end
it { is_expected.to be_truthy }
end
context 'scan present' do
before do
allow(vulnerability).to receive(:scanner).and_return(false)
allow(vulnerability).to receive(:scan).and_return(true)
end
it { is_expected.to be_truthy }
end
context 'neither scan nor scanner being present' do
before do
allow(vulnerability).to receive(:scanner).and_return(false)
allow(vulnerability).to receive(:scan).and_return(false)
end
it { is_expected.to be_falsey }
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