guard-brakeman 0.5.0 → 0.5.1
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.
- data/README.md +1 -2
- data/lib/guard/brakeman.rb +72 -35
- data/lib/guard/brakeman/templates/Guardfile +1 -1
- metadata +10 -10
data/README.md
CHANGED
@@ -27,7 +27,7 @@ $ guard init brakeman
|
|
27
27
|
|
28
28
|
## Use sublime Text 2?
|
29
29
|
|
30
|
-
Check out [sublime_guard](https://github.com/cyphactor/sublime_guard)! It gives you control Guard without leaving the editor. This is even more powerful with Growl notifications. Enter distraction-free mode and never leave!
|
30
|
+
Check out [sublime_guard](https://github.com/cyphactor/sublime_guard)! It gives you control Guard without leaving the editor. This is even more powerful with Growl notifications. Enter distraction-free mode and never leave!
|
31
31
|
|
32
32
|
## Usage
|
33
33
|
|
@@ -85,7 +85,6 @@ Pull requests are very welcome! Please try to follow these simple rules if appli
|
|
85
85
|
|
86
86
|
* Please create a topic branch for every separate change you make.
|
87
87
|
* Make sure your patches are well tested.
|
88
|
-
* Update the [Yard](http://yardoc.org/) documentation.
|
89
88
|
* Update the README.
|
90
89
|
* Update the CHANGELOG for noteworthy changes.
|
91
90
|
* Please **do not change** the version number.
|
data/lib/guard/brakeman.rb
CHANGED
@@ -12,8 +12,10 @@ module Guard
|
|
12
12
|
def initialize(watchers = [], options = { })
|
13
13
|
super
|
14
14
|
|
15
|
+
::Brakeman.instance_variable_set(:@quiet, options[:quiet])
|
16
|
+
|
15
17
|
if options[:skip_checks]
|
16
|
-
options[:skip_checks] = options[:skip_checks].map do |val|
|
18
|
+
options[:skip_checks] = options[:skip_checks].map do |val|
|
17
19
|
# mimic Brakeman::set_options behavior
|
18
20
|
val[0,5] == "Check" ? val : "Check" << val
|
19
21
|
end
|
@@ -24,10 +26,10 @@ module Guard
|
|
24
26
|
|
25
27
|
# TODO mixing the use of this attr, good to match? Bad to couple?
|
26
28
|
@options = {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
:notifications => true,
|
30
|
+
:run_on_start => false,
|
31
|
+
:chatty => false,
|
32
|
+
:min_confidence => 1
|
31
33
|
}.update(options)
|
32
34
|
end
|
33
35
|
|
@@ -38,11 +40,10 @@ module Guard
|
|
38
40
|
def start
|
39
41
|
@scanner_opts = ::Brakeman::set_options({:app_path => '.'}.merge(@options))
|
40
42
|
@options.merge!(@scanner_opts)
|
41
|
-
|
42
43
|
@tracker = ::Brakeman::Scanner.new(@scanner_opts).process
|
43
44
|
|
44
45
|
if @options[:run_on_start]
|
45
|
-
run_all
|
46
|
+
run_all
|
46
47
|
elsif @options[:chatty]
|
47
48
|
::Guard::Notifier.notify("Brakeman is ready to work!", :title => "Brakeman started", :image => :pending)
|
48
49
|
end
|
@@ -53,7 +54,6 @@ module Guard
|
|
53
54
|
# @raise [:task_has_failed] when stop has failed
|
54
55
|
#
|
55
56
|
def run_all
|
56
|
-
UI.info 'running all'
|
57
57
|
@tracker.run_checks
|
58
58
|
print_failed(@tracker.checks)
|
59
59
|
throw :task_has_failed if @tracker.checks.all_warnings.any?
|
@@ -82,71 +82,76 @@ module Guard
|
|
82
82
|
|
83
83
|
all_warnings = report.all_warnings
|
84
84
|
|
85
|
-
puts all_warnings.sort_by { |w| w.confidence }
|
86
|
-
|
87
85
|
message = "#{all_warnings.count} brakeman findings"
|
88
86
|
|
89
87
|
if @options[:output_files]
|
90
88
|
write_report
|
91
|
-
message += "\nResults written to #{@options[:output_files]}"
|
89
|
+
message += "\nResults written to #{@options[:output_files]}"
|
92
90
|
end
|
93
91
|
|
94
92
|
if @options[:chatty] && all_warnings.any?
|
95
|
-
::Guard::Notifier.notify(message, :title => "Full Brakeman results", :image => icon)
|
93
|
+
::Guard::Notifier.notify(message, :title => "Full Brakeman results", :image => icon)
|
96
94
|
end
|
95
|
+
|
96
|
+
info(message, 'yellow')
|
97
|
+
warning_info(all_warnings.sort_by { |w| w.confidence })
|
97
98
|
end
|
98
99
|
|
99
100
|
def print_changed report
|
100
101
|
UI.info "\n------ brakeman warnings --------\n"
|
101
|
-
|
102
|
-
message =
|
102
|
+
|
103
|
+
message = []
|
103
104
|
should_alert = false
|
104
105
|
|
105
106
|
fixed_warnings = report.fixed_warnings
|
106
107
|
if fixed_warnings.any?
|
107
|
-
icon = :success
|
108
108
|
results_notification = pluralize(fixed_warnings.length, "fixed warning")
|
109
|
-
|
110
|
-
|
111
|
-
should_alert = true
|
112
|
-
message += results_notification
|
109
|
+
info(results_notification, 'green')
|
110
|
+
warning_info(fixed_warnings.sort_by { |w| w.confidence })
|
113
111
|
|
114
|
-
|
115
|
-
|
112
|
+
message << results_notification
|
113
|
+
should_alert = true
|
114
|
+
icon = :success
|
116
115
|
end
|
117
116
|
|
118
117
|
new_warnings = report.new_warnings
|
119
118
|
if new_warnings.any?
|
120
119
|
new_warning_message = pluralize(new_warnings.length, "new warning")
|
121
|
-
|
120
|
+
info(new_warning_message, 'red')
|
121
|
+
warning_info(new_warnings.sort_by { |w| w.confidence })
|
122
122
|
|
123
|
-
message
|
123
|
+
message << new_warning_message
|
124
124
|
should_alert = true
|
125
125
|
icon = :failed
|
126
|
-
|
127
|
-
puts new_warnings.sort_by { |w| w.confidence }
|
128
|
-
puts ""
|
129
126
|
end
|
130
127
|
|
131
128
|
existing_warnings = report.existing_warnings
|
132
129
|
if existing_warnings.any?
|
133
|
-
should_alert = true if @options[:chatty]
|
134
|
-
icon ||= :pending
|
135
|
-
|
136
130
|
existing_warning_message = pluralize(existing_warnings.length, "previous warning")
|
137
|
-
|
138
|
-
|
131
|
+
info(existing_warning_message, 'yellow')
|
132
|
+
warning_info(existing_warnings.sort_by { |w| w.confidence })
|
139
133
|
|
140
|
-
|
134
|
+
message << existing_warning_message
|
135
|
+
should_alert = true if @options[:chatty]
|
136
|
+
icon ||= :pending
|
141
137
|
end
|
142
138
|
|
143
139
|
if @options[:output_files]
|
144
140
|
write_report
|
145
|
-
message
|
141
|
+
message << "\nResults written to #{@options[:output_files]}"
|
142
|
+
end
|
143
|
+
|
144
|
+
title = case icon
|
145
|
+
when :success
|
146
|
+
pluralize(fixed_warnings.length, "Warning") + " fixed."
|
147
|
+
when :pending
|
148
|
+
pluralize(existing_warnings.length, "Warning") + " left to fix."
|
149
|
+
when :failed
|
150
|
+
pluralize(new_warnings.length, "Warning") + " introduced."
|
146
151
|
end
|
147
152
|
|
148
153
|
if @options[:notifications] && should_alert
|
149
|
-
::Guard::Notifier.notify(message.chomp, :title =>
|
154
|
+
::Guard::Notifier.notify(message.join(", ").chomp, :title => title, :image => icon)
|
150
155
|
end
|
151
156
|
end
|
152
157
|
|
@@ -158,9 +163,41 @@ module Guard
|
|
158
163
|
end
|
159
164
|
end
|
160
165
|
|
161
|
-
# stolen from
|
166
|
+
# stolen from ActiveSupport
|
162
167
|
def pluralize(count, singular, plural = nil)
|
163
168
|
"#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize))
|
164
169
|
end
|
170
|
+
|
171
|
+
def info(message, color = :white)
|
172
|
+
UI.info(UI.send(:color, message, color))
|
173
|
+
end
|
174
|
+
|
175
|
+
def warning_info(warnings, color = :white)
|
176
|
+
warnings.each do |warning|
|
177
|
+
info(decorate_warning(warning))
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def decorate_warning(warning)
|
182
|
+
color = case warning.confidence
|
183
|
+
when 0
|
184
|
+
:red
|
185
|
+
when 1
|
186
|
+
:yellow
|
187
|
+
when 2
|
188
|
+
:white
|
189
|
+
end
|
190
|
+
|
191
|
+
output = UI.send(:color, ::Brakeman::Warning::TEXT_CONFIDENCE[warning.confidence], color)
|
192
|
+
output << " - #{warning.warning_type} - #{warning.message}"
|
193
|
+
output << " near line #{warning.line}" if warning.line
|
194
|
+
if warning.file
|
195
|
+
# fix this ish or wait for brakeman to be fixed
|
196
|
+
filename = warning.file.gsub(@options[:app_path], '')
|
197
|
+
output << " in #{filename}"
|
198
|
+
end
|
199
|
+
output << ": #{warning.format_code}" if warning.code
|
200
|
+
output
|
201
|
+
end
|
165
202
|
end
|
166
203
|
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:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Neil Matatall
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-10-08 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: guard
|
@@ -40,14 +40,14 @@ dependencies:
|
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 11
|
46
46
|
segments:
|
47
47
|
- 1
|
48
|
-
-
|
49
|
-
-
|
50
|
-
version: 1.
|
48
|
+
- 7
|
49
|
+
- 0
|
50
|
+
version: 1.7.0
|
51
51
|
type: :runtime
|
52
52
|
version_requirements: *id002
|
53
53
|
description: Guard::Brakeman automatically scans your Rails app for vulnerabilities
|
@@ -70,7 +70,7 @@ post_install_message:
|
|
70
70
|
rdoc_options:
|
71
71
|
- --charset=UTF-8
|
72
72
|
- --main=README.md
|
73
|
-
- --exclude='(
|
73
|
+
- --exclude='(test|spec)|(Gem|Guard|Rake)file'
|
74
74
|
require_paths:
|
75
75
|
- lib
|
76
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|