exception_handling 2.6.1 → 2.7.0.pre.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.jenkins/Jenkinsfile +8 -24
- data/CHANGELOG.md +8 -1
- data/Gemfile +4 -4
- data/Gemfile.lock +19 -29
- data/Rakefile +6 -7
- data/lib/exception_handling/log_stub_error.rb +1 -2
- data/lib/exception_handling/logging_methods.rb +33 -0
- data/lib/exception_handling/methods.rb +6 -53
- data/lib/exception_handling/testing.rb +20 -10
- data/lib/exception_handling/version.rb +1 -1
- data/lib/exception_handling.rb +2 -2
- data/{spec → test}/helpers/controller_helpers.rb +0 -0
- data/{spec → test}/helpers/exception_helpers.rb +2 -2
- data/{spec → test}/rake_test_warning_false.rb +0 -0
- data/{spec/spec_helper.rb → test/test_helper.rb} +39 -50
- 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} +107 -105
- data/{spec/unit/exception_handling/honeybadger_callbacks_spec.rb → test/unit/exception_handling/honeybadger_callbacks_test.rb} +20 -20
- data/{spec/unit/exception_handling/log_error_stub_spec.rb → test/unit/exception_handling/log_error_stub_test.rb} +22 -38
- data/test/unit/exception_handling/logging_methods_test.rb +37 -0
- data/{spec/unit/exception_handling/mailer_spec.rb → test/unit/exception_handling/mailer_test.rb} +17 -17
- data/test/unit/exception_handling/methods_test.rb +105 -0
- data/test/unit/exception_handling/sensu_test.rb +52 -0
- data/{spec/unit/exception_handling_spec.rb → test/unit/exception_handling_test.rb} +329 -325
- metadata +36 -34
- data/.rspec +0 -3
- 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/methods_spec.rb +0 -84
- data/spec/unit/exception_handling/sensu_spec.rb +0 -51
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('../../test_helper', __dir__)
|
4
|
+
|
5
|
+
module ExceptionHandling
|
6
|
+
class ExceptionCatalogTest < ActiveSupport::TestCase
|
7
|
+
|
8
|
+
context "With stubbed yaml content" do
|
9
|
+
setup do
|
10
|
+
filter_list = { exception1: { error: "my error message" },
|
11
|
+
exception2: { error: "some other message", session: "misc data" } }
|
12
|
+
stub(YAML).load_file { filter_list }
|
13
|
+
|
14
|
+
# bump modified time up to get the above filter loaded
|
15
|
+
stub(File).mtime { incrementing_mtime }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with loaded data" do
|
19
|
+
setup do
|
20
|
+
stub(File).mtime { incrementing_mtime }
|
21
|
+
@exception_catalog = ExceptionCatalog.new(ExceptionHandling.filter_list_filename)
|
22
|
+
@exception_catalog.send :load_file
|
23
|
+
end
|
24
|
+
|
25
|
+
should "have loaded filters" do
|
26
|
+
assert_equal 2, @exception_catalog.instance_eval("@filters").size
|
27
|
+
end
|
28
|
+
|
29
|
+
should "find messages in the catalog" do
|
30
|
+
assert !@exception_catalog.find(error: "Scott says unlikely to ever match")
|
31
|
+
end
|
32
|
+
|
33
|
+
should "find matching data" do
|
34
|
+
exception_description = @exception_catalog.find(error: "this is my error message, which should match something")
|
35
|
+
assert exception_description
|
36
|
+
assert_equal :exception1, exception_description.filter_name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "write errors loading the yaml file directly to the log file" do
|
41
|
+
@exception_catalog = ExceptionCatalog.new(ExceptionHandling.filter_list_filename)
|
42
|
+
|
43
|
+
mock(ExceptionHandling).log_error.never
|
44
|
+
mock(ExceptionHandling).write_exception_to_log(anything, "ExceptionCatalog#refresh_filters: ./config/exception_filters.yml", anything)
|
45
|
+
mock(@exception_catalog).load_file { raise "noooooo" }
|
46
|
+
|
47
|
+
@exception_catalog.find({})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with live yaml content" do
|
52
|
+
setup do
|
53
|
+
@filename = File.expand_path('../../../config/exception_filters.yml', __dir__)
|
54
|
+
@exception_catalog = ExceptionCatalog.new(@filename)
|
55
|
+
assert_nothing_raised do
|
56
|
+
@exception_catalog.send :load_file
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
should "load the filter data" do
|
61
|
+
assert !@exception_catalog.find(error: "Scott says unlikely to ever match")
|
62
|
+
assert !@exception_catalog.find(error: "Scott says unlikely to ever match")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with no yaml content" do
|
67
|
+
setup do
|
68
|
+
@exception_catalog = ExceptionCatalog.new(nil)
|
69
|
+
end
|
70
|
+
|
71
|
+
should "not load filter data" do
|
72
|
+
mock(ExceptionHandling).write_exception_to_log.with_any_args.never
|
73
|
+
@exception_catalog.find(error: "Scott says unlikely to ever match")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def incrementing_mtime
|
80
|
+
@mtime ||= Time.now
|
81
|
+
@mtime += 1.day
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('../../test_helper', __dir__)
|
4
|
+
|
5
|
+
module ExceptionHandling
|
6
|
+
class ExceptionDescriptionTest < ActiveSupport::TestCase
|
7
|
+
|
8
|
+
context "Filter" do
|
9
|
+
should "allow direct matching of strings" do
|
10
|
+
@f = ExceptionDescription.new(:filter1, error: "my error message")
|
11
|
+
assert @f.match?('error' => "my error message")
|
12
|
+
end
|
13
|
+
|
14
|
+
should "allow direct matching of strings on with symbol keys" do
|
15
|
+
@f = ExceptionDescription.new(:filter1, error: "my error message")
|
16
|
+
assert @f.match?(error: "my error message")
|
17
|
+
end
|
18
|
+
|
19
|
+
should "allow wildcards to cross line boundries" do
|
20
|
+
@f = ExceptionDescription.new(:filter1, error: "my error message.*with multiple lines")
|
21
|
+
assert @f.match?(error: "my error message\nwith more than one, with multiple lines")
|
22
|
+
end
|
23
|
+
|
24
|
+
should "complain when no regexps have a value" do
|
25
|
+
assert_raise(ArgumentError, "has all blank regexe") { ExceptionDescription.new(:filter1, error: nil) }
|
26
|
+
end
|
27
|
+
|
28
|
+
should "report when an invalid key is passed" do
|
29
|
+
assert_raise(ArgumentError, "Unknown section: not_a_parameter") { ExceptionDescription.new(:filter1, error: "my error message", not_a_parameter: false) }
|
30
|
+
end
|
31
|
+
|
32
|
+
should "allow send_to_honeybadger to be specified and have it disabled by default" do
|
33
|
+
assert !ExceptionDescription.new(:filter1, error: "my error message", send_to_honeybadger: false).send_to_honeybadger
|
34
|
+
assert ExceptionDescription.new(:filter1, error: "my error message", send_to_honeybadger: true).send_to_honeybadger
|
35
|
+
assert !ExceptionDescription.new(:filter1, error: "my error message").send_to_honeybadger
|
36
|
+
end
|
37
|
+
|
38
|
+
should "allow send_metric to be configured" do
|
39
|
+
assert !ExceptionDescription.new(:filter1, error: "my error message", send_metric: false).send_metric
|
40
|
+
assert ExceptionDescription.new(:filter1, error: "my error message").send_metric
|
41
|
+
end
|
42
|
+
|
43
|
+
should "provide metric name" do
|
44
|
+
assert_equal "filter1", ExceptionDescription.new(:filter1, error: "my error message").metric_name
|
45
|
+
assert_equal "some_other_metric_name", ExceptionDescription.new(:filter1, error: "my error message", metric_name: :some_other_metric_name).metric_name
|
46
|
+
end
|
47
|
+
|
48
|
+
should "replace spaces in metric name" do
|
49
|
+
@f = ExceptionDescription.new(:"filter has spaces", error: "my error message")
|
50
|
+
assert_equal "filter_has_spaces", @f.metric_name
|
51
|
+
end
|
52
|
+
|
53
|
+
should "allow notes to be recorded" do
|
54
|
+
assert_nil ExceptionDescription.new(:filter1, error: "my error message").notes
|
55
|
+
assert_equal "a long string", ExceptionDescription.new(:filter1, error: "my error message", notes: "a long string").notes
|
56
|
+
end
|
57
|
+
|
58
|
+
should "not consider config options in the filter set" do
|
59
|
+
assert ExceptionDescription.new(:filter1, error: "my error message", send_metric: false).match?(error: "my error message")
|
60
|
+
assert ExceptionDescription.new(:filter1, error: "my error message", metric_name: "false").match?(error: "my error message")
|
61
|
+
assert ExceptionDescription.new(:filter1, error: "my error message", notes: "hey").match?(error: "my error message")
|
62
|
+
end
|
63
|
+
|
64
|
+
should "provide exception details" do
|
65
|
+
exception_description = ExceptionDescription.new(:filter1, error: "my error message", notes: "hey")
|
66
|
+
|
67
|
+
expected = { "send_metric" => true, "metric_name" => "filter1", "notes" => "hey" }
|
68
|
+
|
69
|
+
assert_equal expected, exception_description.exception_data
|
70
|
+
end
|
71
|
+
|
72
|
+
should "match multiple email addresses" do
|
73
|
+
mobi = "ExceptionHandling::Warning: LoginAttempt::IPAddressLocked: failed login for 'mcc@mobistreak.com'"
|
74
|
+
credit = "ExceptionHandling::Warning: LoginAttempt::IPAddressLocked: failed login for 'damon@thecreditpros.com'"
|
75
|
+
|
76
|
+
exception_description = ExceptionDescription.new(:filter1, error: "ExceptionHandling::Warning: LoginAttempt::IPAddressLocked: failed login for '(mcc\@mobistreak|damon\@thecreditpros).com'")
|
77
|
+
assert exception_description.match?(error: mobi), "does not match mobi"
|
78
|
+
assert exception_description.match?(error: credit), "does not match credit"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|