airbrake-ruby 2.2.3 → 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airbrake-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airbrake Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-11 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -115,7 +115,6 @@ files:
115
115
  - lib/airbrake-ruby/config.rb
116
116
  - lib/airbrake-ruby/config/validator.rb
117
117
  - lib/airbrake-ruby/filter_chain.rb
118
- - lib/airbrake-ruby/filters.rb
119
118
  - lib/airbrake-ruby/filters/gem_root_filter.rb
120
119
  - lib/airbrake-ruby/filters/keys_blacklist.rb
121
120
  - lib/airbrake-ruby/filters/keys_filter.rb
@@ -126,10 +125,10 @@ files:
126
125
  - lib/airbrake-ruby/nested_exception.rb
127
126
  - lib/airbrake-ruby/notice.rb
128
127
  - lib/airbrake-ruby/notifier.rb
129
- - lib/airbrake-ruby/payload_truncator.rb
130
128
  - lib/airbrake-ruby/promise.rb
131
129
  - lib/airbrake-ruby/response.rb
132
130
  - lib/airbrake-ruby/sync_sender.rb
131
+ - lib/airbrake-ruby/truncator.rb
133
132
  - lib/airbrake-ruby/version.rb
134
133
  - spec/airbrake_spec.rb
135
134
  - spec/async_sender_spec.rb
@@ -137,18 +136,20 @@ files:
137
136
  - spec/config/validator_spec.rb
138
137
  - spec/config_spec.rb
139
138
  - spec/filter_chain_spec.rb
139
+ - spec/filters/gem_root_filter_spec.rb
140
140
  - spec/filters/keys_blacklist_spec.rb
141
+ - spec/filters/keys_whitelist_spec.rb
142
+ - spec/filters/root_directory_filter_spec.rb
143
+ - spec/filters/system_exit_filter_spec.rb
141
144
  - spec/filters/thread_filter_spec.rb
142
145
  - spec/nested_exception_spec.rb
143
146
  - spec/notice_spec.rb
144
147
  - spec/notifier_spec.rb
145
- - spec/notifier_spec/blacklist_keys_spec.rb
146
148
  - spec/notifier_spec/options_spec.rb
147
- - spec/notifier_spec/whitelist_keys_spec.rb
148
- - spec/payload_truncator_spec.rb
149
149
  - spec/promise_spec.rb
150
150
  - spec/spec_helper.rb
151
151
  - spec/sync_sender_spec.rb
152
+ - spec/truncator_spec.rb
152
153
  homepage: https://airbrake.io
153
154
  licenses:
154
155
  - MIT
@@ -180,15 +181,17 @@ test_files:
180
181
  - spec/config/validator_spec.rb
181
182
  - spec/config_spec.rb
182
183
  - spec/filter_chain_spec.rb
184
+ - spec/filters/gem_root_filter_spec.rb
183
185
  - spec/filters/keys_blacklist_spec.rb
186
+ - spec/filters/keys_whitelist_spec.rb
187
+ - spec/filters/root_directory_filter_spec.rb
188
+ - spec/filters/system_exit_filter_spec.rb
184
189
  - spec/filters/thread_filter_spec.rb
185
190
  - spec/nested_exception_spec.rb
186
191
  - spec/notice_spec.rb
187
- - spec/notifier_spec/blacklist_keys_spec.rb
188
192
  - spec/notifier_spec/options_spec.rb
189
- - spec/notifier_spec/whitelist_keys_spec.rb
190
193
  - spec/notifier_spec.rb
191
- - spec/payload_truncator_spec.rb
192
194
  - spec/promise_spec.rb
193
195
  - spec/spec_helper.rb
194
196
  - spec/sync_sender_spec.rb
