class Bundler::Audit::Presenter::Junit

Public Instance Methods

print_report() click to toggle source

Protected Instance Methods

advisory_criticality(advisory) click to toggle source
# File lib/bundler/audit/presenter/junit.rb, line 21
def advisory_criticality(advisory)
  case advisory.criticality
  when :low    then "Low"
  when :medium then "Medium"
  when :high   then "High"
  else              "Unknown"
  end
end
advisory_ref(advisory) click to toggle source
# File lib/bundler/audit/presenter/junit.rb, line 13
def advisory_ref(advisory)
  if advisory.cve
    xml_escape "CVE-#{advisory.cve}"
  elsif advisory.osvdb
    xml_escape advisory.osvdb
  end
end
advisory_solution(advisory) click to toggle source
# File lib/bundler/audit/presenter/junit.rb, line 30
def advisory_solution(advisory)
  unless advisory.patched_versions.empty?
    xml_escape "upgrade to #{advisory.patched_versions.join(', ')}"
  else
    "remove or disable this gem until a patch is available!"
  end
end
bundle_title(bundle) click to toggle source
# File lib/bundler/audit/presenter/junit.rb, line 38
def bundle_title(bundle)
  xml_escape "#{advisory_criticality(bundle.advisory).upcase} #{bundle.gem.name}(#{bundle.gem.version}) #{bundle.advisory.title}"
end
template_string() click to toggle source
# File lib/bundler/audit/presenter/junit.rb, line 53
        def template_string
          <<-HERE.strip

<testsuites id="<%= Time.now.to_i %>" name="Bundle Audit" tests="225" failures="1262">
  <testsuite id="Gemfile" name="Ruby Gemfile" failures="<%= @advisory_bundles.size %>">
    <%- @advisory_bundles.each do |bundle| -%>
    <testcase id="<%= xml_escape(bundle.gem.name) %>" name="<%= bundle_title(bundle) %>">
      <failure message="<%= xml_escape(bundle.advisory.title) %>" type="<%= xml_escape(bundle.advisory.criticality) %>">
Name: <%= xml_escape(bundle.gem.name) %>
Version: <%= xml_escape(bundle.gem.version) %>
Advisory: <%= advisory_ref(bundle.advisory) %>
Criticality: <%= advisory_criticality(bundle.advisory) %>
URL: <%= xml_escape(bundle.advisory.url) %>
Title: <%= xml_escape(bundle.advisory.title) %>
Solution: <%= advisory_solution(bundle.advisory) %>
      </failure>
    </testcase>
    <%- end -%>
  </testsuite>
</testsuites>
          HERE
        end
xml_escape(string) click to toggle source
# File lib/bundler/audit/presenter/junit.rb, line 42
def xml_escape(string)
  string.to_s.gsub(
    /[<>"'&]/,
    '<' => '&lt;',
    '>' => '&gt;',
    '"' => '&quot;',
    '\'' => '&apos;',
    '&' => '&amp;',
  )
end