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,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'rollbar/json/oj'
4
-
5
- describe Rollbar::JSON::Oj do
6
- let(:options) do
7
- {
8
- :mode => :compat,
9
- :use_to_json => false,
10
- :symbol_keys => false,
11
- :circular => false
12
- }
13
- end
14
-
15
- it 'returns correct options' do
16
- expect(described_class.options).to be_eql(options)
17
- end
18
- end
@@ -1,110 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'multi_json'
4
- require 'rollbar/json'
5
- require 'rollbar/configuration'
6
-
7
- class Rollbar::JSON::MockAdapter
8
- def self.options
9
- { 'mock' => 'adapter' }
10
- end
11
- end
12
-
13
- module MultiJson
14
- module Adapters
15
- module MockAdapter
16
- end
17
- end
18
- end
19
-
20
- module MultiJson
21
- module Adapters
22
- module MissingCustomOptions
23
- end
24
- end
25
- end
26
-
27
- module MissingCustomOptions
28
- # Consider the fact that there's MultiJson::Adapters::Yajl but not
29
- # Rollbar::JSON::Yajl, it should not look for ::Yajl but only
30
- # Rollbar::JSON::Yajl.
31
- end
32
-
33
- describe Rollbar::JSON do
34
- let(:payload) do
35
- { :foo => :bar }
36
- end
37
- let(:adapter_options) { { 'option' => 'value' } }
38
-
39
- describe '.dump' do
40
- before do
41
- allow(described_class).to receive(:adapter_options).and_return(adapter_options)
42
- end
43
-
44
- it 'calls MultiJson.dump' do
45
- expect(::MultiJson).to receive(:dump).once.with(payload, adapter_options)
46
-
47
- described_class.dump(payload)
48
- end
49
- end
50
-
51
- describe '.load' do
52
- before do
53
- allow(described_class).to receive(:adapter_options).and_return(adapter_options)
54
- end
55
-
56
- it 'calls MultiJson.load' do
57
- expect(::MultiJson).to receive(:load).once.with(payload, adapter_options)
58
-
59
- described_class.load(payload)
60
- end
61
- end
62
-
63
- describe '.with_adapter' do
64
- let(:object) { double(:foo => 'bar') }
65
- let(:callback) do
66
- proc { object.foo }
67
- end
68
- let(:adapter) { described_class.detect_multi_json_adapter }
69
-
70
- it 'calls mock.something with an adapter' do
71
- expect(MultiJson).to receive(:with_adapter).with(adapter).and_call_original
72
- expect(object).to receive(:foo).once
73
-
74
- described_class.with_adapter(&callback)
75
- end
76
- end
77
-
78
- describe '.adapter_options' do
79
- it 'calls .options in adapter module' do
80
- expect(described_class.options_module).to receive(:options)
81
-
82
- described_class.adapter_options
83
- end
84
- end
85
-
86
- describe '.options_module' do
87
- before do
88
- described_class.options_module = nil
89
- allow(MultiJson).to receive(:current_adapter).and_return(multi_json_module)
90
- end
91
-
92
- context 'with a defined rollbar adapter' do
93
- let(:multi_json_module) { MultiJson::Adapters::MockAdapter }
94
- let(:expected_adapter) { Rollbar::JSON::MockAdapter }
95
-
96
- it 'returns the correct options' do
97
- expect(described_class.options_module).to be(expected_adapter)
98
- end
99
- end
100
-
101
- context 'without a defined rollbar adapter' do
102
- let(:multi_json_module) { MultiJson::Adapters::MissingCustomOptions }
103
- let(:expected_adapter) { Rollbar::JSON::Default }
104
-
105
- it 'returns the correct options' do
106
- expect(described_class.options_module).to be(expected_adapter)
107
- end
108
- end
109
- end
110
- end
@@ -1,99 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'rollbar/lazy_store'
4
-
5
-
6
- describe Rollbar::LazyStore do
7
- subject { Rollbar::LazyStore.new(data) }
8
- let(:lazy_value) do
9
- proc { :bar }
10
- end
11
- let(:data) do
12
- {
13
- :somekey => :value,
14
- :foo => lazy_value
15
- }
16
- end
17
-
18
- describe '#[]' do
19
- it 'gets the regular values' do
20
- expect(subject[:somekey]).to be_eql(:value)
21
- end
22
-
23
- it 'gets the lazy values and evaluates them just once' do
24
- expect(lazy_value).to receive(:call).once.and_call_original
25
-
26
- value1 = subject[:foo]
27
- value2 = subject[:foo]
28
-
29
- expect(value1).to be_eql(:bar)
30
- expect(value2).to be_eql(:bar)
31
- end
32
- end
33
-
34
- describe '#[]=' do
35
- before do
36
- # load data in :foo
37
- subject[:foo]
38
- end
39
-
40
- it 'sets the data and clears the loaded data' do
41
- subject[:foo] = 'something-else'
42
-
43
- expect(subject[:foo]).to be_eql('something-else')
44
- end
45
- end
46
-
47
- describe '#eql?' do
48
- context 'passing a Hash' do
49
- it 'checks correctly eql?' do
50
- expect(subject.eql?(data)).to be(true)
51
- expect(subject.eql?({})).to be(false)
52
- end
53
- end
54
-
55
- context 'passing a LazyStore' do
56
- it 'checks correctly eql?' do
57
- expect(subject.eql?(Rollbar::LazyStore.new(data))).to be(true)
58
- expect(subject.eql?(Rollbar::LazyStore.new({}))).to be(false)
59
- end
60
- end
61
- end
62
-
63
- describe '#==' do
64
- context 'passing a Hash' do
65
- it 'checks correctly eql?' do
66
- expect(subject == data).to be(true)
67
- expect(subject == {}).to be(false)
68
- end
69
- end
70
-
71
- context 'passing a LazyStore' do
72
- it 'checks correctly eql?' do
73
- expect(subject == Rollbar::LazyStore.new(data)).to be(true)
74
- expect(subject == Rollbar::LazyStore.new({})).to be(false)
75
- end
76
- end
77
- end
78
-
79
- describe '#data' do
80
- it 'returns the data with lazy values loaded' do
81
- value = subject.data
82
-
83
- expected_value = {
84
- :somekey => :value,
85
- :foo => :bar
86
- }
87
- expect(value).to be_eql(expected_value)
88
- end
89
- end
90
-
91
- describe '#clone' do
92
- it 'returns a new object, with same data and empty loaded_data' do
93
- new_scope = subject.clone
94
-
95
- expect(new_scope.instance_variable_get('@loaded_data')).to be_empty
96
- expect(new_scope.raw).to be_eql(subject.raw)
97
- end
98
- end
99
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rollbar::LoggerProxy do
4
- let(:logger) { double(:logger) }
5
- let(:message) { 'the-message' }
6
-
7
- subject { described_class.new(logger) }
8
-
9
- before do
10
- allow(Rollbar.configuration).to receive(:enabled).and_return(true)
11
- end
12
-
13
- shared_examples 'delegate to logger' do
14
- it 'logs with correct level' do
15
- expect(logger).to receive(level).with(message)
16
-
17
- subject.send(level, message)
18
- end
19
- end
20
-
21
- %w(info error warn debug).each do |level|
22
- describe "#{level}" do
23
- it_should_behave_like 'delegate to logger' do
24
- let(:level) { level }
25
- end
26
- end
27
- end
28
-
29
- describe '#log' do
30
- context 'if Rollbar is disabled' do
31
- before do
32
- expect(Rollbar.configuration).to receive(:enabled).and_return(false)
33
- end
34
-
35
- it 'doesnt call the logger' do
36
- expect(logger).to_not receive(:error)
37
-
38
- subject.log('error', 'foo')
39
- end
40
- end
41
-
42
- context 'if the logger fails' do
43
- it 'doesnt raise' do
44
- allow(logger).to receive(:info).and_raise(StandardError.new)
45
-
46
- expect { subject.log('info', message) }.not_to raise_error
47
- end
48
- end
49
- end
50
- end
@@ -1,124 +0,0 @@
1
- require 'spec_helper'
2
- require 'rollbar/logger'
3
-
4
- describe Rollbar::Logger do
5
- describe '#add' do
6
- context 'with severity under level' do
7
- it 'returns true' do
8
- result = subject.add(Logger::DEBUG, 'foo')
9
-
10
- expect(result).to be_truthy
11
- end
12
- end
13
-
14
- context 'with blank message' do
15
- it 'returns true' do
16
- result = subject.add(subject.level)
17
-
18
- expect(result).to be_truthy
19
- end
20
- end
21
-
22
- context 'with ERROR severity' do
23
- let(:message) { 'foo' }
24
-
25
- it 'calls Rollbar to send the message' do
26
- expect_any_instance_of(Rollbar::Notifier).to receive(:log).with(:error, message)
27
-
28
- subject.add(Logger::ERROR, message)
29
- end
30
- end
31
-
32
- context 'with FATAL severity' do
33
- let(:message) { 'foo' }
34
-
35
- it 'calls Rollbar to send the message with critical level' do
36
- expect_any_instance_of(Rollbar::Notifier).to receive(:log).with(:critical, message)
37
-
38
- subject.add(Logger::FATAL, message)
39
- end
40
- end
41
-
42
- context 'with UNKNOWN severity' do
43
- let(:message) { 'foo' }
44
-
45
- it 'calls Rollbar to send the message with error level' do
46
- expect_any_instance_of(Rollbar::Notifier).to receive(:log).with(:error, message)
47
-
48
- subject.add(Logger::UNKNOWN, message)
49
- end
50
- end
51
-
52
- context 'with out of range severity' do
53
- let(:message) { 'foo' }
54
-
55
- it 'calls Rollbar to send the message with error level' do
56
- expect_any_instance_of(Rollbar::Notifier).to receive(:log).with(:error, message)
57
-
58
- subject.add(10, message)
59
- end
60
- end
61
-
62
- context 'without active_support/core_ext/object/blank' do
63
- let(:message) { 'foo'.tap { |message| message.instance_eval('undef :blank?') } }
64
-
65
- it 'calls Rollbar to send the message' do
66
- expect_any_instance_of(Rollbar::Notifier).to receive(:log).with(:error, message)
67
-
68
- subject.add(Logger::ERROR, message)
69
- end
70
- end
71
- end
72
-
73
- describe '#<<' do
74
- let(:message) { 'foo' }
75
-
76
- it 'calls #error' do
77
- expect(subject).to receive(:error).with(message)
78
-
79
- subject << message
80
- end
81
- end
82
-
83
- describe '#formatter=' do
84
- it 'fails with FormatterNotSupported' do
85
- expect do
86
- subject.formatter = double
87
- end.to raise_error(Rollbar::Logger::FormatterNotSupported)
88
- end
89
- end
90
-
91
- describe '#formatter' do
92
- it 'fails with FormatterNotSupported' do
93
- expect do
94
- subject.formatter
95
- end.to raise_error(Rollbar::Logger::FormatterNotSupported)
96
- end
97
- end
98
-
99
- describe '#datetime_format=' do
100
- it 'fails with DatetimeFormatNotSupported' do
101
- expect do
102
- subject.datetime_format = double
103
- end.to raise_error(Rollbar::Logger::DatetimeFormatNotSupported)
104
- end
105
- end
106
-
107
- describe '#datetime_format' do
108
- it 'fails with DatetimeFormatNotSupported' do
109
- expect do
110
- subject.datetime_format
111
- end.to raise_error(Rollbar::Logger::DatetimeFormatNotSupported)
112
- end
113
- end
114
-
115
- describe '#rollbar' do
116
- it 'returns a Rollbar notifier with a logger pointing to /dev/null' do
117
- notifier = subject.rollbar
118
- logger = notifier.configuration.logger
119
- logdev = logger.instance_eval { @logdev }
120
-
121
- expect(logdev.filename).to be_eql('/dev/null')
122
- end
123
- end
124
- end
@@ -1,421 +0,0 @@
1
- require 'spec_helper'
2
- require 'rollbar/middleware/js'
3
-
4
- describe Rollbar::Middleware::Js do
5
- subject { described_class.new(app, config) }
6
-
7
- let(:env) { {} }
8
- let(:config) { {} }
9
- let(:app) do
10
- proc do |_|
11
- [status, headers, body]
12
- end
13
- end
14
- let(:html) do
15
- <<-END
16
- <html>
17
- <head>
18
- <link rel="stylesheet" href="url" type="text/css" media="screen" />
19
- <script type="text/javascript" src="foo"></script>
20
- </head>
21
- <body>
22
- <h1>Testing the middleware</h1>
23
- </body>
24
- </html>
25
- END
26
- end
27
- let(:minified_html) do
28
- <<-END
29
- <html><head><link rel="stylesheet" href="url" type="text/css" media="screen" /><script type="text/javascript" src="foo"></script></head><body><h1>Testing the middleware</h1></body></html>
30
- END
31
- end
32
- let(:meta_charset_html) do
33
- <<-END
34
- <html>
35
- <head>
36
- <meta charset="UTF-8"/>
37
- <link rel="stylesheet" href="url" type="text/css" media="screen" />
38
- <script type="text/javascript" src="foo"></script>
39
- </head>
40
- <body>
41
- <h1>Testing the middleware</h1>
42
- </body>
43
- </html>
44
- END
45
- end
46
- let(:meta_content_html) do
47
- <<-END
48
- <html>
49
- <head>
50
- <meta content="origin" id="mref" name="referrer">
51
- <link rel="stylesheet" href="url" type="text/css" media="screen" />
52
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
53
- <script type="text/javascript" src="foo"></script>
54
- </head>
55
- <body>
56
- <h1>Testing the middleware</h1>
57
- </body>
58
- </html>
59
- END
60
- end
61
- let(:snippet) { 'THIS IS THE SNIPPET' }
62
- let(:content_type) { 'text/html' }
63
-
64
- before do
65
- reconfigure_notifier
66
- allow(subject).to receive(:js_snippet).and_return(snippet)
67
- end
68
-
69
- shared_examples "doesn't add the snippet or config", :add_js => false do
70
- it "doesn't add the snippet or config" do
71
- res_status, res_headers, response = subject.call(env)
72
- new_body = response.join
73
-
74
- expect(new_body).not_to include(snippet)
75
- expect(new_body).not_to include(config[:options].to_json)
76
- expect(new_body).to be_eql(body.join)
77
- expect(res_status).to be_eql(status)
78
- expect(res_headers['Content-Type']).to be_eql(content_type)
79
- end
80
- end
81
-
82
- describe '#call' do
83
- context 'with enabled config' do
84
- let(:config) do
85
- {
86
- :enabled => true,
87
- :options => { :foo => :bar }
88
- }
89
- end
90
-
91
- context 'having a html 200 response' do
92
- let(:body) { [html] }
93
- let(:status) { 200 }
94
- let(:headers) do
95
- { 'Content-Type' => content_type }
96
- end
97
-
98
- it 'adds the config and the snippet to the response' do
99
- res_status, res_headers, response = subject.call(env)
100
- new_body = response.body.join
101
-
102
- expect(new_body).to_not include('>>')
103
- expect(new_body).to include(snippet)
104
- expect(new_body).to include(config[:options].to_json)
105
- expect(res_status).to be_eql(status)
106
- expect(res_headers['Content-Type']).to be_eql(content_type)
107
- end
108
- end
109
-
110
- context 'having a html 200 response with minified body' do
111
- let(:body) { [minified_html] }
112
- let(:status) { 200 }
113
- let(:headers) do
114
- { 'Content-Type' => content_type }
115
- end
116
-
117
- it 'adds the config and the snippet to the response' do
118
- res_status, res_headers, response = subject.call(env)
119
- new_body = response.body.join
120
-
121
- expect(new_body).to_not include('>>')
122
- expect(new_body).to include(snippet)
123
- expect(new_body).to include(config[:options].to_json)
124
- expect(res_status).to be_eql(status)
125
- expect(res_headers['Content-Type']).to be_eql(content_type)
126
- end
127
- end
128
-
129
- context 'having a html 200 resposne with meta charset tag' do
130
- let(:body) { [meta_charset_html] }
131
- let(:status) { 200 }
132
- let(:headers) do
133
- { 'Content-Type' => content_type }
134
- end
135
- it 'adds the config and the snippet to the response' do
136
- res_status, res_headers, response = subject.call(env)
137
- new_body = response.body.join
138
-
139
- expect(new_body).to_not include('>>')
140
- expect(new_body).to include(snippet)
141
- expect(new_body).to include(config[:options].to_json)
142
- expect(res_status).to be_eql(status)
143
- expect(res_headers['Content-Type']).to be_eql(content_type)
144
- meta_tag = '<meta charset="UTF-8"/>'
145
- expect(new_body.index(snippet)).to be > new_body.index(meta_tag)
146
- end
147
- end
148
-
149
- context 'having a html 200 resposne with meta content-type tag' do
150
- let(:body) { [meta_content_html] }
151
- let(:status) { 200 }
152
- let(:headers) do
153
- { 'Content-Type' => content_type }
154
- end
155
- it 'adds the config and the snippet to the response' do
156
- res_status, res_headers, response = subject.call(env)
157
- new_body = response.body.join
158
-
159
- expect(new_body).to_not include('>>')
160
- expect(new_body).to include(snippet)
161
- expect(new_body).to include(config[:options].to_json)
162
- expect(res_status).to be_eql(status)
163
- expect(res_headers['Content-Type']).to be_eql(content_type)
164
- meta_tag = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>'
165
- expect(new_body.index(snippet)).to be > new_body.index(meta_tag)
166
- end
167
- end
168
-
169
- context 'having a html 200 response and SecureHeaders >= 3.0.0 defined' do
170
- let(:body) { [html] }
171
- let(:status) { 200 }
172
- let(:headers) do
173
- { 'Content-Type' => content_type }
174
- end
175
-
176
- before do
177
- Object.const_set('SecureHeaders', Module.new)
178
- SecureHeaders.const_set('VERSION', '3.0.0')
179
- SecureHeaders.const_set('Configuration', Module.new {
180
- def self.get
181
- end
182
- })
183
- allow(SecureHeaders).to receive(:content_security_policy_script_nonce) { 'lorem-ipsum-nonce' }
184
- end
185
-
186
- after do
187
- Object.send(:remove_const, 'SecureHeaders')
188
- end
189
-
190
- it 'renders the snippet and config in the response with nonce in script tag when SecureHeaders installed' do
191
- secure_headers_config = double(:configuration, :current_csp => {}, :csp => double(:opt_out? => false))
192
- allow(SecureHeaders::Configuration).to receive(:get).and_return(secure_headers_config)
193
- res_status, res_headers, response = subject.call(env)
194
-
195
- new_body = response.body.join
196
-
197
- expect(new_body).to include('<script type="text/javascript" nonce="lorem-ipsum-nonce">')
198
- expect(new_body).to include("var _rollbarConfig = #{config[:options].to_json};")
199
- expect(new_body).to include(snippet)
200
- end
201
-
202
- it 'renders the snippet in the response without nonce if SecureHeaders script_src includes \'unsafe-inline\'' do
203
- secure_headers_config = double(:configuration,
204
- :current_csp => {
205
- :script_src => %w('unsafe-inline')
206
- },
207
- :csp => double(:opt_out? => false))
208
- allow(SecureHeaders::Configuration).to receive(:get).and_return(secure_headers_config)
209
-
210
- res_status, res_headers, response = subject.call(env)
211
- new_body = response.body.join
212
-
213
- expect(new_body).to include('<script type="text/javascript">')
214
- expect(new_body).to include("var _rollbarConfig = #{config[:options].to_json};")
215
- expect(new_body).to include(snippet)
216
-
217
- SecureHeaders.send(:remove_const, 'Configuration')
218
- end
219
-
220
- it 'renders the snippet in the response without nonce if SecureHeaders CSP is OptOut' do
221
- secure_headers_config = double(:configuration, :csp => double(:opt_out? => true))
222
- allow(SecureHeaders::Configuration).to receive(:get).and_return(secure_headers_config)
223
-
224
- res_status, res_headers, response = subject.call(env)
225
- new_body = response.body.join
226
-
227
- expect(new_body).to include('<script type="text/javascript">')
228
- expect(new_body).to include("var _rollbarConfig = #{config[:options].to_json};")
229
- expect(new_body).to include(snippet)
230
-
231
- SecureHeaders.send(:remove_const, 'Configuration')
232
- end
233
- end
234
-
235
- context 'having a html 200 response and SecureHeaders < 3.0.0 defined' do
236
- let(:body) { [html] }
237
- let(:status) { 200 }
238
- let(:headers) do
239
- { 'Content-Type' => content_type }
240
- end
241
-
242
- before do
243
- Object.const_set('SecureHeaders', Module.new)
244
- SecureHeaders.const_set('VERSION', '2.4.0')
245
- end
246
-
247
- after do
248
- Object.send(:remove_const, 'SecureHeaders')
249
- end
250
-
251
- it 'renders the snippet and config in the response without nonce in script tag when too old SecureHeaders installed' do
252
- res_status, res_headers, response = subject.call(env)
253
- new_body = response.body.join
254
-
255
- expect(new_body).to include('<script type="text/javascript">')
256
- expect(new_body).to include("var _rollbarConfig = #{config[:options].to_json};")
257
- expect(new_body).to include(snippet)
258
- end
259
- end
260
-
261
- context 'having a html 200 response without head', :add_js => false do
262
- let(:body) { ['foobar'] }
263
- let(:status) { 200 }
264
- let(:headers) do
265
- { 'Content-Type' => content_type }
266
- end
267
- end
268
-
269
- context 'having a html 200 response without head but with an header tag', :add_js => false do
270
- let(:body) { ['<header>foobar</header>'] }
271
- let(:status) { 200 }
272
- let(:headers) do
273
- { 'Content-Type' => content_type }
274
- end
275
- end
276
-
277
- context 'having a html 302 response', :add_js => false do
278
- let(:body) { ['foobar'] }
279
- let(:status) { 302 }
280
- let(:headers) do
281
- { 'Content-Type' => content_type }
282
- end
283
- end
284
-
285
- context 'having the js already injected key in env', :add_js => false do
286
- let(:body) { ['foobar'] }
287
- let(:status) { 200 }
288
- let(:headers) do
289
- { 'Content-Type' => content_type }
290
- end
291
- let(:env) do
292
- { described_class::JS_IS_INJECTED_KEY => true }
293
- end
294
- end
295
-
296
- context 'having an attachment', :add_js => false do
297
- let(:content_type) { 'text/plain' }
298
- let(:body) { ['foobar'] }
299
- let(:status) { 200 }
300
- let(:headers) do
301
- { 'Content-Disposition' => 'attachment',
302
- 'Content-Type' => content_type
303
- }
304
- end
305
- end
306
-
307
- context 'with an exception raised while adding the js', :add_js => false do
308
- let(:body) { [html] }
309
- let(:status) { 200 }
310
- let(:headers) do
311
- { 'Content-Type' => content_type }
312
- end
313
-
314
- before do
315
- allow(subject).to receive(:add_js).and_raise(StandardError.new)
316
- end
317
- end
318
-
319
- context 'with person data' do
320
- let(:body) { [html] }
321
- let(:status) { 200 }
322
- let(:headers) do
323
- { 'Content-Type' => content_type }
324
- end
325
- let(:config) do
326
- {
327
- :enabled => true,
328
- :options => { :foo => :bar, :payload => { :a => 42 } }
329
- }
330
- end
331
- let(:env) do
332
- {
333
- 'rollbar.person_data' => {
334
- :id => 100,
335
- :username => 'foo',
336
- :email => 'foo@bar.com'
337
- }
338
- }
339
- end
340
- let(:expected_js_options) do
341
- {
342
- :foo => :bar,
343
- :payload => {
344
- :a => 42,
345
- :person => {
346
- :id => 100,
347
- :username => 'foo',
348
- :email => 'foo@bar.com'
349
- }
350
- }
351
- }
352
- end
353
-
354
- it 'adds the person data to the configuration' do
355
- _, _, response = subject.call(env)
356
- new_body = response.body.join
357
-
358
- expect(new_body).to include(expected_js_options.to_json)
359
- end
360
-
361
- context 'when the person data is nil' do
362
- let(:env) do
363
- {
364
- 'rollbar.person_data' => nil
365
- }
366
- end
367
-
368
- it 'works correctly and doesnt add anything about person data' do
369
- _, _, response = subject.call(env)
370
- new_body = response.body.join
371
-
372
- expect(new_body).not_to include('person')
373
- end
374
-
375
- it 'doesnt include old data when called a second time' do
376
- _, _, _ = subject.call({
377
- 'rollbar.person_data' => {
378
- :id => 100,
379
- :username => 'foo',
380
- :email => 'foo@bar.com'
381
- }
382
- })
383
- _, _, response = subject.call(env)
384
- new_body = response.body.join
385
-
386
- expect(new_body).not_to include('person')
387
- end
388
- end
389
- end
390
- end
391
-
392
- context 'having the config disabled', :add_js => false do
393
- let(:body) { ['foobar'] }
394
- let(:status) { 302 }
395
- let(:headers) do
396
- { 'Content-Type' => content_type }
397
- end
398
- let(:config) do
399
- {
400
- :enabled => false,
401
- :options => { :foo => :bar }
402
- }
403
- end
404
- end
405
-
406
- context 'if the app raises' do
407
- let(:exception) { StandardError.new }
408
- let(:app) do
409
- proc do |_|
410
- raise exception
411
- end
412
- end
413
-
414
- it 'propagates the exception' do
415
- expect do
416
- app.call(env)
417
- end.to raise_exception(exception)
418
- end
419
- end
420
- end
421
- end