red_alert 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -1
- data/lib/red_alert.rb +2 -0
- data/lib/red_alert/cleaner.rb +35 -0
- data/lib/red_alert/const.rb +15 -0
- data/lib/red_alert/notifier.rb +7 -1
- data/lib/red_alert/rack/notifier.rb +5 -0
- data/lib/red_alert/version.rb +1 -1
- data/spec/red_alert/cleaner_spec.rb +65 -0
- data/spec/red_alert/notifier_spec.rb +9 -2
- data/spec/red_alert/rack/notifier_spec.rb +15 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 835ff34cab230a96c3dc7a6972095cba661ca988
|
4
|
+
data.tar.gz: b00cc6f956ae826e0a7cb095ab11dc13679ed07e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0357b0a2161ce655c08a6fefaea8546da251ddd1b30d6c89d62cd544f647fb04f0d10f0e211060da919e12f95c2f421022eecf9f0547c7fe7873f17e6cd9140
|
7
|
+
data.tar.gz: 3eb0419a57d2db742af88b3eebcce69b42615ce7cb5b5af3e5bec2fc58d017658ded88d4fb3174f2ffbd546d5d315f9e7c9093de3b8828b9ab3feb0feebb06aa
|
data/Rakefile
CHANGED
data/lib/red_alert.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module RedAlert
|
2
|
+
class Cleaner
|
3
|
+
FILTERED_TEXT = '[REMOVED]'
|
4
|
+
RECURSIVE_TEXT = '[RECURSIVE STRUCTURE]'
|
5
|
+
|
6
|
+
attr_reader :filter_keys
|
7
|
+
|
8
|
+
def initialize(filter_keys)
|
9
|
+
@filter_keys = filter_keys.to_set
|
10
|
+
end
|
11
|
+
|
12
|
+
def scrub(params)
|
13
|
+
formatted = format(params)
|
14
|
+
formatted.each do |key, value|
|
15
|
+
if filter_keys.include? key
|
16
|
+
formatted[key] = FILTERED_TEXT
|
17
|
+
elsif value.respond_to? :to_hash
|
18
|
+
formatted[key] = scrub value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def format(value, stack = Set.new)
|
24
|
+
return RECURSIVE_TEXT if stack.include? value.object_id
|
25
|
+
|
26
|
+
if value.respond_to? :to_ary
|
27
|
+
value.map{|v| format v, stack + [value.object_id]}
|
28
|
+
elsif value.respond_to? :to_hash
|
29
|
+
value.each_with_object({}){|(k,v), memo| memo[k] = format v, stack + [value.object_id]}
|
30
|
+
else
|
31
|
+
value.nil? ? nil : value.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RedAlert
|
2
|
+
RACK_DEFAULT_FILTERS = %w{
|
3
|
+
rack.request.cookie_hash
|
4
|
+
rack.request.cookie_string
|
5
|
+
rack.request.form_vars
|
6
|
+
rack.session
|
7
|
+
rack.session.options
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
PARAMS_DEFAULT_FILTERS = %w{
|
11
|
+
password
|
12
|
+
password_confirm
|
13
|
+
password_confirmation
|
14
|
+
}.freeze
|
15
|
+
end
|
data/lib/red_alert/notifier.rb
CHANGED
@@ -10,8 +10,14 @@ module RedAlert
|
|
10
10
|
@notifier_settings ||= {}
|
11
11
|
end
|
12
12
|
|
13
|
+
def filter_keys
|
14
|
+
PARAMS_DEFAULT_FILTERS
|
15
|
+
end
|
16
|
+
|
13
17
|
def alert(exception, data = {})
|
14
|
-
|
18
|
+
cleaner = Cleaner.new(filter_keys)
|
19
|
+
cleaned_data = cleaner.scrub data
|
20
|
+
notification = Notification.build notifier_settings[:subject], template, exception, cleaned_data
|
15
21
|
mail = Mail.new(
|
16
22
|
to: notifier_settings[:to],
|
17
23
|
from: notifier_settings[:from],
|
data/lib/red_alert/version.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RedAlert::Cleaner do
|
4
|
+
let(:filter_keys) { ['foo', 'bar'] }
|
5
|
+
|
6
|
+
subject { RedAlert::Cleaner.new(filter_keys) }
|
7
|
+
|
8
|
+
it 'filters keys from a hash' do
|
9
|
+
result = subject.scrub('foo' => 'secret', 'baz' => 'cool')
|
10
|
+
result['foo'].must_equal RedAlert::Cleaner::FILTERED_TEXT
|
11
|
+
result['baz'].must_equal 'cool'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns a new hash' do
|
15
|
+
input = {'qux' => 'val'}
|
16
|
+
subject.scrub(input).wont_be_same_as input
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'filters nested hashes' do
|
20
|
+
input = {'zing' => {'foo' => 'secret'}}
|
21
|
+
result = subject.scrub(input)
|
22
|
+
result['zing']['foo'].must_equal RedAlert::Cleaner::FILTERED_TEXT
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'stringifys with unserializable data' do
|
26
|
+
bad_data = lambda { puts 'hello' }
|
27
|
+
input = {'zing' => bad_data}
|
28
|
+
result = subject.scrub(input)
|
29
|
+
assert_equal result['zing'], bad_data.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'stringifys with unserializable data in arrays' do
|
33
|
+
bad_data = lambda { puts 'hello' }
|
34
|
+
input = {'zing' => [bad_data]}
|
35
|
+
result = subject.scrub(input)
|
36
|
+
assert_equal result['zing'].first, bad_data.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'stringifys ints' do
|
40
|
+
input = {'zing' => 1}
|
41
|
+
result = subject.scrub(input)
|
42
|
+
result['zing'].must_equal '1'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'handles recursive arrays' do
|
46
|
+
a = []
|
47
|
+
a << a
|
48
|
+
input = {'zing' => a}
|
49
|
+
result = subject.scrub(input)
|
50
|
+
result['zing'].first.must_equal RedAlert::Cleaner::RECURSIVE_TEXT
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'handles recursive hashes' do
|
54
|
+
input = {}
|
55
|
+
input['zing'] = {'self' => input}
|
56
|
+
result = subject.scrub(input)
|
57
|
+
result['zing']['self'].must_equal RedAlert::Cleaner::RECURSIVE_TEXT
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'handles nil' do
|
61
|
+
input = {'zing' => nil}
|
62
|
+
result = subject.scrub(input)
|
63
|
+
result['zing'].must_equal nil
|
64
|
+
end
|
65
|
+
end
|
@@ -47,7 +47,7 @@ describe RedAlert::Notifier do
|
|
47
47
|
enable_starttls_auto: true
|
48
48
|
} }
|
49
49
|
|
50
|
-
subject { TestNotifier.new 'test template <%= exception %> |<%= data
|
50
|
+
subject { TestNotifier.new 'test template <%= exception %> |<%= data %>|' }
|
51
51
|
|
52
52
|
before do
|
53
53
|
subject.to to
|
@@ -67,12 +67,19 @@ describe RedAlert::Notifier do
|
|
67
67
|
notification.to.must_include to
|
68
68
|
notification.from.must_include from
|
69
69
|
notification.subject.must_equal 'test subject something bad happened'
|
70
|
-
notification.body.to_s.must_equal 'test template something bad happened |here|'
|
70
|
+
notification.body.to_s.must_equal 'test template something bad happened |{:stuff=>"here"}|'
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'uses settings' do
|
74
74
|
result = subject.alert(exception).delivery_method.settings
|
75
75
|
result.must_equal settings
|
76
76
|
end
|
77
|
+
|
78
|
+
it 'strips sensitive params' do
|
79
|
+
data['password'] = 'secret'
|
80
|
+
subject.alert exception, data
|
81
|
+
message = deliveries.first
|
82
|
+
message.body.to_s.must_include RedAlert::Cleaner::FILTERED_TEXT
|
83
|
+
end
|
77
84
|
end
|
78
85
|
end
|
@@ -12,11 +12,24 @@ describe RedAlert::Rack::Notifier do
|
|
12
12
|
after { deliveries.clear }
|
13
13
|
|
14
14
|
it 'alerts' do
|
15
|
+
expected = SecureRandom.hex
|
15
16
|
begin
|
16
17
|
raise 'boom'
|
17
18
|
rescue => e
|
18
|
-
subject.alert(e, request: 'data', env: { 'in' =>
|
19
|
-
deliveries.
|
19
|
+
subject.alert(e, request: 'data', env: { 'in' => expected })
|
20
|
+
message = deliveries.first
|
21
|
+
message.body.to_s.must_include expected
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'removes sensitive rack params' do
|
26
|
+
expected = SecureRandom.hex
|
27
|
+
begin
|
28
|
+
raise 'boom'
|
29
|
+
rescue => e
|
30
|
+
subject.alert(e, request: 'data', env: { 'rack.session' => expected })
|
31
|
+
message = deliveries.first
|
32
|
+
message.body.to_s.wont_include expected
|
20
33
|
end
|
21
34
|
end
|
22
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red_alert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vyrak.bunleang@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -37,6 +37,8 @@ files:
|
|
37
37
|
- README.md
|
38
38
|
- Rakefile
|
39
39
|
- lib/red_alert.rb
|
40
|
+
- lib/red_alert/cleaner.rb
|
41
|
+
- lib/red_alert/const.rb
|
40
42
|
- lib/red_alert/notification.rb
|
41
43
|
- lib/red_alert/notifier.rb
|
42
44
|
- lib/red_alert/rack.rb
|
@@ -47,6 +49,7 @@ files:
|
|
47
49
|
- lib/red_alert/sidekiq/notifier.rb
|
48
50
|
- lib/red_alert/version.rb
|
49
51
|
- red_alert.gemspec
|
52
|
+
- spec/red_alert/cleaner_spec.rb
|
50
53
|
- spec/red_alert/notification_spec.rb
|
51
54
|
- spec/red_alert/notifier_spec.rb
|
52
55
|
- spec/red_alert/rack/middleware_spec.rb
|
@@ -78,6 +81,7 @@ signing_key:
|
|
78
81
|
specification_version: 4
|
79
82
|
summary: Middlewares for mailing errors
|
80
83
|
test_files:
|
84
|
+
- spec/red_alert/cleaner_spec.rb
|
81
85
|
- spec/red_alert/notification_spec.rb
|
82
86
|
- spec/red_alert/notifier_spec.rb
|
83
87
|
- spec/red_alert/rack/middleware_spec.rb
|