Collects up results from running different checks.
Checks can be added with +Check.add(check_class)+
All .rb files in checks/ will be loaded.
Add a check. This will call klass.new when running tests
# File lib/brakeman/checks.rb, line 15 def self.add klass @checks << klass end
No need to use this directly.
# File lib/brakeman/checks.rb, line 24 def initialize options = { } if options[:min_confidence] @min_confidence = options[:min_confidence] else @min_confidence = Brakeman.get_defaults[:min_confidence] end @warnings = [] @template_warnings = [] @model_warnings = [] @controller_warnings = [] @checks_run = [] end
Run all the checks on the given Tracker. Returns a new instance of Checks with the results.
# File lib/brakeman/checks.rb, line 78 def self.run_checks(app_tree, tracker) if tracker.options[:parallel_checks] self.run_checks_parallel(app_tree, tracker) else self.run_checks_sequential(app_tree, tracker) end end
Run checks in parallel threads
# File lib/brakeman/checks.rb, line 121 def self.run_checks_parallel(app_tree, tracker) threads = [] error_mutex = Mutex.new check_runner = self.new :min_confidence => tracker.options[:min_confidence] @checks.each do |c| check_name = get_check_name c #Run or don't run check based on options unless tracker.options[:skip_checks].include? check_name or (tracker.options[:run_checks] and not tracker.options[:run_checks].include? check_name) Brakeman.notify " - #{check_name}" threads << Thread.new do check = c.new(app_tree, tracker) begin check.run_check rescue Exception => e error_mutex.synchronize do tracker.error e end end check.warnings end #Maintain list of which checks were run #mainly for reporting purposes check_runner.checks_run << check_name[5..-1] end end threads.each { |t| t.join } Brakeman.notify "Checks finished, collecting results..." #Collect results threads.each do |thread| thread.value.each do |warning| check_runner.add_warning warning end end check_runner end
Run checks sequentially
# File lib/brakeman/checks.rb, line 87 def self.run_checks_sequential(app_tree, tracker) check_runner = self.new :min_confidence => tracker.options[:min_confidence] @checks.each do |c| check_name = get_check_name c #Run or don't run check based on options unless tracker.options[:skip_checks].include? check_name or (tracker.options[:run_checks] and not tracker.options[:run_checks].include? check_name) Brakeman.notify " - #{check_name}" check = c.new(app_tree, tracker) begin check.run_check rescue Exception => e tracker.error e end check.warnings.each do |w| check_runner.add_warning w end #Maintain list of which checks were run #mainly for reporting purposes check_runner.checks_run << check_name[5..-1] end end check_runner end
Add Warning to list of warnings to report. Warnings are split into four different arrays for template, controller, model, and generic warnings.
Will not add warnings which are below the minimum confidence level.
# File lib/brakeman/checks.rb, line 43 def add_warning warning unless warning.confidence > @min_confidence case warning.warning_set when :template @template_warnings << warning when :warning @warnings << warning when :controller @controller_warnings << warning when :model @model_warnings << warning else raise "Unknown warning: #{warning.warning_set}" end end end
Return an array of all warnings found.
# File lib/brakeman/checks.rb, line 72 def all_warnings @warnings + @template_warnings + @controller_warnings + @model_warnings end
Return a hash of arrays of new and fixed warnings
diff = checks.diff old_checks diff[:fixed] # [...] diff[:new] # [...]
# File lib/brakeman/checks.rb, line 65 def diff other_checks my_warnings = self.all_warnings other_warnings = other_checks.all_warnings Brakeman::Differ.new(my_warnings, other_warnings).diff end
Generated with the Darkfish Rdoc Generator 2.