exception_handling 2.11.3 → 3.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -3
- data/.ruby-version +1 -1
- data/Gemfile +16 -16
- data/Gemfile.lock +114 -110
- data/README.md +3 -7
- data/Rakefile +11 -8
- data/exception_handling.gemspec +10 -12
- data/lib/exception_handling/exception_info.rb +10 -13
- data/lib/exception_handling/honeybadger_callbacks.rb +59 -0
- data/lib/exception_handling/log_stub_error.rb +1 -2
- data/lib/exception_handling/methods.rb +53 -6
- data/lib/exception_handling/testing.rb +10 -20
- data/lib/exception_handling/version.rb +1 -1
- data/lib/exception_handling.rb +30 -58
- data/semaphore_ci/setup.sh +3 -0
- data/{spec → test}/helpers/controller_helpers.rb +0 -0
- data/{spec → test}/helpers/exception_helpers.rb +2 -2
- data/{spec/spec_helper.rb → test/test_helper.rb} +42 -63
- data/test/unit/exception_handling/exception_catalog_test.rb +85 -0
- data/test/unit/exception_handling/exception_description_test.rb +82 -0
- data/{spec/unit/exception_handling/exception_info_spec.rb → test/unit/exception_handling/exception_info_test.rb} +114 -153
- data/test/unit/exception_handling/honeybadger_callbacks_test.rb +122 -0
- data/{spec/unit/exception_handling/log_error_stub_spec.rb → test/unit/exception_handling/log_error_stub_test.rb} +22 -38
- data/{spec/unit/exception_handling/mailer_spec.rb → test/unit/exception_handling/mailer_test.rb} +18 -17
- data/test/unit/exception_handling/methods_test.rb +84 -0
- data/test/unit/exception_handling/sensu_test.rb +52 -0
- data/test/unit/exception_handling_test.rb +1109 -0
- metadata +60 -115
- data/.github/workflows/pipeline.yml +0 -33
- data/.rspec +0 -3
- data/Appraisals +0 -13
- data/CHANGELOG.md +0 -109
- data/gemfiles/rails_5.gemfile +0 -18
- data/gemfiles/rails_6.gemfile +0 -18
- data/lib/exception_handling/escalate_callback.rb +0 -19
- data/lib/exception_handling/logging_methods.rb +0 -27
- data/spec/rake_test_warning_false.rb +0 -20
- data/spec/unit/exception_handling/escalate_callback_spec.rb +0 -81
- data/spec/unit/exception_handling/exception_catalog_spec.rb +0 -85
- data/spec/unit/exception_handling/exception_description_spec.rb +0 -82
- data/spec/unit/exception_handling/logging_methods_spec.rb +0 -38
- data/spec/unit/exception_handling/methods_spec.rb +0 -105
- data/spec/unit/exception_handling/sensu_spec.rb +0 -51
- data/spec/unit/exception_handling_spec.rb +0 -1254
@@ -1,58 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path('../../
|
3
|
+
require File.expand_path('../../test_helper', __dir__)
|
4
4
|
require_test_helper 'controller_helpers'
|
5
5
|
require_test_helper 'exception_helpers'
|
6
6
|
|
7
7
|
module ExceptionHandling
|
8
|
-
|
8
|
+
class ExceptionInfoTest < ActiveSupport::TestCase
|
9
9
|
include ControllerHelpers
|
10
10
|
include ExceptionHelpers
|
11
11
|
|
12
12
|
context "initialize" do
|
13
|
-
|
13
|
+
setup do
|
14
14
|
@exception = StandardError.new("something went wrong")
|
15
15
|
@timestamp = Time.now
|
16
16
|
@controller = Object.new
|
17
17
|
end
|
18
18
|
|
19
19
|
context "controller_from_context" do
|
20
|
-
|
20
|
+
should "extract controller from context when not specified explicitly" do
|
21
21
|
exception_context = {
|
22
22
|
"action_controller.instance" => @controller
|
23
23
|
}
|
24
24
|
exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp)
|
25
|
-
|
25
|
+
assert_equal @controller, exception_info.controller
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
should "prefer the explicit controller over the one from context" do
|
29
29
|
exception_context = {
|
30
30
|
"action_controller.instance" => Object.new
|
31
31
|
}
|
32
|
-
exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp,
|
33
|
-
|
34
|
-
|
32
|
+
exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp, @controller)
|
33
|
+
assert_equal @controller, exception_info.controller
|
34
|
+
assert_not_equal exception_context["action_controller.instance"], exception_info.controller
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
should "leave controller unset when not included in the context hash" do
|
38
38
|
exception_info = ExceptionInfo.new(@exception, {}, @timestamp)
|
39
|
-
|
39
|
+
assert_nil exception_info.controller
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
should "leave controller unset when context is not in hash format" do
|
43
43
|
exception_info = ExceptionInfo.new(@exception, "string context", @timestamp)
|
44
|
-
|
44
|
+
assert_nil exception_info.controller
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context "data" do
|
50
|
-
|
50
|
+
setup do
|
51
51
|
@exception = StandardError.new("something went wrong")
|
52
52
|
@timestamp = Time.now
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
should "return a hash with exception specific data including context hash" do
|
56
56
|
exception_context = {
|
57
57
|
"rack.session" => {
|
58
58
|
user_id: 23,
|
@@ -73,17 +73,17 @@ module ExceptionHandling
|
|
73
73
|
}
|
74
74
|
}
|
75
75
|
|
76
|
-
|
76
|
+
assert_equal_with_diff expected_data, exception_info.data
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
should "generate exception data appropriately if exception message is nil" do
|
80
80
|
exception_info = ExceptionInfo.new(exception_with_nil_message, "custom context data", @timestamp)
|
81
81
|
exception_data = exception_info.data
|
82
|
-
|
83
|
-
|
82
|
+
assert_equal "RuntimeError: ", exception_data["error_string"]
|
83
|
+
assert_equal "RuntimeError: : custom context data", exception_data["error"]
|
84
84
|
end
|
85
85
|
|
86
|
-
|
86
|
+
should "return a hash with exception specific data including context string" do
|
87
87
|
exception_context = "custom context data"
|
88
88
|
exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp)
|
89
89
|
expected_data = {
|
@@ -96,20 +96,21 @@ module ExceptionHandling
|
|
96
96
|
"message" => "custom context data"
|
97
97
|
}
|
98
98
|
}
|
99
|
-
|
99
|
+
|
100
|
+
assert_equal_with_diff expected_data, exception_info.data
|
100
101
|
end
|
101
102
|
|
102
|
-
|
103
|
+
should "not include enhanced data from controller or custom data callback" do
|
103
104
|
env = { server: "fe98" }
|
104
105
|
parameters = { advertiser_id: 435 }
|
105
106
|
session = { username: "jsmith" }
|
106
107
|
request_uri = "host/path"
|
107
108
|
controller = create_dummy_controller(env, parameters, session, request_uri)
|
108
109
|
data_callback = ->(data) { data[:custom_section] = "value" }
|
109
|
-
exception_info = ExceptionInfo.new(@exception, "custom context data", @timestamp, controller
|
110
|
+
exception_info = ExceptionInfo.new(@exception, "custom context data", @timestamp, controller, data_callback)
|
110
111
|
|
111
|
-
|
112
|
-
|
112
|
+
dont_allow(exception_info).extract_and_merge_controller_data
|
113
|
+
dont_allow(exception_info).customize_from_data_callback
|
113
114
|
expected_data = {
|
114
115
|
"error_class" => "StandardError",
|
115
116
|
"error_string" => "StandardError: something went wrong",
|
@@ -121,12 +122,12 @@ module ExceptionHandling
|
|
121
122
|
}
|
122
123
|
}
|
123
124
|
|
124
|
-
|
125
|
+
assert_equal_with_diff expected_data, exception_info.data
|
125
126
|
end
|
126
127
|
end
|
127
128
|
|
128
129
|
context "enhanced_data" do
|
129
|
-
|
130
|
+
setup do
|
130
131
|
@exception = StandardError.new("something went wrong")
|
131
132
|
@timestamp = Time.now
|
132
133
|
@exception_context = {
|
@@ -144,13 +145,13 @@ module ExceptionHandling
|
|
144
145
|
@data_callback = ->(data) { data[:custom_section] = "check this out" }
|
145
146
|
end
|
146
147
|
|
147
|
-
|
148
|
+
should "not return a mutable object for the session" do
|
148
149
|
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
|
149
150
|
exception_info.enhanced_data["session"]["hello"] = "world"
|
150
|
-
|
151
|
+
assert_nil @controller.session["hello"]
|
151
152
|
end
|
152
153
|
|
153
|
-
|
154
|
+
should "return a hash with generic exception attributes as well as context data" do
|
154
155
|
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
|
155
156
|
expected_data = {
|
156
157
|
"error_class" => "StandardError",
|
@@ -163,20 +164,20 @@ module ExceptionHandling
|
|
163
164
|
"location" => { "file" => "<no backtrace>", "line" => nil }
|
164
165
|
}
|
165
166
|
|
166
|
-
|
167
|
+
assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
|
167
168
|
end
|
168
169
|
|
169
|
-
|
170
|
+
should "generate exception data appropriately if exception message is nil" do
|
170
171
|
exception_with_nil_message = RuntimeError.new(nil)
|
171
|
-
|
172
|
+
stub(exception_with_nil_message).message { nil }
|
172
173
|
exception_info = ExceptionInfo.new(exception_with_nil_message, @exception_context, @timestamp)
|
173
174
|
exception_data = exception_info.enhanced_data
|
174
|
-
|
175
|
-
|
175
|
+
assert_equal "RuntimeError: ", exception_data["error_string"]
|
176
|
+
assert_equal "RuntimeError: ", exception_data["error"]
|
176
177
|
end
|
177
178
|
|
178
|
-
|
179
|
-
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp,
|
179
|
+
should "include controller data when available" do
|
180
|
+
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, @controller)
|
180
181
|
expected_data = {
|
181
182
|
"error_class" => "StandardError",
|
182
183
|
"error_string" => "StandardError: something went wrong",
|
@@ -193,10 +194,10 @@ module ExceptionHandling
|
|
193
194
|
"location" => { "controller" => "dummy", "action" => "fail", "file" => "<no backtrace>", "line" => nil }
|
194
195
|
}
|
195
196
|
|
196
|
-
|
197
|
+
assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
|
197
198
|
end
|
198
199
|
|
199
|
-
|
200
|
+
should "extract controller from rack specific exception context when not provided explicitly" do
|
200
201
|
@exception_context["action_controller.instance"] = @controller
|
201
202
|
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
|
202
203
|
expected_data = {
|
@@ -215,11 +216,11 @@ module ExceptionHandling
|
|
215
216
|
"location" => { "controller" => "dummy", "action" => "fail", "file" => "<no backtrace>", "line" => nil }
|
216
217
|
}
|
217
218
|
|
218
|
-
|
219
|
+
assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
|
219
220
|
end
|
220
221
|
|
221
|
-
|
222
|
-
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp,
|
222
|
+
should "add to_s attribute to specific sections that have their content in hash format" do
|
223
|
+
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, @controller)
|
223
224
|
expected_data = {
|
224
225
|
"error_class" => "StandardError",
|
225
226
|
"error_string" => "StandardError: something went wrong",
|
@@ -244,13 +245,13 @@ module ExceptionHandling
|
|
244
245
|
"location" => { "controller" => "dummy", "action" => "fail", "file" => "<no backtrace>", "line" => nil }
|
245
246
|
}
|
246
247
|
|
247
|
-
|
248
|
+
assert_equal_with_diff expected_data, exception_info.enhanced_data
|
248
249
|
end
|
249
250
|
|
250
|
-
|
251
|
+
should "filter out sensitive parameters like passwords" do
|
251
252
|
@controller.request.parameters[:password] = "super_secret"
|
252
253
|
@controller.request.parameters[:user] = { "password" => "also super secret", "password_confirmation" => "also super secret" }
|
253
|
-
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp,
|
254
|
+
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, @controller)
|
254
255
|
expected_params = {
|
255
256
|
"password" => "[FILTERED]",
|
256
257
|
"advertiser_id" => 435, "controller" => "dummy",
|
@@ -260,11 +261,11 @@ module ExceptionHandling
|
|
260
261
|
"password_confirmation" => "[FILTERED]"
|
261
262
|
}
|
262
263
|
}
|
263
|
-
|
264
|
+
assert_equal_with_diff expected_params, exception_info.enhanced_data["request"]["params"]
|
264
265
|
end
|
265
266
|
|
266
|
-
|
267
|
-
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp,
|
267
|
+
should "include the changes from the custom data callback" do
|
268
|
+
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, nil, @data_callback)
|
268
269
|
expected_data = {
|
269
270
|
"error_class" => "StandardError",
|
270
271
|
"error_string" => "StandardError: something went wrong",
|
@@ -277,11 +278,11 @@ module ExceptionHandling
|
|
277
278
|
"location" => { "file" => "<no backtrace>", "line" => nil }
|
278
279
|
}
|
279
280
|
|
280
|
-
|
281
|
+
assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
|
281
282
|
end
|
282
283
|
|
283
|
-
|
284
|
-
|
284
|
+
should "apply the custom_data_hook results" do
|
285
|
+
stub(ExceptionHandling).custom_data_hook { ->(data) { data[:custom_hook] = "changes from custom hook" } }
|
285
286
|
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
|
286
287
|
expected_data = {
|
287
288
|
"error_class" => "StandardError",
|
@@ -295,61 +296,61 @@ module ExceptionHandling
|
|
295
296
|
"location" => { "file" => "<no backtrace>", "line" => nil }
|
296
297
|
}
|
297
298
|
|
298
|
-
|
299
|
+
assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
|
299
300
|
end
|
300
301
|
|
301
|
-
|
302
|
+
should "log info if the custom data hook results in a nil message exception" do
|
302
303
|
ExceptionHandling.custom_data_hook = ->(_data) do
|
303
304
|
raise_exception_with_nil_message
|
304
305
|
end
|
305
306
|
log_info_messages = []
|
306
|
-
|
307
|
+
stub(ExceptionHandling.logger).info.with_any_args do |message, _|
|
307
308
|
log_info_messages << message
|
308
309
|
end
|
309
310
|
|
310
311
|
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
|
311
312
|
exception_info.enhanced_data
|
312
|
-
|
313
|
+
assert log_info_messages.find { |message| message =~ /Unable to execute custom custom_data_hook callback/ }
|
313
314
|
ExceptionHandling.custom_data_hook = nil
|
314
315
|
end
|
315
316
|
end
|
316
317
|
|
317
318
|
context "exception_description" do
|
318
|
-
|
319
|
+
should "return the exception description from the global exception filter list" do
|
319
320
|
exception = StandardError.new("No route matches")
|
320
321
|
exception_info = ExceptionInfo.new(exception, {}, Time.now)
|
321
322
|
description = exception_info.exception_description
|
322
|
-
|
323
|
-
|
323
|
+
assert_not_nil description
|
324
|
+
assert_equal :NoRoute, description.filter_name
|
324
325
|
end
|
325
326
|
|
326
|
-
|
327
|
+
should "find the description when filter criteria includes section in hash format" do
|
327
328
|
env = { server: "fe98" }
|
328
329
|
parameters = { advertiser_id: 435, controller: "sessions", action: "fail" }
|
329
330
|
session = { username: "jsmith", id: "session_key" }
|
330
331
|
request_uri = "host/path"
|
331
332
|
controller = create_dummy_controller(env, parameters, session, request_uri)
|
332
333
|
exception = StandardError.new("Request to click domain rejected")
|
333
|
-
exception_info = ExceptionInfo.new(exception,
|
334
|
-
|
334
|
+
exception_info = ExceptionInfo.new(exception, {}, Time.now, controller)
|
335
|
+
assert_equal true, exception_info.enhanced_data[:request].is_a?(Hash)
|
335
336
|
description = exception_info.exception_description
|
336
|
-
|
337
|
-
|
337
|
+
assert_not_nil description
|
338
|
+
assert_equal :"Click Request Rejected", description.filter_name
|
338
339
|
end
|
339
340
|
|
340
|
-
|
341
|
+
should "return same description object for related errors (avoid reloading exception catalog from disk)" do
|
341
342
|
exception = StandardError.new("No route matches")
|
342
|
-
exception_info = ExceptionInfo.new(exception,
|
343
|
+
exception_info = ExceptionInfo.new(exception, {}, Time.now)
|
343
344
|
description = exception_info.exception_description
|
344
345
|
|
345
346
|
repeat_ex = StandardError.new("No route matches 2")
|
346
|
-
repeat_ex_info = ExceptionInfo.new(repeat_ex,
|
347
|
-
|
347
|
+
repeat_ex_info = ExceptionInfo.new(repeat_ex, {}, Time.now)
|
348
|
+
assert_equal description.object_id, repeat_ex_info.exception_description.object_id
|
348
349
|
end
|
349
350
|
end
|
350
351
|
|
351
352
|
context "controller_name" do
|
352
|
-
|
353
|
+
setup do
|
353
354
|
@exception = StandardError.new('something went wrong')
|
354
355
|
@timestamp = Time.now
|
355
356
|
@exception_context = {
|
@@ -361,113 +362,73 @@ module ExceptionHandling
|
|
361
362
|
}
|
362
363
|
end
|
363
364
|
|
364
|
-
|
365
|
-
allow(ExceptionHandling.logger).to receive(:current_context_for_thread).and_return({ honeybadger_grouping: 'Group 1' })
|
366
|
-
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
|
367
|
-
|
368
|
-
expect(exception_info.controller_name).to eq('Group 1')
|
369
|
-
end
|
370
|
-
|
371
|
-
it "returns honeybadger_grouping from log context even if controller is defined" do
|
372
|
-
allow(ExceptionHandling.logger).to receive(:current_context_for_thread).and_return({ honeybadger_grouping: 'Group 1' })
|
373
|
-
|
374
|
-
env = { server: 'fe98' }
|
375
|
-
parameters = { controller: 'some_controller' }
|
376
|
-
session = { username: 'smith' }
|
377
|
-
request_uri = "host/path"
|
378
|
-
controller = create_dummy_controller(env, parameters, session, request_uri)
|
379
|
-
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: controller)
|
380
|
-
|
381
|
-
expect(exception_info.controller_name).to eq('Group 1')
|
382
|
-
end
|
383
|
-
|
384
|
-
it "return controller_name when controller is present" do
|
365
|
+
should "return controller_name when controller is present" do
|
385
366
|
env = { server: 'fe98' }
|
386
367
|
parameters = { controller: 'some_controller' }
|
387
368
|
session = { username: 'smith' }
|
388
369
|
request_uri = "host/path"
|
389
370
|
controller = create_dummy_controller(env, parameters, session, request_uri)
|
390
|
-
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller
|
371
|
+
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller)
|
391
372
|
|
392
|
-
|
373
|
+
assert_equal 'some_controller', exception_info.controller_name
|
393
374
|
end
|
394
375
|
|
395
|
-
|
376
|
+
should "return an empty string when controller is not present" do
|
396
377
|
exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
|
397
378
|
|
398
|
-
|
379
|
+
assert_equal '', exception_info.controller_name
|
399
380
|
end
|
400
381
|
end
|
401
382
|
|
402
383
|
context "send_to_honeybadger?" do
|
403
|
-
|
404
|
-
|
384
|
+
should "be enabled when Honeybadger is defined and exception is not in the filter list" do
|
385
|
+
stub(ExceptionHandling).honeybadger_defined? { true }
|
405
386
|
exception = StandardError.new("something went wrong")
|
406
|
-
exception_info = ExceptionInfo.new(exception,
|
407
|
-
|
408
|
-
|
387
|
+
exception_info = ExceptionInfo.new(exception, {}, Time.now)
|
388
|
+
assert_nil exception_info.exception_description
|
389
|
+
assert_equal true, exception_info.send_to_honeybadger?
|
409
390
|
end
|
410
391
|
|
411
|
-
|
412
|
-
|
392
|
+
should "be enabled when Honeybadger is defined and exception is on the filter list with the flag turned on" do
|
393
|
+
stub(ExceptionHandling).honeybadger_defined? { true }
|
413
394
|
exception = StandardError.new("No route matches")
|
414
|
-
exception_info = ExceptionInfo.new(exception,
|
415
|
-
|
416
|
-
|
417
|
-
|
395
|
+
exception_info = ExceptionInfo.new(exception, {}, Time.now)
|
396
|
+
assert_not_nil exception_info.exception_description
|
397
|
+
assert_equal true, exception_info.exception_description.send_to_honeybadger
|
398
|
+
assert_equal true, exception_info.send_to_honeybadger?
|
418
399
|
end
|
419
400
|
|
420
|
-
|
421
|
-
|
401
|
+
should "be disabled when Honeybadger is defined and exception is on the filter list with the flag turned off" do
|
402
|
+
stub(ExceptionHandling).honeybadger_defined? { true }
|
422
403
|
exception = StandardError.new("No route matches")
|
423
|
-
exception_info = ExceptionInfo.new(exception,
|
424
|
-
|
425
|
-
|
426
|
-
|
404
|
+
exception_info = ExceptionInfo.new(exception, {}, Time.now)
|
405
|
+
assert_not_nil exception_info.exception_description
|
406
|
+
stub(exception_info.exception_description).send_to_honeybadger { false }
|
407
|
+
assert_equal false, exception_info.send_to_honeybadger?
|
427
408
|
end
|
428
409
|
|
429
|
-
|
430
|
-
|
410
|
+
should "be disabled when Honeybadger is not defined" do
|
411
|
+
stub(ExceptionHandling).honeybadger_defined? { false }
|
431
412
|
exception = StandardError.new("something went wrong")
|
432
|
-
exception_info = ExceptionInfo.new(exception,
|
433
|
-
|
434
|
-
|
413
|
+
exception_info = ExceptionInfo.new(exception, {}, Time.now)
|
414
|
+
assert_nil exception_info.exception_description
|
415
|
+
assert_equal false, exception_info.send_to_honeybadger?
|
435
416
|
end
|
436
417
|
end
|
437
418
|
|
438
419
|
context "honeybadger_context_data" do
|
439
|
-
|
440
|
-
allow(ExceptionHandling.logger).to receive(:current_context_for_thread).and_return({ cuid: 'ABCD' })
|
441
|
-
end
|
442
|
-
|
443
|
-
it "include thread_context when log_context: is nil" do
|
444
|
-
exception_with_nil_message = RuntimeError.new(nil)
|
445
|
-
allow(exception_with_nil_message).to receive(:message).and_return(nil)
|
446
|
-
exception_info = ExceptionInfo.new(exception_with_nil_message, @exception_context, @timestamp)
|
447
|
-
honeybadger_context_data = exception_info.honeybadger_context_data
|
448
|
-
expect(honeybadger_context_data[:log_context]).to eq({ "cuid" => 'ABCD' })
|
449
|
-
end
|
450
|
-
|
451
|
-
it "include thread context merged with log_context:" do
|
452
|
-
exception_with_nil_message = RuntimeError.new(nil)
|
453
|
-
allow(exception_with_nil_message).to receive(:message).and_return(nil)
|
454
|
-
exception_info = ExceptionInfo.new(exception_with_nil_message, @exception_context, @timestamp, log_context: { url: 'http://example.com' })
|
455
|
-
honeybadger_context_data = exception_info.honeybadger_context_data
|
456
|
-
expect(honeybadger_context_data[:log_context]).to eq({ "cuid" => 'ABCD', "url" => 'http://example.com' })
|
457
|
-
end
|
458
|
-
|
459
|
-
it "return the error details and relevant context data to be used as honeybadger notification context while filtering sensitive data" do
|
420
|
+
should "return the error details and relevant context data to be used as honeybadger notification context while filtering sensitive data" do
|
460
421
|
env = { server: "fe98" }
|
461
422
|
parameters = { advertiser_id: 435 }
|
462
423
|
session = { username: "jsmith" }
|
463
424
|
request_uri = "host/path"
|
464
425
|
controller = create_dummy_controller(env, parameters, session, request_uri)
|
465
|
-
|
426
|
+
stub(ExceptionHandling).server_name { "invoca_fe98" }
|
466
427
|
|
467
428
|
exception = StandardError.new("Some Exception")
|
468
429
|
exception.set_backtrace([
|
469
|
-
"
|
470
|
-
"
|
430
|
+
"test/unit/exception_handling_test.rb:847:in `exception_1'",
|
431
|
+
"test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
|
471
432
|
])
|
472
433
|
exception_context = { "SERVER_NAME" => "exceptional.com" }
|
473
434
|
data_callback = ->(data) do
|
@@ -477,7 +438,7 @@ module ExceptionHandling
|
|
477
438
|
data[:other_section] = "This should not be included in the response"
|
478
439
|
end
|
479
440
|
timestamp = Time.now
|
480
|
-
exception_info = ExceptionInfo.new(exception, exception_context, timestamp, controller
|
441
|
+
exception_info = ExceptionInfo.new(exception, exception_context, timestamp, controller, data_callback)
|
481
442
|
|
482
443
|
expected_data = {
|
483
444
|
timestamp: timestamp,
|
@@ -485,6 +446,7 @@ module ExceptionHandling
|
|
485
446
|
exception_context: { "SERVER_NAME" => "exceptional.com" },
|
486
447
|
server: "invoca_fe98",
|
487
448
|
scm_revision: "5b24eac37aaa91f5784901e9aabcead36fd9df82",
|
449
|
+
notes: "this is used by a test",
|
488
450
|
user_details: { "username" => "jsmith" },
|
489
451
|
request: {
|
490
452
|
"params" => { "advertiser_id" => 435 },
|
@@ -499,30 +461,28 @@ module ExceptionHandling
|
|
499
461
|
"SERVER_NAME" => "exceptional.com"
|
500
462
|
},
|
501
463
|
backtrace: [
|
502
|
-
"
|
503
|
-
"
|
464
|
+
"test/unit/exception_handling_test.rb:847:in `exception_1'",
|
465
|
+
"test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
|
504
466
|
],
|
505
|
-
event_response: "Event successfully received"
|
506
|
-
log_context: { "cuid" => "ABCD" },
|
507
|
-
notes: "this is used by a test"
|
467
|
+
event_response: "Event successfully received"
|
508
468
|
}
|
509
|
-
|
469
|
+
assert_equal_with_diff expected_data, exception_info.honeybadger_context_data
|
510
470
|
end
|
511
471
|
|
512
472
|
[['Hash', { 'cookie' => 'cookie_context' }],
|
513
473
|
['String', 'Entering Error State'],
|
514
474
|
['Array', ['Error1', 'Error2']]].each do |klass, value|
|
515
|
-
|
475
|
+
should "extract context from exception_context when it is a #{klass}" do
|
516
476
|
exception = StandardError.new("Exception")
|
517
477
|
exception_context = value
|
518
478
|
exception_info = ExceptionInfo.new(exception, exception_context, Time.now)
|
519
479
|
|
520
|
-
|
521
|
-
|
480
|
+
assert_equal klass, value.class.name
|
481
|
+
assert_equal value, exception_info.honeybadger_context_data[:exception_context]
|
522
482
|
end
|
523
483
|
end
|
524
484
|
|
525
|
-
|
485
|
+
should "filter out sensitive data from exception context such as [password, password_confirmation, oauth_token]" do
|
526
486
|
sensitive_data = {
|
527
487
|
"password" => "super_secret",
|
528
488
|
"password_confirmation" => "super_secret_confirmation",
|
@@ -557,14 +517,15 @@ module ExceptionHandling
|
|
557
517
|
}
|
558
518
|
}.merge(expected_sensitive_data)
|
559
519
|
|
560
|
-
|
520
|
+
assert_equal_with_diff expected_exception_context, exception_info.honeybadger_context_data[:exception_context]
|
561
521
|
end
|
562
522
|
|
563
|
-
|
523
|
+
should "omit context if exception_context is empty" do
|
564
524
|
exception = StandardError.new("Exception")
|
565
525
|
exception_context = ""
|
566
526
|
exception_info = ExceptionInfo.new(exception, exception_context, Time.now)
|
567
|
-
|
527
|
+
|
528
|
+
assert_nil exception_info.honeybadger_context_data[:exception_context]
|
568
529
|
end
|
569
530
|
end
|
570
531
|
|