提交 b8dc5554 编写于 作者: J Justin

Merge pull request #166 from presidentbeef/use_multi_json_gem

Use multi_json instead of json_pure gem
...@@ -54,7 +54,8 @@ end ...@@ -54,7 +54,8 @@ end
if options[:previous_results_json] if options[:previous_results_json]
vulns = Brakeman.compare options.merge(:quiet => options[:quiet]) vulns = Brakeman.compare options.merge(:quiet => options[:quiet])
puts JSON.pretty_generate(vulns) puts MultiJson.dump(vulns, :pretty => true)
if options[:exit_on_warn] and (vulns[:new].count + vulns[:fixed].count > 0) if options[:exit_on_warn] and (vulns[:new].count + vulns[:fixed].count > 0)
exit Brakeman::Warnings_Found_Exit_Code exit Brakeman::Warnings_Found_Exit_Code
end end
......
...@@ -19,5 +19,5 @@ Gem::Specification.new do |s| ...@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
s.add_dependency "erubis", "~>2.6" s.add_dependency "erubis", "~>2.6"
s.add_dependency "haml", "~>3.0" s.add_dependency "haml", "~>3.0"
s.add_dependency "sass", "~>3.0" s.add_dependency "sass", "~>3.0"
s.add_dependency "json_pure" s.add_dependency "multi_json"
end end
...@@ -316,19 +316,20 @@ module Brakeman ...@@ -316,19 +316,20 @@ module Brakeman
# Compare JSON ouptut from a previous scan and return the diff of the two scans # Compare JSON ouptut from a previous scan and return the diff of the two scans
def self.compare options def self.compare options
require 'json' require 'multi_json'
require 'brakeman/differ' require 'brakeman/differ'
raise ArgumentError.new("Comparison file doesn't exist") unless File.exists? options[:previous_results_json] raise ArgumentError.new("Comparison file doesn't exist") unless File.exists? options[:previous_results_json]
begin begin
previous_results = JSON.parse(File.read(options[:previous_results_json]), :symbolize_names =>true)[:warnings] previous_results = MultiJson.load(File.read(options[:previous_results_json]), :symbolize_keys => true)[:warnings]
rescue JSON::ParserError rescue MultiJson::DecodeError
self.notify "Error parsing comparison file: #{options[:previous_results_json]}" self.notify "Error parsing comparison file: #{options[:previous_results_json]}"
exit! exit!
end end
tracker = run(options) tracker = run(options)
new_results = JSON.parse(tracker.report.to_json, :symbolize_names =>true)[:warnings]
new_results = MultiJson.load(tracker.report.to_json, :symbolize_keys => true)[:warnings]
Brakeman::Differ.new(new_results, previous_results).diff Brakeman::Differ.new(new_results, previous_results).diff
end end
......
...@@ -6,6 +6,7 @@ require 'brakeman/util' ...@@ -6,6 +6,7 @@ require 'brakeman/util'
require 'terminal-table' require 'terminal-table'
require 'highline/system_extensions' require 'highline/system_extensions'
require "csv" require "csv"
require 'multi_json'
require 'brakeman/version' require 'brakeman/version'
if CSV.const_defined? :Reader if CSV.const_defined? :Reader
...@@ -17,6 +18,15 @@ else ...@@ -17,6 +18,15 @@ else
# CSV is now FasterCSV in ruby 1.9 # CSV is now FasterCSV in ruby 1.9
end end
#This is so OkJson will work with symbol values
if MultiJson.default_engine == :ok_json
class Symbol
def to_json
self.to_s.inspect
end
end
end
#Generates a report based on the Tracker and the results of #Generates a report based on the Tracker and the results of
#Tracker#run_checks. Be sure to +run_checks+ before generating #Tracker#run_checks. Be sure to +run_checks+ before generating
#a report. #a report.
...@@ -647,8 +657,6 @@ class Brakeman::Report ...@@ -647,8 +657,6 @@ class Brakeman::Report
end end
def to_json def to_json
require 'json'
errors = tracker.errors.map{|e| { :error => e[:error], :location => e[:backtrace][0] }} errors = tracker.errors.map{|e| { :error => e[:error], :location => e[:backtrace][0] }}
app_path = tracker.options[:app_path] app_path = tracker.options[:app_path]
...@@ -662,7 +670,7 @@ class Brakeman::Report ...@@ -662,7 +670,7 @@ class Brakeman::Report
:app_path => File.expand_path(tracker.options[:app_path]), :app_path => File.expand_path(tracker.options[:app_path]),
:rails_version => rails_version, :rails_version => rails_version,
:security_warnings => all_warnings.length, :security_warnings => all_warnings.length,
:timestamp => Time.now, :timestamp => Time.now.to_s,
:checks_performed => checks.checks_run.sort, :checks_performed => checks.checks_run.sort,
:number_of_controllers =>tracker.controllers.length, :number_of_controllers =>tracker.controllers.length,
# ignore the "fake" model # ignore the "fake" model
...@@ -672,11 +680,11 @@ class Brakeman::Report ...@@ -672,11 +680,11 @@ class Brakeman::Report
:brakeman_version => Brakeman::Version :brakeman_version => Brakeman::Version
} }
JSON.pretty_generate({ MultiJson.dump({
:scan_info => scan_info, :scan_info => scan_info,
:warnings => warnings, :warnings => warnings,
:errors => errors :errors => errors
}) }, :pretty => true)
end end
def all_warnings def all_warnings
......
require 'multi_json'
#The Warning class stores information about warnings #The Warning class stores information about warnings
class Brakeman::Warning class Brakeman::Warning
attr_reader :called_from, :check, :class, :confidence, :controller, attr_reader :called_from, :check, :class, :confidence, :controller,
...@@ -177,8 +179,6 @@ class Brakeman::Warning ...@@ -177,8 +179,6 @@ class Brakeman::Warning
end end
def to_json def to_json
require 'json' MultiJson.dump self.to_hash
JSON.dump self.to_hash
end end
end end
...@@ -6,7 +6,7 @@ class JSONCompareTests < Test::Unit::TestCase ...@@ -6,7 +6,7 @@ class JSONCompareTests < Test::Unit::TestCase
@json_path = File.join @path, "report.json" @json_path = File.join @path, "report.json"
File.delete @json_path if File.exist? @json_path File.delete @json_path if File.exist? @json_path
Brakeman.run :app_path => @path, :output_files => [@json_path] Brakeman.run :app_path => @path, :output_files => [@json_path]
@report = JSON.parse File.read(@json_path) @report = MultiJson.load File.read(@json_path)
end end
def update_json def update_json
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册