Class: Bundler::Audit::Presenter::Junit
- Inherits:
-
Base
- Object
- Base
- Bundler::Audit::Presenter::Junit
show all
- Defined in:
- lib/bundler/audit/presenter/junit.rb
Instance Attribute Summary
Attributes inherited from Base
#options, #shell
Instance Method Summary
collapse
Methods inherited from Base
#exit_code, #initialize, #problematic?, #push_advisory, #push_warning
Instance Method Details
#advisory_criticality(advisory) ⇒ Object
21
22
23
24
25
26
27
28
|
# 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) ⇒ Object
13
14
15
16
17
18
19
|
# 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) ⇒ Object
30
31
32
33
34
35
36
|
# 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) ⇒ Object
38
39
40
|
# 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
|
#print_report ⇒ Object
7
8
9
|
# File 'lib/bundler/audit/presenter/junit.rb', line 7
def print_report
puts ERB.new(template_string, nil, '-').result(binding)
end
|
#template_string ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/bundler/audit/presenter/junit.rb', line 53
def template_string
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<testsuites id=\"<%= Time.now.to_i %>\" name=\"Bundle Audit\" tests=\"225\" failures=\"1262\">\n <testsuite id=\"Gemfile\" name=\"Ruby Gemfile\" failures=\"<%= @advisory_bundles.size %>\">\n <%- @advisory_bundles.each do |bundle| -%>\n <testcase id=\"<%= xml_escape(bundle.gem.name) %>\" name=\"<%= bundle_title(bundle) %>\">\n <failure message=\"<%= xml_escape(bundle.advisory.title) %>\" type=\"<%= xml_escape(bundle.advisory.criticality) %>\">\nName: <%= xml_escape(bundle.gem.name) %>\nVersion: <%= xml_escape(bundle.gem.version) %>\nAdvisory: <%= advisory_ref(bundle.advisory) %>\nCriticality: <%= advisory_criticality(bundle.advisory) %>\nURL: <%= xml_escape(bundle.advisory.url) %>\nTitle: <%= xml_escape(bundle.advisory.title) %>\nSolution: <%= advisory_solution(bundle.advisory) %>\n </failure>\n </testcase>\n <%- end -%>\n </testsuite>\n</testsuites>\n HERE\nend\n".strip
|
#xml_escape(string) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/bundler/audit/presenter/junit.rb', line 42
def xml_escape(string)
string.gsub(
/[<>"'&]/,
'<' => '<',
'>' => '>',
'"' => '"',
'\'' => ''',
'&' => '&',
)
end
|