197
+ - spec/truncator_spec.rb
@@ -1,10 +0,0 @@
1
- module Airbrake
2
- ##
3
- # Represents a namespace for default Airbrake Ruby filters.
4
- module Filters
5
- ##
6
- # @return [Array<Symbol>] parts of a Notice's payload that can be modified
7
- # by various filters
8
- FILTERABLE_KEYS = %i[environment session params].freeze
9
- end
10
- end
@@ -1,192 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe "Airbrake::Notifier blacklist_keys" do
4
- def expect_a_request_with_body(body)
5
- expect(a_request(:post, endpoint).with(body: body)).to have_been_made.once
6
- end
7
-
8
- let(:project_id) { 105138 }
9
- let(:project_key) { 'fd04e13d806a90f96614ad8e529b2822' }
10
- let(:localhost) { 'http://localhost:8080' }
11
-
12
- let(:endpoint) do
13
- "https://airbrake.io/api/v3/projects/#{project_id}/notices?key=#{project_key}"
14
- end
15
-
16
- let(:airbrake_params) do
17
- { project_id: project_id,
18
- project_key: project_key,
19
- logger: Logger.new(StringIO.new) }
20
- end
21
-
22
- let(:ex) { AirbrakeTestError.new }
23
-
24
- shared_examples 'blacklisting' do |keys, params|
25
- it "filters out the value" do
26
- blacklist = { blacklist_keys: keys }
27
- notifier = Airbrake::Notifier.new(airbrake_params.merge(blacklist))
28
-
29
- notifier.notify_sync(ex, params)
30
-
31
- expect_a_request_with_body(expected_body)
32
- end
33
- end
34
-
35
- shared_examples 'logging' do |keys, params|
36
- it "logs the error" do
37
- out = StringIO.new
38
- blacklist = { blacklist_keys: keys, logger: Logger.new(out) }
39
- notifier = Airbrake::Notifier.new(airbrake_params.merge(blacklist))
40
-
41
- notifier.notify_sync(ex, params)
42
-
43
- expect(out.string).to match(expected_output)
44
- end
45
- end
46
-
47
- before do
48
- stub_request(:post, endpoint).to_return(status: 201, body: '{}')
49
- end
50
-
51
- context "when blacklisting with a Regexp" do
52
- let(:expected_body) { /"params":{"bingo":"\[Filtered\]".*}/ }
53
- include_examples('blacklisting', [/\Abin/], bingo: 'bango')
54
- end
55
-
56
- context "when blacklisting with a Symbol" do
57
- let(:expected_body) { /"params":{"bingo":"\[Filtered\]".*}/ }
58
- include_examples('blacklisting', [:bingo], bingo: 'bango')
59
- end
60
-
61
- context "when blacklisting with a String" do
62
- let(:expected_body) { /"params":{"bingo":"\[Filtered\]".*}/ }
63
- include_examples('blacklisting', ['bingo'], bingo: 'bango')
64
- end
65
-
66
- context "when payload has a hash" do
67
- context "and it is a non-recursive hash" do
68
- let(:expected_body) { /"params":{"bongo":{"bish":"\[Filtered\]"}.*}/ }
69
- include_examples('blacklisting', ['bish'], bongo: { bish: 'bash' })
70
- end
71
-
72
- context "and it is a recursive hash" do
73
- let(:expected_body) { /"params":{"bingo":{"bango":"\[Filtered\]"}.*}/ }
74
-
75
- bongo = { bingo: {} }
76
- bongo[:bingo][:bango] = bongo
77
-
78
- include_examples('blacklisting', ['bango'], bongo)
79
- end
80
- end
81
-
82
- context "when there was invalid pattern provided" do
83
- let(:expected_output) do
84
- /ERROR.+KeysBlacklist is invalid.+patterns: \[#<Object:.+>\]/
85
- end
86
-
87
- include_examples('logging', [Object.new], bingo: 'bango')
88
- end
89
-
90
- context "when there was a proc provided, which returns an array of keys" do
91
- let(:expected_body) { /"params":{"bingo":"\[Filtered\]","bongo":"bish".*}/ }
92
- include_examples('blacklisting', [proc { 'bingo' }], bingo: 'bango', bongo: 'bish')
93
- end
94
-
95
- context "when there was a proc provided along with normal keys" do
96
- let(:expected_body) do
97
- /"params":{"bingo":"bango","bongo":"\[Filtered\]","bash":"\[Filtered\]".*}/
98
- end
99
-
100
- include_examples(
101
- 'blacklisting',
102
- [proc { 'bongo' }, :bash],
103
- bingo: 'bango', bongo: 'bish', bash: 'bosh'
104
- )
105
- end
106
-
107
- context "when there was a proc provided, which doesn't return an array of keys" do
108
- let(:expected_output) do
109
- /ERROR.+KeysBlacklist is invalid.+patterns: \[#<Object:.+>\]/
110
- end
111
-
112
- include_examples('logging', [proc { Object.new }], bingo: 'bango')
113
-
114
- it "doesn't blacklist keys" do
115
- blacklist = { blacklist_keys: [proc { Object.new }] }
116
- notifier = Airbrake::Notifier.new(airbrake_params.merge(blacklist))
117
-
118
- notifier.notify_sync(ex, bingo: 'bango', bongo: 'bish')
119
-
120
- expect_a_request_with_body(/"params":{"bingo":"bango","bongo":"bish".*}/)
121
- end
122
- end
123
-
124
- context "when there was a proc provided, which returns another proc" do
125
- context "when called once" do
126
- let(:expected_output) do
127
- /ERROR.+KeysBlacklist is invalid.+patterns: \[#<Proc:.+>\]/
128
- end
129
-
130
- include_examples('logging', [proc { proc { ['bingo'] } }], bingo: 'bango')
131
- end
132
-
133
- context "when called twice" do
134
- it "unwinds procs and filters keys" do
135
- blacklist = { blacklist_keys: [proc { proc { ['bingo'] } }] }
136
- notifier = Airbrake::Notifier.new(airbrake_params.merge(blacklist))
137
-
138
- notifier.notify_sync(ex, bingo: 'bango', bongo: 'bish')
139
- notifier.notify_sync(ex, bingo: 'bango', bongo: 'bish')
140
-
141
- expect_a_request_with_body(
142
- /"params":{"bingo":"\[Filtered\]","bongo":"bish".*}/
143
- )
144
- end
145
- end
146
- end
147
-
148
- it "filters query parameters correctly" do
149
- blacklist = { blacklist_keys: ['bish'] }
150
- notifier = Airbrake::Notifier.new(airbrake_params.merge(blacklist))
151
-
152
- notice = notifier.build_notice(ex)
153
- notice[:context][:url] = 'http://localhost:3000/crash?foo=bar&baz=bongo&bish=bash&color=%23FFAAFF'
154
-
155
- notifier.notify_sync(notice)
156
-
157
- # rubocop:disable Metrics/LineLength
158
- expected_body =
159
- %r("context":{.*"url":"http://localhost:3000/crash\?foo=bar&baz=bongo&bish=\[Filtered\]&color=%23FFAAFF".*})
160
- # rubocop:enable Metrics/LineLength
161
-
162
- expect_a_request_with_body(expected_body)
163
- end
164
-
165
- context "when the user payload is present" do
166
- context "and when the user key is ignored" do
167
- it "filters out user entirely" do
168
- blacklist = { blacklist_keys: ['user'] }
169
- notifier = Airbrake::Notifier.new(airbrake_params.merge(blacklist))
170
-
171
- notice = notifier.build_notice(ex)
172
- notice[:context][:user] = { id: 1337, name: 'Bingo Bango' }
173
-
174
- notifier.notify_sync(notice)
175
-
176
- expect_a_request_with_body(/"user":"\[Filtered\]"/)
177
- end
178
- end
179
-
180
- it "filters out individual user fields" do
181
- blacklist = { blacklist_keys: ['name'] }
182
- notifier = Airbrake::Notifier.new(airbrake_params.merge(blacklist))
183
-
184
- notice = notifier.build_notice(ex)
185
- notice[:context][:user] = { id: 1337, name: 'Bingo Bango' }
186
-
187
- notifier.notify_sync(notice)
188
-
189
- expect_a_request_with_body(/"user":{"id":1337,"name":"\[Filtered\]"}/)
190
- end
191
- end
192
- end
@@ -1,248 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe "Airbrake::Notifier whitelist_keys" do
4
- def expect_a_request_with_body(body)
5
- expect(a_request(:post, endpoint).with(body: body)).to have_been_made.once
6
- end
7
-
8
- let(:project_id) { 105138 }
9
- let(:project_key) { 'fd04e13d806a90f96614ad8e529b2822' }
10
- let(:localhost) { 'http://localhost:8080' }
11
-
12
- let(:endpoint) do
13
- "https://airbrake.io/api/v3/projects/#{project_id}/notices?key=#{project_key}"
14
- end
15
-
16
- let(:airbrake_params) do
17
- { project_id: project_id,
18
- project_key: project_key,
19
- logger: Logger.new(StringIO.new) }
20
- end
21
-
22
- let(:ex) { AirbrakeTestError.new }
23
-
24
- shared_examples 'whitelisting' do |keys, params|
25
- it "filters everything but the value of the specified key" do
26
- whitelist = { whitelist_keys: keys }
27
- notifier = Airbrake::Notifier.new(airbrake_params.merge(whitelist))
28
-
29
- notifier.notify_sync(ex, params)
30
-
31
- expect_a_request_with_body(expected_body)
32
- end
33
- end
34
-
35
- shared_examples 'logging' do |keys, params|
36
- it "logs the error" do
37
- out = StringIO.new
38
- whitelist = { whitelist_keys: keys, logger: Logger.new(out) }
39
- notifier = Airbrake::Notifier.new(airbrake_params.merge(whitelist))
40
-
41
- notifier.notify_sync(ex, params)
42
-
43
- expect(out.string).to match(expected_output)
44
- end
45
- end
46
-
47
- before do
48
- stub_request(:post, endpoint).to_return(status: 201, body: '{}')
49
- end
50
-
51
- context "when whitelisting with a Regexp" do
52
- let(:expected_body) do
53
- /"params":{"bingo":"bango","bongo":"\[Filtered\]","bash":"\[Filtered\]".*}/
54
- end
55
-
56
- include_examples(
57
- 'whitelisting',
58
- [/\Abin/],
59
- bingo: 'bango', bongo: 'bish', bash: 'bosh'
60
- )
61
- end
62
-
63
- context "when whitelisting with a Symbol" do
64
- let(:expected_body) do
65
- /"params":{"bingo":"\[Filtered\]","bongo":"bish","bash":"\[Filtered\]".*}/
66
- end
67
-
68
- include_examples(
69
- 'whitelisting',
70
- [:bongo],
71
- bingo: 'bango', bongo: 'bish', bash: 'bosh'
72
- )
73
- end
74
-
75
- context "when whitelisting with a String" do
76
- let(:expected_body) do
77
- /"params":{"bingo":"\[Filtered\]","bongo":"\[Filtered\]",
78
- "bash":"bosh","bbashh":"\[Filtered\]".*}/x
79
- end
80
-
81
- include_examples(
82
- 'whitelisting',
83
- ['bash'],
84
- bingo: 'bango', bongo: 'bish', bash: 'bosh', bbashh: 'bboshh'
85
- )
86
- end
87
-
88
- context "when payload has a hash" do
89
- context "and it is a non-recursive hash" do
90
- let(:expected_body) do
91
- /"params":{"bingo":"\[Filtered\]","bongo":{"bish":"bash"}.*}/
92
- end
93
-
94
- include_examples(
95
- 'whitelisting',
96
- %w[bongo bish],
97
- bingo: 'bango', bongo: { bish: 'bash' }
98
- )
99
- end
100
-
101
- context "and it is a recursive hash" do
102
- it "errors when nested hashes are not filtered" do
103
- whitelist = airbrake_params.merge(whitelist_keys: %w[bingo bango])
104
- notifier = Airbrake::Notifier.new(whitelist)
105
-
106
- bongo = { bingo: {} }
107
- bongo[:bingo][:bango] = bongo
108
-
109
- if RUBY_ENGINE == 'jruby'
110
- # JRuby might raise two different exceptions, which represent the
111
- # same thing. One is a Java exception, the other is a Ruby
112
- # exception. It's probably a JRuby bug:
113
- # https://github.com/jruby/jruby/issues/1903
114
- begin
115
- expect do
116
- notifier.notify_sync(ex, bongo)
117
- end.to raise_error(SystemStackError)
118
- rescue RSpec::Expectations::ExpectationNotMetError
119
- expect do
120
- notifier.notify_sync(ex, bongo)
121
- end.to raise_error(java.lang.StackOverflowError)
122
- end
123
- else
124
- expect do
125
- notifier.notify_sync(ex, bongo)
126
- end.to raise_error(SystemStackError)
127
- end
128
- end
129
- end
130
- end
131
-
132
- context "when there was a proc provided, which returns an array of keys" do
133
- let(:expected_body) do
134
- /"params":{"bingo":"\[Filtered\]","bongo":"bish","bash":"\[Filtered\]".*}/
135
- end
136
-
137
- include_examples(
138
- 'whitelisting',
139
- [proc { 'bongo' }],
140
- bingo: 'bango', bongo: 'bish', bash: 'bosh'
141
- )
142
- end
143
-
144
- context "when there was a proc provided along with normal keys" do
145
- let(:expected_body) do
146
- /"params":{"bingo":"\[Filtered\]","bongo":"bish","bash":"bosh".*}/
147
- end
148
-
149
- include_examples(
150
- 'whitelisting',
151
- [proc { 'bongo' }, :bash],
152
- bingo: 'bango', bongo: 'bish', bash: 'bosh'
153
- )
154
- end
155
-
156
- context "when there was a proc provided, which returns another proc" do
157
- context "when called once" do
158
- let(:expected_output) do
159
- /ERROR.+KeysWhitelist is invalid.+patterns: \[#<Proc:.+>\]/
160
- end
161
-
162
- include_examples('logging', [proc { proc { ['bingo'] } }], bingo: 'bango')
163
- end
164
-
165
- context "when called twice" do
166
- it "unwinds procs and filters keys" do
167
- whitelist = { whitelist_keys: [proc { proc { ['bingo'] } }] }
168
- notifier = Airbrake::Notifier.new(airbrake_params.merge(whitelist))
169
-
170
- notifier.notify_sync(ex, bingo: 'bango', bongo: 'bish')
171
- notifier.notify_sync(ex, bingo: 'bango', bongo: 'bish')
172
-
173
- expect_a_request_with_body(
174
- /"params":{"bingo":"bango","bongo":"\[Filtered\]".*}/
175
- )
176
- end
177
- end
178
- end
179
-
180
- context "when there was a proc provided, which doesn't return an array of keys" do
181
- let(:expected_output) do
182
- /ERROR.+KeysWhitelist is invalid.+patterns: \[#<Object:.+>\]/
183
- end
184
-
185
- include_examples('logging', [proc { Object.new }], bingo: 'bango')
186
-
187
- it "doesn't whitelist keys" do
188
- whitelist = { whitelist_keys: [proc { Object.new }] }
189
- notifier = Airbrake::Notifier.new(airbrake_params.merge(whitelist))
190
-
191
- notifier.notify_sync(ex, bingo: 'bango', bongo: 'bish')
192
-
193
- expect_a_request_with_body(
194
- /"params":{"bingo":"\[Filtered\]","bongo":"\[Filtered\]".*}/
195
- )
196
- end
197
- end
198
-
199
- describe "context/url" do
200
- let(:notifier) do
201
- Airbrake::Notifier.new(airbrake_params.merge(whitelist_keys: %w[bish]))
202
- end
203
-
204
- context "given a standard URL" do
205
- it "filters query parameters correctly" do
206
- notice = notifier.build_notice(ex)
207
- notice[:context][:url] = 'http://localhost:3000/crash?foo=bar&baz=bongo&bish=bash'
208
-
209
- notifier.notify_sync(notice)
210
-
211
- expect_a_request_with_body(
212
- # rubocop:disable Metrics/LineLength
213
- %r("context":{.*"url":"http://localhost:3000/crash\?foo=\[Filtered\]&baz=\[Filtered\]&bish=bash".*})
214
- # rubocop:enable Metrics/LineLength
215
- )
216
- end
217
- end
218
-
219
- context "given a non-standard URL" do
220
- it "leaves the URL unfiltered" do
221
- notice = notifier.build_notice(ex)
222
- notice[:context][:url] =
223
- 'http://localhost:3000/cra]]]sh?foo=bar&baz=bongo&bish=bash'
224
-
225
- notifier.notify_sync(notice)
226
-
227
- expect_a_request_with_body(
228
- # rubocop:disable Metrics/LineLength
229
- %r("context":{.*"url":"http://localhost:3000/cra\]\]\]sh\?foo=bar&baz=bongo&bish=bash".*})
230
- # rubocop:enable Metrics/LineLength
231
- )
232
- end
233
- end
234
-
235
- context "given a URL without a query" do
236
- it "skips params filtering and leaves the URL untouched" do
237
- notice = notifier.build_notice(ex)
238
- notice[:context][:url] = 'http://localhost:3000/crash'
239
-
240
- notifier.notify_sync(notice)
241
-
242
- expect_a_request_with_body(
243
- %r("context":{.*"url":"http://localhost:3000/crash".*})
244
- )
245
- end
246
- end
247
- end
248
- end