guard-brakeman 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +4 -2
  2. data/lib/guard/brakeman.rb +65 -20
  3. metadata +6 -38
data/README.md CHANGED
@@ -46,8 +46,10 @@ Please read the [Guard documentation](http://github.com/guard/guard#readme) for
46
46
  ### List of available options
47
47
 
48
48
  ```ruby
49
- :notifications => false # display Growl notifications, defaults to true
50
- :run_on_start => true # run all checks on startup, defaults to false
49
+ :notifications => false # display Growl notifications, defaults to true
50
+ :run_on_start => true # run all checks on startup, defaults to false
51
+ :min_confidence => 3 # only alert on warnings above a threshold, defaults to 1
52
+ :chatty => true # notify on ALL changes. Defaults to false, only new or fixed warnings trigger a Growl
51
53
  ```
52
54
 
53
55
  ## Brakeman configuration
@@ -11,9 +11,23 @@ module Guard
11
11
  class Brakeman < Guard
12
12
  def initialize(watchers = [], options = { })
13
13
  super
14
+
15
+ if options[:skip_checks]
16
+ options[:skip_checks] = options[:skip_checks].map do |val|
17
+ # mimic Brakeman::set_options behavior
18
+ val[0,5] == "Check" ? val : "Check" << val
19
+ end
20
+ end
21
+
22
+ # chatty implies notifications
23
+ options[:notifications] = true if options[:chatty]
24
+
25
+ # TODO mixing the use of this attr, good to match? Bad to couple?
14
26
  @options = {
15
27
  :notifications => true,
16
- :run_on_start => false
28
+ :run_on_start => false,
29
+ :chatty => false,
30
+ :min_confidence => 1
17
31
  }.update(options)
18
32
  end
19
33
 
@@ -22,11 +36,15 @@ module Guard
22
36
  # @raise [:task_has_failed] when stop has failed
23
37
  #
24
38
  def start
25
- scanner_opts = ::Brakeman::set_options(:app_path => '.')
39
+ scanner_opts = ::Brakeman::set_options({:app_path => '.'}.merge(@options))
26
40
  @scanner = ::Brakeman::Scanner.new(scanner_opts)
27
41
  @tracker = @scanner.process
28
42
 
29
- run_all if @options[:run_on_start]
43
+ if @options[:run_on_start]
44
+ run_all
45
+ elsif @options[:chatty]
46
+ Notifier.notify("Brakeman is ready to work!", :title => "Brakeman started", :image => :pending)
47
+ end
30
48
  end
31
49
 
32
50
  # Gets called when all checks should be run.
@@ -48,7 +66,7 @@ module Guard
48
66
  def run_on_change(paths)
49
67
  return run_all unless @tracker.checks
50
68
 
51
- UI.info "rescanning #{paths}, running all checks"
69
+ UI.info "\n\nrescanning #{paths}, running all checks"
52
70
  report = ::Brakeman::rescan(@tracker, paths)
53
71
  print_changed(report)
54
72
  throw :task_has_failed if report.any_warnings?
@@ -59,41 +77,68 @@ module Guard
59
77
  def print_failed report
60
78
  UI.info "\n------ brakeman warnings --------\n"
61
79
 
62
- icon = report.all_warnings.count > 0 ? :success : :pending
80
+ icon = report.all_warnings.count > 0 ? :failed : :success
81
+
82
+ all_warnings = reject_below_threshold(report.all_warnings)
63
83
 
64
- Notifier.notify("#{report.all_warnings.count} brakeman findings", :title => "Brakeman results", :image => icon) if @options[:notifications]
65
- puts report.all_warnings.sort_by { |w| w.confidence }
84
+ puts all_warnings.sort_by { |w| w.confidence }
85
+
86
+ if @options[:chatty] && all_warnings.any?
87
+ Notifier.notify("#{all_warnings.count} brakeman findings", :title => "Full Brakeman results", :image => icon)
88
+ end
66
89
  end
67
90
 
68
91
  def print_changed report
69
92
  UI.info "\n------ brakeman warnings --------\n"
70
93
 
71
94
  message = ""
95
+ should_alert = false
72
96
 
73
- unless report.fixed_warnings.empty?
74
- message += "#{report.fixed_warnings.length} fixed warning(s)\n"
97
+ fixed_warnings = reject_below_threshold(report.fixed_warnings)
98
+ if fixed_warnings.any?
75
99
  icon = :success
76
- UI.info(UI.send(:color, message, 'green')) # janky
77
- puts report.fixed_warnings.sort_by { |w| w.confidence }
100
+ results_notification = "#{fixed_warnings.length} fixed warning(s)\n"
101
+ UI.info(UI.send(:color, results_notification, 'green')) # janky
102
+
103
+ should_alert = true
104
+ message += results_notification
105
+
106
+ puts fixed_warnings.sort_by { |w| w.confidence }
78
107
  puts
79
108
  end
80
109
 
81
- unless report.new_warnings.empty?
82
- message += "#{report.new_warnings.length} new warning(s)\n"
110
+ new_warnings = reject_below_threshold(report.new_warnings)
111
+ if new_warnings.any?
112
+ new_warning_message = "#{new_warnings.length} new warning(s)\n"
113
+ UI.error new_warning_message
114
+ message += new_warning_message
115
+
116
+ should_alert = true
83
117
  icon = :failed
84
- UI.error message
85
- puts report.new_warnings.sort_by { |w| w.confidence }
118
+
119
+ puts new_warnings.sort_by { |w| w.confidence }
86
120
  puts
87
121
  end
88
122
 
89
- unless report.existing_warnings.empty?
123
+ existing_warnings = reject_below_threshold(report.existing_warnings)
124
+ if existing_warnings.any?
125
+ should_alert = true if @options[:chatty]
90
126
  icon ||= :pending
91
- message += "#{report.existing_warnings.length} previous warning(s)\n"
92
- UI.warning message
93
- puts report.existing_warnings.sort_by { |w| w.confidence }
127
+
128
+ existing_warning_message = "#{existing_warnings.length} previous warning(s)\n"
129
+ UI.warning existing_warning_message
130
+ message += existing_warning_message
131
+
132
+ puts existing_warnings.sort_by { |w| w.confidence }
133
+ end
134
+
135
+ if @options[:notifications] && should_alert
136
+ Notifier.notify(message.chomp, :title => "Brakeman results", :image => icon)
94
137
  end
138
+ end
95
139
 
96
- Notifier.notify(message.chomp, :title => "Brakeman results", :image => icon) if @options[:notifications]
140
+ def reject_below_threshold(warnings)
141
+ warnings.reject {|w| w.confidence > (3 - @options[:min_confidence].to_i)}
97
142
  end
98
143
  end
99
144
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-brakeman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 8
10
- version: 0.1.8
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Neil Matatall
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-01 00:00:00 -08:00
18
+ date: 2012-02-02 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,38 +50,6 @@ dependencies:
50
50
  version: 1.2.2
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: rspec
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 23
62
- segments:
63
- - 2
64
- - 6
65
- - 0
66
- version: 2.6.0
67
- type: :development
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: guard-rspec
71
- prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- hash: 17
78
- segments:
79
- - 0
80
- - 3
81
- - 1
82
- version: 0.3.1
83
- type: :development
84
- version_requirements: *id004
85
53
  description: Guard::Brakeman automatically scans your Rails app for vulnerabilities
86
54
  email:
87
55
  - neil@matatall.com
@@ -128,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
96
  requirements: []
129
97
 
130
98
  rubyforge_project: guard-brakeman
131
- rubygems_version: 1.6.2
99
+ rubygems_version: 1.6.1
132
100
  signing_key:
133
101
  specification_version: 3
134
102
  summary: Guard gem for Brakeman