rollbar 2.16.2 → 2.22.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +47 -0
  3. data/.travis.yml +182 -94
  4. data/Appraisals +10 -10
  5. data/Gemfile +45 -13
  6. data/README.md +20 -3
  7. data/Rakefile +0 -0
  8. data/data/rollbar.snippet.js +1 -1
  9. data/docs/configuration.md +15 -0
  10. data/gemfiles/rails30.gemfile +21 -14
  11. data/gemfiles/rails31.gemfile +21 -12
  12. data/gemfiles/rails32.gemfile +18 -8
  13. data/gemfiles/rails40.gemfile +18 -6
  14. data/gemfiles/rails41.gemfile +17 -6
  15. data/gemfiles/rails42.gemfile +24 -14
  16. data/gemfiles/rails50.gemfile +20 -11
  17. data/gemfiles/rails51.gemfile +20 -10
  18. data/gemfiles/rails52.gemfile +65 -0
  19. data/gemfiles/rails60.gemfile +67 -0
  20. data/lib/generators/rollbar/rollbar_generator.rb +1 -1
  21. data/lib/rails/rollbar_runner.rb +17 -2
  22. data/lib/rollbar.rb +2 -3
  23. data/lib/rollbar/capistrano.rb +71 -39
  24. data/lib/rollbar/capistrano3.rb +56 -1
  25. data/lib/rollbar/capistrano_tasks.rb +130 -0
  26. data/lib/rollbar/configuration.rb +95 -7
  27. data/lib/rollbar/delay/active_job.rb +17 -0
  28. data/lib/rollbar/delay/girl_friday.rb +2 -2
  29. data/lib/rollbar/delay/resque.rb +4 -6
  30. data/lib/rollbar/delay/shoryuken.rb +15 -9
  31. data/lib/rollbar/delay/sidekiq.rb +6 -8
  32. data/lib/rollbar/delay/sucker_punch.rb +17 -19
  33. data/lib/rollbar/delay/thread.rb +3 -3
  34. data/lib/rollbar/deploy.rb +90 -0
  35. data/lib/rollbar/encoding/encoder.rb +9 -9
  36. data/lib/rollbar/exception_reporter.rb +19 -5
  37. data/lib/rollbar/item.rb +62 -20
  38. data/lib/rollbar/item/backtrace.rb +4 -4
  39. data/lib/rollbar/item/frame.rb +7 -1
  40. data/lib/rollbar/item/locals.rb +56 -0
  41. data/lib/rollbar/json.rb +5 -51
  42. data/lib/rollbar/language_support.rb +4 -20
  43. data/lib/rollbar/lazy_store.rb +5 -5
  44. data/lib/rollbar/logger.rb +1 -0
  45. data/lib/rollbar/logger_proxy.rb +15 -2
  46. data/lib/rollbar/middleware/js.rb +110 -10
  47. data/lib/rollbar/middleware/js/json_value.rb +26 -0
  48. data/lib/rollbar/middleware/rack.rb +4 -1
  49. data/lib/rollbar/middleware/rails/rollbar.rb +10 -1
  50. data/lib/rollbar/notifier.rb +118 -49
  51. data/lib/rollbar/notifier/trace_with_bindings.rb +65 -0
  52. data/lib/rollbar/plugin.rb +54 -6
  53. data/lib/rollbar/plugins.rb +7 -1
  54. data/lib/rollbar/plugins/active_job.rb +5 -1
  55. data/lib/rollbar/plugins/basic_socket.rb +21 -6
  56. data/lib/rollbar/plugins/delayed_job/job_data.rb +3 -3
  57. data/lib/rollbar/plugins/delayed_job/plugin.rb +3 -3
  58. data/lib/rollbar/plugins/goalie.rb +11 -3
  59. data/lib/rollbar/plugins/rails/controller_methods.rb +17 -4
  60. data/lib/rollbar/plugins/rails/railtie_mixin.rb +7 -3
  61. data/lib/rollbar/plugins/rake.rb +2 -2
  62. data/lib/rollbar/plugins/sidekiq/plugin.rb +10 -6
  63. data/lib/rollbar/rake_tasks.rb +3 -86
  64. data/lib/rollbar/request_data_extractor.rb +35 -21
  65. data/lib/rollbar/rollbar_test.rb +147 -0
  66. data/lib/rollbar/scrubbers.rb +7 -3
  67. data/lib/rollbar/scrubbers/params.rb +38 -20
  68. data/lib/rollbar/scrubbers/url.rb +27 -13
  69. data/lib/rollbar/truncation.rb +9 -2
  70. data/lib/rollbar/truncation/min_body_strategy.rb +2 -3
  71. data/lib/rollbar/truncation/remove_any_key_strategy.rb +123 -0
  72. data/lib/rollbar/truncation/remove_extra_strategy.rb +35 -0
  73. data/lib/rollbar/truncation/remove_request_strategy.rb +21 -0
  74. data/lib/rollbar/truncation/strings_strategy.rb +3 -4
  75. data/lib/rollbar/util.rb +75 -45
  76. data/lib/rollbar/util/hash.rb +30 -6
  77. data/lib/rollbar/util/ip_anonymizer.rb +8 -7
  78. data/lib/rollbar/util/ip_obfuscator.rb +1 -1
  79. data/lib/rollbar/version.rb +1 -1
  80. data/lib/tasks/benchmark.rake +103 -0
  81. data/rollbar.gemspec +14 -8
  82. metadata +25 -277
  83. data/gemfiles/ruby_1_8_and_1_9_2.gemfile +0 -49
  84. data/lib/rollbar/json/default.rb +0 -11
  85. data/lib/rollbar/json/oj.rb +0 -16
  86. data/lib/rollbar/tasks/rollbar.cap +0 -47
  87. data/spec/cacert.pem +0 -3988
  88. data/spec/controllers/home_controller_spec.rb +0 -480
  89. data/spec/delay/sidekiq_spec.rb +0 -61
  90. data/spec/delay/sucker_punch_spec.rb +0 -25
  91. data/spec/delayed/backend/test.rb +0 -140
  92. data/spec/delayed/serialization/test.rb +0 -0
  93. data/spec/dummyapp/.gitignore +0 -73
  94. data/spec/dummyapp/Rakefile +0 -7
  95. data/spec/dummyapp/app/assets/javascripts/application.js +0 -3
  96. data/spec/dummyapp/app/assets/stylesheets/application.css.scss +0 -37
  97. data/spec/dummyapp/app/controllers/application_controller.rb +0 -3
  98. data/spec/dummyapp/app/controllers/home_controller.rb +0 -60
  99. data/spec/dummyapp/app/controllers/users_controller.rb +0 -17
  100. data/spec/dummyapp/app/helpers/.gitkeep +0 -0
  101. data/spec/dummyapp/app/mailers/.gitkeep +0 -0
  102. data/spec/dummyapp/app/models/.gitkeep +0 -0
  103. data/spec/dummyapp/app/models/book.rb +0 -5
  104. data/spec/dummyapp/app/models/post.rb +0 -9
  105. data/spec/dummyapp/app/models/user.rb +0 -9
  106. data/spec/dummyapp/app/views/devise/registrations/edit.html.erb +0 -27
  107. data/spec/dummyapp/app/views/devise/registrations/new.html.erb +0 -20
  108. data/spec/dummyapp/app/views/devise/shared/_links.html.erb +0 -25
  109. data/spec/dummyapp/app/views/home/cause_exception.html.erb +0 -1
  110. data/spec/dummyapp/app/views/home/index.html.erb +0 -4
  111. data/spec/dummyapp/app/views/home/report_exception.html.erb +0 -1
  112. data/spec/dummyapp/app/views/js/test.html.erb +0 -1
  113. data/spec/dummyapp/app/views/layouts/_messages.html.erb +0 -5
  114. data/spec/dummyapp/app/views/layouts/_navigation.html.erb +0 -21
  115. data/spec/dummyapp/app/views/layouts/application.html.erb +0 -25
  116. data/spec/dummyapp/app/views/layouts/simple.html.erb +0 -18
  117. data/spec/dummyapp/app/views/users/index.html.erb +0 -8
  118. data/spec/dummyapp/app/views/users/show.html.erb +0 -3
  119. data/spec/dummyapp/config.ru +0 -4
  120. data/spec/dummyapp/config/application.rb +0 -59
  121. data/spec/dummyapp/config/boot.rb +0 -10
  122. data/spec/dummyapp/config/database.yml +0 -25
  123. data/spec/dummyapp/config/environment.rb +0 -5
  124. data/spec/dummyapp/config/environments/development.rb +0 -37
  125. data/spec/dummyapp/config/environments/production.rb +0 -67
  126. data/spec/dummyapp/config/environments/test.rb +0 -37
  127. data/spec/dummyapp/config/initializers/backtrace_silencers.rb +0 -7
  128. data/spec/dummyapp/config/initializers/inflections.rb +0 -15
  129. data/spec/dummyapp/config/initializers/mime_types.rb +0 -5
  130. data/spec/dummyapp/config/initializers/rollbar.rb +0 -26
  131. data/spec/dummyapp/config/initializers/secret_token.rb +0 -7
  132. data/spec/dummyapp/config/initializers/session_store.rb +0 -8
  133. data/spec/dummyapp/config/initializers/wrap_parameters.rb +0 -16
  134. data/spec/dummyapp/config/locales/devise.en.yml +0 -58
  135. data/spec/dummyapp/config/locales/en.yml +0 -5
  136. data/spec/dummyapp/config/routes.rb +0 -17
  137. data/spec/dummyapp/config/secrets.yml +0 -2
  138. data/spec/dummyapp/db/migrate/20121121184652_devise_create_users.rb +0 -46
  139. data/spec/dummyapp/db/migrate/20121121184654_add_name_to_users.rb +0 -5
  140. data/spec/dummyapp/db/migrate/20161219184410_create_books.rb +0 -10
  141. data/spec/dummyapp/db/migrate/20161219185529_add_username_to_users.rb +0 -5
  142. data/spec/dummyapp/db/schema.rb +0 -41
  143. data/spec/dummyapp/db/seeds.rb +0 -12
  144. data/spec/dummyapp/lib/assets/.gitkeep +0 -0
  145. data/spec/dummyapp/public/404.html +0 -26
  146. data/spec/dummyapp/public/422.html +0 -26
  147. data/spec/dummyapp/public/500.html +0 -25
  148. data/spec/dummyapp/public/favicon.ico +0 -0
  149. data/spec/dummyapp/script/rails +0 -6
  150. data/spec/fixtures/file1 +0 -1
  151. data/spec/fixtures/file2 +0 -1
  152. data/spec/fixtures/payloads/message.json +0 -25
  153. data/spec/fixtures/payloads/sample.trace.json +0 -275
  154. data/spec/fixtures/payloads/sample.trace_chain.json +0 -530
  155. data/spec/fixtures/plugins/dummy1.rb +0 -5
  156. data/spec/fixtures/plugins/dummy2.rb +0 -5
  157. data/spec/generators/rollbar/rollbar_generator_rails30_spec.rb +0 -31
  158. data/spec/generators/rollbar/rollbar_generator_spec.rb +0 -51
  159. data/spec/requests/home_spec.rb +0 -49
  160. data/spec/rollbar/configuration_spec.rb +0 -46
  161. data/spec/rollbar/delay/delayed_job_spec.rb +0 -22
  162. data/spec/rollbar/delay/girl_friday_spec.rb +0 -41
  163. data/spec/rollbar/delay/resque_spec.rb +0 -37
  164. data/spec/rollbar/delay/thread_spec.rb +0 -27
  165. data/spec/rollbar/encoding/encoder_spec.rb +0 -63
  166. data/spec/rollbar/item/backtrace_spec.rb +0 -26
  167. data/spec/rollbar/item/frame_spec.rb +0 -267
  168. data/spec/rollbar/item_spec.rb +0 -736
  169. data/spec/rollbar/json/oj_spec.rb +0 -18
  170. data/spec/rollbar/json_spec.rb +0 -110
  171. data/spec/rollbar/lazy_store_spec.rb +0 -99
  172. data/spec/rollbar/logger_proxy_spec.rb +0 -50
  173. data/spec/rollbar/logger_spec.rb +0 -124
  174. data/spec/rollbar/middleware/js_spec.rb +0 -421
  175. data/spec/rollbar/middleware/sinatra_spec.rb +0 -197
  176. data/spec/rollbar/notifier_spec.rb +0 -56
  177. data/spec/rollbar/plugin_spec.rb +0 -209
  178. data/spec/rollbar/plugins/active_job_spec.rb +0 -38
  179. data/spec/rollbar/plugins/delayed_job/job_data_spec.rb +0 -48
  180. data/spec/rollbar/plugins/delayed_job_spec.rb +0 -129
  181. data/spec/rollbar/plugins/rack_spec.rb +0 -152
  182. data/spec/rollbar/plugins/rails_js_spec.rb +0 -19
  183. data/spec/rollbar/plugins/rake_spec.rb +0 -34
  184. data/spec/rollbar/plugins/resque/failure_spec.rb +0 -36
  185. data/spec/rollbar/plugins/sidekiq_spec.rb +0 -171
  186. data/spec/rollbar/plugins/validations_spec.rb +0 -56
  187. data/spec/rollbar/plugins_spec.rb +0 -68
  188. data/spec/rollbar/request_data_extractor_spec.rb +0 -270
  189. data/spec/rollbar/scrubbers/params_spec.rb +0 -314
  190. data/spec/rollbar/scrubbers/url_spec.rb +0 -136
  191. data/spec/rollbar/scrubbers_spec.rb +0 -31
  192. data/spec/rollbar/sidekig/clear_scope_spec.rb +0 -19
  193. data/spec/rollbar/truncation/frames_strategy_spec.rb +0 -70
  194. data/spec/rollbar/truncation/min_body_strategy_spec.rb +0 -57
  195. data/spec/rollbar/truncation/strings_strategy_spec.rb +0 -89
  196. data/spec/rollbar/truncation_spec.rb +0 -27
  197. data/spec/rollbar/util/hash_spec.rb +0 -22
  198. data/spec/rollbar/util/ip_anonymizer_spec.rb +0 -30
  199. data/spec/rollbar/util_spec.rb +0 -80
  200. data/spec/rollbar_bc_spec.rb +0 -380
  201. data/spec/rollbar_spec.rb +0 -1667
  202. data/spec/spec_helper.rb +0 -84
  203. data/spec/support/cause_exception.rb +0 -1
  204. data/spec/support/encoding_helpers.rb +0 -8
  205. data/spec/support/encodings/iso_8859_9 +0 -1
  206. data/spec/support/fixture_helpers.rb +0 -10
  207. data/spec/support/get_ip_raising.rb +0 -7
  208. data/spec/support/helpers.rb +0 -5
  209. data/spec/support/matchers.rb +0 -23
  210. data/spec/support/notifier_helpers.rb +0 -57
  211. data/spec/support/rollbar_api.rb +0 -57
  212. data/spec/support/shared_contexts.rb +0 -12
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'rollbar/scrubbers'
4
-
5
- describe Rollbar::Scrubbers do
6
- describe '.scrub_value' do
7
- context 'with random scrub length' do
8
- before do
9
- allow(Rollbar.configuration).to receive(:randomize_scrub_length).and_return(true)
10
- end
11
-
12
- let(:value) { 'herecomesaverylongvalue' }
13
-
14
- it 'randomizes the scrubbed string' do
15
- expect(described_class.scrub_value(value)).to match(/\*{3,8}/)
16
- end
17
- end
18
-
19
- context 'with no-random scrub length' do
20
- before do
21
- allow(Rollbar.configuration).to receive(:randomize_scrub_length).and_return(false)
22
- end
23
-
24
- let(:value) { 'herecomesaverylongvalue' }
25
-
26
- it 'randomizes the scrubbed string' do
27
- expect(described_class.scrub_value(value)).to match(/\*{#{value.length}}/)
28
- end
29
- end
30
- end
31
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- unless RUBY_VERSION == '1.8.7'
4
- require 'sidekiq'
5
- end
6
-
7
- Rollbar.plugins.load!
8
-
9
- describe Rollbar::Sidekiq::ClearScope, :reconfigure_notifier => false do
10
- describe '#call' do
11
- let(:middleware_block) { proc{} }
12
-
13
- it 'sends the error to Rollbar::Sidekiq.handle_exception' do
14
- expect(Rollbar).to receive(:reset_notifier!)
15
-
16
- subject.call(nil, nil, nil, &middleware_block)
17
- end
18
- end
19
- end unless RUBY_VERSION == '1.8.7'
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
- require 'rollbar/truncation/frames_strategy'
3
-
4
- describe Rollbar::Truncation::FramesStrategy do
5
- def expand_frames(frames)
6
- frames * (1 + 300 / frames.count)
7
- end
8
-
9
- describe '.call', :fixture => :payload do
10
- context 'with trace key' do
11
- let(:payload_fixture) { 'payloads/sample.trace.json' }
12
- let(:frames) { payload['data']['body']['trace']['frames'].clone }
13
-
14
- before do
15
- payload['data']['body']['trace']['frames'] = expand_frames(frames)
16
- end
17
-
18
- it 'returns a new payload with 300 frames' do
19
- result = Rollbar::JSON.load(described_class.call(payload))
20
-
21
- new_frames = result['data']['body']['trace']['frames']
22
-
23
- expect(new_frames.count).to be_eql(300)
24
- expect(new_frames.first).to be_eql(frames.first)
25
- expect(new_frames.last).to be_eql(frames.last)
26
- end
27
- end
28
-
29
- context 'with trace_chain key' do
30
- let(:payload_fixture) { 'payloads/sample.trace_chain.json' }
31
-
32
- let(:frames1) { payload['data']['body']['trace_chain'][0]['frames'].clone }
33
- let(:frames2) { payload['data']['body']['trace_chain'][1]['frames'].clone }
34
-
35
- before do
36
- payload['data']['body']['trace_chain'][0]['frames'] = expand_frames(frames1)
37
- payload['data']['body']['trace_chain'][1]['frames'] = expand_frames(frames2)
38
- end
39
-
40
- it 'returns a new payload with 300 frames for each chain item' do
41
- result = Rollbar::JSON.load(described_class.call(payload))
42
-
43
- new_frames1 = result['data']['body']['trace_chain'][0]['frames']
44
- new_frames2 = result['data']['body']['trace_chain'][1]['frames']
45
-
46
- expect(new_frames1.count).to be_eql(300)
47
- expect(new_frames1.first).to be_eql(frames1.first)
48
- expect(new_frames1.last).to be_eql(frames1.last)
49
-
50
- expect(new_frames2.count).to be_eql(300)
51
- expect(new_frames2.first).to be_eql(frames2.first)
52
- expect(new_frames2.last).to be_eql(frames2.last)
53
- end
54
- end
55
-
56
- context 'without trace or trace_chain', :fixture => :payload do
57
- let(:payload_fixture) { 'payloads/sample.trace.json' }
58
-
59
- before do
60
- payload['data']['body'].delete('trace')
61
- end
62
-
63
- it 'returns the original payload' do
64
- result = Rollbar::JSON.load(described_class.call(payload))
65
-
66
- expect(result).to be_eql(payload)
67
- end
68
- end
69
- end
70
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
- require 'rollbar/truncation/frames_strategy'
3
-
4
- describe Rollbar::Truncation::MinBodyStrategy do
5
- describe '.call', :fixture => :payload do
6
- let(:message) { 'a' * 1_000 }
7
-
8
- context 'with trace key ' do
9
- let(:payload_fixture) { 'payloads/sample.trace.json' }
10
- let!(:frames) { payload['data']['body']['trace']['frames'].clone }
11
-
12
- before do
13
- payload['data']['body']['trace']['exception']['message'] = message
14
- end
15
-
16
- it 'truncates the exception message and frames array' do
17
- result = Rollbar::JSON.load(described_class.call(payload))
18
-
19
- trace = result['data']['body']['trace']
20
- expect(trace['frames'].count).to eq 2
21
- expect(trace['exception']['message']).to be_eql('a' * 255)
22
- end
23
- end
24
-
25
- context 'with trace_chain key ' do
26
- let(:payload_fixture) { 'payloads/sample.trace_chain.json' }
27
- let!(:frames1) { payload['data']['body']['trace_chain'][0]['frames'].clone }
28
- let!(:frames2) { payload['data']['body']['trace_chain'][1]['frames'].clone }
29
-
30
- before do
31
- payload['data']['body']['trace_chain'][0]['exception']['message'] = message
32
- payload['data']['body']['trace_chain'][1]['exception']['message'] = message
33
- end
34
-
35
- it 'truncates the exception message and frames array' do
36
- result = Rollbar::JSON.load(described_class.call(payload))
37
-
38
- traces = result['data']['body']['trace_chain']
39
- expect(traces[0]['frames'].count).to eq 2
40
- expect(traces[0]['exception']['message']).to be_eql('a' * 255)
41
-
42
- expect(traces[1]['frames'].count).to eq 2
43
- expect(traces[1]['exception']['message']).to be_eql('a' * 255)
44
- end
45
- end
46
-
47
- context 'with a message payload' do
48
- let(:payload_fixture) { 'payloads/message.json' }
49
-
50
- it "doesn't truncate anything and returns same payload" do
51
- result = Rollbar::JSON.load(described_class.call(payload))
52
-
53
- expect(result).to be_eql(payload)
54
- end
55
- end
56
- end
57
- end
@@ -1,89 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
- require 'rollbar/truncation/frames_strategy'
5
-
6
- describe Rollbar::Truncation::StringsStrategy do
7
- describe '.call' do
8
- let(:long_message) { 'a' * 2000 }
9
- let(:payload) do
10
- {
11
- 'truncated' => long_message,
12
- 'not_truncated' => '123456',
13
- 'hash' => {
14
- 'inner_truncated' => long_message,
15
- 'inner_not_truncated' => '567',
16
- 'array' => ['12345678', '12', { 'inner_inner' => long_message }]
17
- }
18
- }
19
- end
20
-
21
- it 'should truncate all nested strings in the payload' do
22
- result = Rollbar::JSON.load(described_class.call(payload))
23
-
24
- expect(result['truncated'].size).to be_eql(1024)
25
- expect(result['hash']['inner_truncated'].size).to be_eql(1024)
26
- expect(result['hash']['array'][2]['inner_inner'].size).to be_eql(1024)
27
- end
28
-
29
- context 'with utf8 strings' do
30
- let(:long_message) { 'Ŝǻмρļẻ śţяịņģ' + 'a' * 2000 }
31
- let(:payload) do
32
- {
33
- 'truncated' => long_message,
34
- 'not_truncated' => '123456',
35
- }
36
- end
37
-
38
- it 'should truncate utf8 strings properly' do
39
- result = Rollbar::JSON.load(described_class.call(payload))
40
- expect(result['truncated']).to match(/^Ŝǻмρļẻ śţяịņģa*\.{3}/)
41
- end
42
- end
43
-
44
- context 'when first threshold is not enough' do
45
- let(:payload) do
46
- 512.times.to_enum.reduce({}) do |hash, i|
47
- hash[i.to_s] = 'a' * 1024
48
- hash
49
- end
50
- end
51
-
52
- it 'truncates to 512 size strings' do
53
- result = Rollbar::JSON.load(described_class.call(payload))
54
-
55
- expect(result['0'].size).to be_eql(512)
56
- end
57
- end
58
-
59
- context 'when second threshold is still not enough' do
60
- let(:payload) do
61
- 1024.times.to_enum.reduce({}) do |hash, i|
62
- hash[i.to_s] = 'a' * 1024
63
- hash
64
- end
65
- end
66
-
67
- it 'truncates to 256 size strings, the third threshold' do
68
- result = Rollbar::JSON.load(described_class.call(payload))
69
-
70
- expect(result['0'].size).to be_eql(256)
71
- end
72
- end
73
-
74
- context 'when third threshold is still not enough' do
75
- let(:payload) do
76
- 1024.times.to_enum.reduce({}) do |hash, i|
77
- hash[i.to_s] = 'a' * 1024
78
- hash
79
- end
80
- end
81
-
82
- it 'just return the value for third threshold' do
83
- result = Rollbar::JSON.load(described_class.call(payload))
84
-
85
- expect(result['0'].size).to be_eql(256)
86
- end
87
- end
88
- end
89
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
- require 'rollbar/truncation'
3
-
4
- describe Rollbar::Truncation do
5
- describe '.truncate' do
6
- let(:payload) { {} }
7
-
8
- context 'if truncation is not needed' do
9
- it 'only calls RawStrategy is truncation is not needed' do
10
- allow(described_class).to receive(:truncate?).and_return(false)
11
- expect(Rollbar::Truncation::RawStrategy).to receive(:call).with(payload)
12
-
13
- Rollbar::Truncation.truncate(payload)
14
- end
15
- end
16
-
17
- context 'if truncation is needed' do
18
- it 'calls the next strategy, FramesStrategy' do
19
- allow(described_class).to receive(:truncate?).and_return(true, false)
20
- expect(Rollbar::Truncation::RawStrategy).to receive(:call).with(payload)
21
- expect(Rollbar::Truncation::FramesStrategy).to receive(:call).with(payload)
22
-
23
- Rollbar::Truncation.truncate(payload)
24
- end
25
- end
26
- end
27
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- require 'rollbar/util/hash'
3
-
4
- describe Rollbar::Util::Hash do
5
- let(:value) do
6
- {
7
- :foo => 'bar',
8
- :bar => {
9
- :foo => 'bar',
10
- :bar => [{:foo => 'bar'}]
11
- },
12
- }
13
- end
14
-
15
- it 'converts the symbol keys to string' do
16
- new_hash = described_class.deep_stringify_keys(value)
17
-
18
- expect(new_hash['foo']).to be_eql('bar')
19
- expect(new_hash['bar']['foo']).to be_eql('bar')
20
- expect(new_hash['bar']['bar'][0]['foo']).to be_eql('bar')
21
- end
22
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'rollbar/util/ip_anonymizer'
3
-
4
- describe Rollbar::Util::IPAnonymizer do
5
-
6
- before do
7
- Rollbar.configuration.anonymize_user_ip = true
8
- end
9
-
10
- context 'with IPv4 address' do
11
- let(:ip) { '127.0.0.1' }
12
-
13
- it 'anonymizes the IP by replacing the last octet with 0' do
14
- anonymized_ip = described_class.anonymize_ip(ip)
15
-
16
- expect(anonymized_ip).to be_eql(IPAddr.new('127.0.0.0').to_s)
17
- end
18
- end
19
-
20
- context 'with IPv6 address' do
21
- let(:ip) { '2001:0db8:85a3:0000:0000:8a2e:0370:7334' }
22
-
23
- it 'anonymizes the IP by replacing the last 80 bits with 0' do
24
-
25
- anonymized_ip = described_class.anonymize_ip(ip)
26
-
27
- expect(anonymized_ip).to be_eql(IPAddr.new('2001:db8:85a3::').to_s)
28
- end
29
- end
30
- end
@@ -1,80 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- require 'rollbar/util'
6
-
7
- describe Rollbar::Util do
8
- describe '.deep_merge' do
9
- context 'with nil arguments' do
10
- let(:data) do
11
- { :foo => :bar }
12
- end
13
-
14
- it 'doesnt fail and returns same hash' do
15
- result = Rollbar::Util.deep_merge(nil, data)
16
-
17
- expect(result).to be_eql(data)
18
- end
19
- end
20
- end
21
-
22
- describe '.enforce_valid_utf8' do
23
- # TODO(jon): all these tests should be removed since they are in
24
- # in spec/rollbar/encoding/encoder.rb.
25
- #
26
- # This should just check that in payload with simple values and
27
- # nested values are each one passed through Rollbar::Encoding.encode
28
- context 'with utf8 string and ruby > 1.8' do
29
- next unless String.instance_methods.include?(:force_encoding)
30
-
31
- let(:payload) { { :foo => 'Изменение' } }
32
-
33
- it 'just returns the same string' do
34
- payload_copy = payload.clone
35
- described_class.enforce_valid_utf8(payload_copy)
36
-
37
- expect(payload_copy[:foo]).to be_eql('Изменение')
38
- end
39
- end
40
-
41
- it 'should replace invalid utf8 values' do
42
- bad_key = force_to_ascii("inner \x92bad key")
43
-
44
- payload = {
45
- :bad_value => force_to_ascii("bad value 1\255"),
46
- :bad_value_2 => force_to_ascii("bad\255 value 2"),
47
- force_to_ascii("bad\255 key") => "good value",
48
- :hash => {
49
- :inner_bad_value => force_to_ascii("\255\255bad value 3"),
50
- bad_key.to_sym => 'inner good value',
51
- force_to_ascii("bad array key\255") => [
52
- 'good array value 1',
53
- force_to_ascii("bad\255 array value 1\255"),
54
- {
55
- :inner_inner_bad => force_to_ascii("bad inner \255inner value")
56
- }
57
- ]
58
- }
59
- }
60
-
61
-
62
- payload_copy = payload.clone
63
- described_class.enforce_valid_utf8(payload_copy)
64
-
65
- payload_copy[:bad_value].should == "bad value 1"
66
- payload_copy[:bad_value_2].should == "bad value 2"
67
- payload_copy["bad key"].should == "good value"
68
- payload_copy.keys.should_not include("bad\456 key")
69
- payload_copy[:hash][:inner_bad_value].should == "bad value 3"
70
- payload_copy[:hash][:"inner bad key"].should == 'inner good value'
71
- payload_copy[:hash]["bad array key"].should == [
72
- 'good array value 1',
73
- 'bad array value 1',
74
- {
75
- :inner_inner_bad => 'bad inner inner value'
76
- }
77
- ]
78
- end
79
- end
80
- end
@@ -1,380 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'logger'
4
- require 'spec_helper'
5
-
6
- describe Rollbar do
7
- let(:notifier) { Rollbar.notifier }
8
-
9
- context 'bc_report_message' do
10
- before do
11
- configure
12
- Rollbar.configure do |config|
13
- config.logger = logger_mock
14
- end
15
- end
16
-
17
- let(:logger_mock) { double('Rails.logger').as_null_object }
18
- let(:user) do
19
- User.create(:email => 'email@example.com',
20
- :encrypted_password => '',
21
- :created_at => Time.now,
22
- :updated_at => Time.now)
23
- end
24
-
25
- it 'should report simple messages' do
26
- logger_mock.should_receive(:info).with('[Rollbar] Scheduling item')
27
- logger_mock.should_receive(:info).with('[Rollbar] Success')
28
-
29
- Rollbar.report_message('Test message')
30
- end
31
-
32
- it 'should not report anything when disabled' do
33
- logger_mock.should_not_receive(:info).with('[Rollbar] Success')
34
-
35
- Rollbar.configure do |config|
36
- config.enabled = false
37
- end
38
-
39
- Rollbar.report_message('Test message that should be ignored')
40
- end
41
-
42
- it 'should report messages with extra data' do
43
- logger_mock.should_receive(:info).with('[Rollbar] Success')
44
- Rollbar.report_message('Test message with extra data', 'debug', :foo => 'bar',
45
- :hash => { :a => 123, :b => 'xyz' })
46
- end
47
-
48
- it 'should not crash with circular extra_data' do
49
- a = { :foo => 'bar' }
50
- b = { :a => a }
51
- c = { :b => b }
52
- a[:c] = c
53
-
54
- logger_mock.should_receive(:error).with(/\[Rollbar\] Reporting internal error encountered while sending data to Rollbar./)
55
-
56
- Rollbar.report_message('Test message with circular extra data', 'debug', a)
57
- end
58
-
59
- it 'should be able to report form validation errors when they are present' do
60
- logger_mock.should_receive(:info).with('[Rollbar] Success')
61
- user.errors.add(:example, 'error')
62
- user.report_validation_errors_to_rollbar
63
- end
64
-
65
- it 'should not report form validation errors when they are not present' do
66
- logger_mock.should_not_receive(:info).with('[Rollbar] Success')
67
- user.errors.clear
68
- user.report_validation_errors_to_rollbar
69
- end
70
- end
71
-
72
- context 'bc_report_message_with_request' do
73
- before(:each) do
74
- configure
75
- Rollbar.configure do |config|
76
- config.logger = logger_mock
77
- end
78
- end
79
-
80
- after do
81
- Rollbar.unconfigure
82
- configure
83
- end
84
-
85
- let(:logger_mock) { double('Rails.logger').as_null_object }
86
- let(:user) { User.create(:email => 'email@example.com', :encrypted_password => '', :created_at => Time.now, :updated_at => Time.now) }
87
-
88
- it 'should report simple messages' do
89
- allow(Rollbar).to receive(:notifier).and_return(notifier)
90
- logger_mock.should_receive(:info).with('[Rollbar] Scheduling item')
91
- logger_mock.should_receive(:info).with('[Rollbar] Success')
92
- Rollbar.report_message_with_request('Test message')
93
-
94
- Rollbar.last_report[:request].should be_nil
95
- Rollbar.last_report[:person].should be_nil
96
- end
97
-
98
- it 'should report messages with request, person data and extra data' do
99
- Rollbar.last_report = nil
100
-
101
- logger_mock.should_receive(:info).with('[Rollbar] Scheduling item')
102
- logger_mock.should_receive(:info).with('[Rollbar] Success')
103
-
104
- request_data = {
105
- :params => {:foo => 'bar'}
106
- }
107
-
108
- person_data = {
109
- :id => 123,
110
- :username => 'username'
111
- }
112
-
113
- extra_data = {
114
- :extra_foo => 'extra_bar'
115
- }
116
-
117
- Rollbar.report_message_with_request('Test message', 'info', request_data, person_data, extra_data)
118
-
119
- Rollbar.last_report[:request].should == request_data
120
- Rollbar.last_report[:person].should == person_data
121
- Rollbar.last_report[:body][:message][:extra][:extra_foo].should == 'extra_bar'
122
- end
123
- end
124
-
125
- context 'bc_report_exception' do
126
- before(:each) do
127
- configure
128
- Rollbar.configure do |config|
129
- config.logger = logger_mock
130
- end
131
-
132
- begin
133
- foo = bar
134
- rescue => e
135
- @exception = e
136
- end
137
- end
138
-
139
- after do
140
- Rollbar.unconfigure
141
- configure
142
- end
143
-
144
- let(:logger_mock) { double('Rails.logger').as_null_object }
145
-
146
- it 'should report exceptions without person or request data' do
147
- logger_mock.should_receive(:info).with('[Rollbar] Success')
148
- Rollbar.report_exception(@exception)
149
- end
150
-
151
- it 'should not report anything when disabled' do
152
- logger_mock.should_not_receive(:info).with('[Rollbar] Success')
153
- Rollbar.configure do |config|
154
- config.enabled = false
155
- end
156
-
157
- Rollbar.report_exception(@exception)
158
- end
159
-
160
- it 'should be enabled when freshly configured' do
161
- Rollbar.configuration.enabled.should == true
162
- end
163
-
164
- it 'should not be enabled when not configured' do
165
- Rollbar.clear_notifier!
166
-
167
- Rollbar.configuration.enabled.should be_nil
168
- Rollbar.report_exception(@exception).should == 'disabled'
169
- end
170
-
171
- it 'should stay disabled if configure is called again' do
172
- Rollbar.clear_notifier!
173
-
174
- # configure once, setting enabled to false.
175
- Rollbar.configure do |config|
176
- config.enabled = false
177
- end
178
-
179
- # now configure again (perhaps to change some other values)
180
- Rollbar.configure do |config| end
181
-
182
- Rollbar.configuration.enabled.should == false
183
- Rollbar.report_exception(@exception).should == 'disabled'
184
- end
185
-
186
- it 'should report exceptions with request and person data' do
187
- logger_mock.should_receive(:info).with('[Rollbar] Success')
188
- request_data = {
189
- :params => { :foo => 'bar' },
190
- :url => 'http://localhost/',
191
- :user_ip => '127.0.0.1',
192
- :headers => {},
193
- :GET => { 'baz' => 'boz' },
194
- :session => { :user_id => 123 },
195
- :method => 'GET',
196
- }
197
- person_data = {
198
- :id => 1,
199
- :username => 'test',
200
- :email => 'test@example.com'
201
- }
202
- Rollbar.report_exception(@exception, request_data, person_data)
203
- end
204
-
205
- # Skip jruby 1.9+ (https://github.com/jruby/jruby/issues/2373)
206
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' && (not RUBY_VERSION =~ /^1\.9/)
207
- it 'should work with an IO object as rack.errors' do
208
- logger_mock.should_receive(:info).with('[Rollbar] Success')
209
-
210
- request_data = {
211
- :params => { :foo => 'bar' },
212
- :url => 'http://localhost/',
213
- :user_ip => '127.0.0.1',
214
- :headers => {},
215
- :GET => { 'baz' => 'boz' },
216
- :session => { :user_id => 123 },
217
- :method => 'GET',
218
- :env => { :'rack.errors' => IO.new(2, File::WRONLY) },
219
- }
220
-
221
- person_data = {
222
- :id => 1,
223
- :username => 'test',
224
- :email => 'test@example.com'
225
- }
226
-
227
- Rollbar.report_exception(@exception, request_data, person_data)
228
- end
229
- end
230
-
231
- it 'should ignore ignored exception classes' do
232
- Rollbar.configure do |config|
233
- config.exception_level_filters = { 'NameError' => 'ignore' }
234
- end
235
-
236
- logger_mock.should_not_receive(:info)
237
- logger_mock.should_not_receive(:error)
238
-
239
- Rollbar.report_exception(@exception)
240
- end
241
-
242
- it 'should ignore ignored persons' do
243
- Rollbar.configure do |config|
244
- config.ignored_person_ids += [1]
245
- end
246
-
247
- logger_mock.should_not_receive(:info)
248
- logger_mock.should_not_receive(:error)
249
-
250
- person_data = {
251
- :id => 1,
252
- :username => 'test',
253
- :email => 'test@example.com'
254
- }
255
- Rollbar.report_exception(@exception, {}, person_data)
256
- end
257
-
258
- it 'should not ignore non-ignored persons' do
259
- Rollbar.configure do |config|
260
- config.ignored_person_ids += [1]
261
- end
262
-
263
- Rollbar.last_report = nil
264
-
265
- person_data = {
266
- :id => 1,
267
- :username => 'test',
268
- :email => 'test@example.com'
269
- }
270
- Rollbar.report_exception(@exception, {}, person_data)
271
- Rollbar.last_report.should be_nil
272
-
273
- person_data = {
274
- :id => 2,
275
- :username => 'test2',
276
- :email => 'test2@example.com'
277
- }
278
- Rollbar.report_exception(@exception, {}, person_data)
279
- Rollbar.last_report.should_not be_nil
280
- end
281
-
282
- it 'should allow callables to set exception filtered level with :use_exception_level_filters option' do
283
- callable_mock = double
284
- Rollbar.configure do |config|
285
- config.exception_level_filters = { 'NameError' => callable_mock }
286
- end
287
-
288
- callable_mock.should_receive(:call).with(@exception).at_least(:once).and_return('info')
289
- logger_mock.should_receive(:info)
290
- logger_mock.should_not_receive(:error)
291
-
292
- Rollbar.report_exception(@exception)
293
- end
294
-
295
- it 'should not report exceptions when silenced' do
296
- notifier.should_not_receive :schedule_payload
297
-
298
- begin
299
- test_var = 1
300
- Rollbar.silenced do
301
- test_var = 2
302
- raise
303
- end
304
- rescue => e
305
- Rollbar.report_exception(e)
306
- end
307
-
308
- test_var.should == 2
309
- end
310
-
311
- it 'should report exception objects with no backtrace' do
312
- allow(Rollbar).to receive(:notifier).and_return(notifier)
313
-
314
- payload = nil
315
-
316
- notifier.stub(:schedule_item) do |*args|
317
- payload = args[0]
318
- end
319
-
320
- Rollbar.report_exception(StandardError.new('oops'))
321
-
322
- payload['data'][:body][:trace][:frames].should == []
323
- payload['data'][:body][:trace][:exception][:class].should == 'StandardError'
324
- payload['data'][:body][:trace][:exception][:message].should == 'oops'
325
- end
326
-
327
- it 'should return the exception data with a uuid, on platforms with SecureRandom' do
328
- if defined?(SecureRandom) and SecureRandom.respond_to?(:uuid)
329
- notifier.stub(:schedule_payload) do |*args| end
330
-
331
- exception_data = Rollbar.report_exception(StandardError.new('oops'))
332
- exception_data[:uuid].should_not be_nil
333
- end
334
- end
335
-
336
- it 'should report exception objects with nonstandard backtraces' do
337
- allow(Rollbar).to receive(:notifier).and_return(notifier)
338
-
339
- payload = nil
340
-
341
- notifier.stub(:schedule_item) do |*args|
342
- payload = args[0]
343
- end
344
-
345
- class CustomException < StandardError
346
- def backtrace
347
- ['custom backtrace line']
348
- end
349
- end
350
-
351
- exception = CustomException.new('oops')
352
-
353
- Rollbar.report_exception(exception)
354
-
355
- payload['data'][:body][:trace][:frames][0][:method].should == 'custom backtrace line'
356
- end
357
-
358
- it 'should report exceptions with a custom level' do
359
- allow(Rollbar).to receive(:notifier).and_return(notifier)
360
- payload = nil
361
-
362
- notifier.stub(:schedule_item) do |*args|
363
- payload = args[0]
364
- end
365
-
366
- Rollbar.report_exception(@exception)
367
-
368
- payload['data'][:level].should == 'error'
369
-
370
- Rollbar.report_exception(@exception, nil, nil, 'debug')
371
-
372
- payload['data'][:level].should == 'debug'
373
- end
374
- end
375
-
376
- # configure with some basic params
377
- def configure
378
- reconfigure_notifier
379
- end
380
- end