Class: Brakeman::Report::Markdown

Inherits:
Table
  • Object
show all
Defined in:
lib/brakeman/report/report_markdown.rb

Defined Under Namespace

Classes: MarkdownTable

Constant Summary

Constants inherited from Base

Base::TEXT_CONFIDENCE

Constants included from Util

Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION, Util::SESSION_SEXP

Instance Attribute Summary

Attributes inherited from Base

#checks, #tracker

Instance Method Summary collapse

Methods inherited from Table

#generate_overview, #generate_templates, #render_array, #text_header

Methods inherited from Base

#all_warnings, #controller_warnings, #convert_controller_warning, #convert_ignored_warning, #convert_model_warning, #convert_template_warning, #convert_to_rows, #filter_warnings, #generate_controller_warnings, #generate_controllers, #generate_errors, #generate_ignored_warnings, #generate_model_warnings, #generate_obsolete, #generate_template_warnings, #generate_warning_overview, #generate_warnings, #generic_warnings, #ignored_warnings, #model_warnings, #number_of_templates, #rails_version, #render_warnings, #sort, #template_warnings, #text_message, #warning_file, #warnings_summary

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #github_url, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #table_to_csv, #template_path_to_name, #true?, #truncate_table, #underscore

Constructor Details

#initialize(*args) ⇒ Markdown

Returns a new instance of Markdown.



24
25
26
27
# File 'lib/brakeman/report/report_markdown.rb', line 24

def initialize *args
  super
  @table = MarkdownTable
end

Instance Method Details

#convert_warning(warning, original) ⇒ Object



86
87
88
89
90
91
# File 'lib/brakeman/report/report_markdown.rb', line 86

def convert_warning warning, original
  warning["Confidence"] = TEXT_CONFIDENCE[warning["Confidence"]]
  warning["Message"] = markdown_message original, warning["Message"]
  warning["Warning Type"] = "[#{warning['Warning Type']}](#{original.link})" if original.link
  warning
end

#generate_checksObject



80
81
82
83
84
# File 'lib/brakeman/report/report_markdown.rb', line 80

def generate_checks
  MarkdownTable.new(:headings => ['Checks performed']) do |t|
    t.add_row([checks.checks_run.sort.join(", ")])
  end
end

#generate_metadataObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/brakeman/report/report_markdown.rb', line 65

def 
  MarkdownTable.new(
    :headings =>
      ['Application path', 'Rails version', 'Brakeman version', 'Started at', 'Duration']
  ) do |t|
    t.add_row([
      tracker.app_path,
      rails_version,
      Brakeman::Version,
      tracker.start_time,
      "#{tracker.duration} seconds",
    ])
  end
end

#generate_reportObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/brakeman/report/report_markdown.rb', line 29

def generate_report
  out = "# BRAKEMAN REPORT\n\n" <<
  .to_s << "\n\n" <<
  generate_checks.to_s << "\n\n" <<
  "### SUMMARY\n\n" <<
  generate_overview.to_s << "\n\n" <<
  generate_warning_overview.to_s << "\n\n"

  #Return output early if only summarizing
  return out if tracker.options[:summary_only]

  if tracker.options[:report_routes] or tracker.options[:debug]
    out << "### CONTROLLERS"  << "\n\n" <<
    generate_controllers.to_s << "\n\n"
  end

  if tracker.options[:debug]
    out << "### TEMPLATES\n\n" <<
    generate_templates.to_s << "\n\n"
  end

  output_table("Errors", generate_errors, out)
  output_table("SECURITY WARNINGS", generate_warnings, out)
  output_table("Controller Warnings:", generate_controller_warnings, out)
  output_table("Model Warnings:", generate_model_warnings, out)
  output_table("View Warnings:", generate_template_warnings, out)

  out
end

#markdown_message(warning, message) ⇒ Object

Escape and code format warning message



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/brakeman/report/report_markdown.rb', line 94

def markdown_message warning, message
  if warning.file
    github_url = github_url warning.file, warning.line
    message.gsub!(/(near line \d+)/, "[\\1](#{github_url})") if github_url
  end
  if warning.code
    code = warning.format_code
    message.gsub(code, "`#{code.gsub('`','``').gsub(/\A``|``\z/, '` `')}`")
  else
    message
  end
end

#output_table(title, result, output) ⇒ Object



59
60
61
62
63
# File 'lib/brakeman/report/report_markdown.rb', line 59

def output_table title, result, output
  return unless result

  output << "### #{title}\n\n#{result.to_s}\n\n"
end