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,171 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'sidekiq' unless RUBY_VERSION == '1.8.7'
4
-
5
- Rollbar.plugins.load!
6
-
7
- describe Rollbar::Sidekiq, :reconfigure_notifier => false do
8
- describe '.handle_exception' do
9
- let(:exception) { StandardError.new('oh noes') }
10
- let(:rollbar) { double }
11
-
12
- let(:job_hash) do
13
- {
14
- 'class' => 'FooWorker',
15
- 'args' => %w(foo bar),
16
- 'queue' => 'default',
17
- 'jid' => '96aa59723946616dff537e97',
18
- 'enqueued_at' => Time.now.to_f,
19
- 'error_message' => exception.message,
20
- 'error_class' => exception.class,
21
- 'created_at' => Time.now.to_f,
22
- 'failed_at' => Time.now.to_f,
23
- 'retry' => 3,
24
- 'retry_count' => 0
25
- }
26
- end
27
-
28
- let(:ctx_hash) do
29
- { :context => 'Job raised exception', :job => job_hash }
30
- end
31
-
32
- let(:expected_scope) do
33
- {
34
- :request => {
35
- :params => job_hash.reject { |k| described_class::PARAM_BLACKLIST.include?(k) }
36
- },
37
- :framework => "Sidekiq: #{Sidekiq::VERSION}",
38
- :context => job_hash['class'],
39
- :queue => job_hash['queue']
40
- }
41
- end
42
-
43
- it 'constructs scope from ctx hash' do
44
- allow(rollbar).to receive(:error)
45
- expect(Rollbar).to receive(:scope).with(expected_scope) { rollbar }
46
-
47
- described_class.handle_exception(ctx_hash, exception)
48
- end
49
-
50
- context 'sidekiq < 4.2.3 ctx hash' do
51
- let(:ctx_hash) { job_hash }
52
-
53
- it 'constructs scope from ctx hash' do
54
- allow(rollbar).to receive(:error)
55
- expect(Rollbar).to receive(:scope).with(expected_scope) { rollbar }
56
-
57
- described_class.handle_exception(ctx_hash, exception)
58
- end
59
- end
60
-
61
- context 'sidekiq < 4.0.0 nil ctx hash from Launcher#actor_died' do
62
- let(:ctx_hash) { nil }
63
-
64
- it 'constructs scope from ctx hash' do
65
- allow(rollbar).to receive(:error)
66
- expect(Rollbar).to receive(:scope).with(
67
- :framework => "Sidekiq: #{Sidekiq::VERSION}"
68
- ) { rollbar }
69
-
70
- described_class.handle_exception(ctx_hash, exception)
71
- end
72
- end
73
-
74
- it 'sends the passed-in error to rollbar' do
75
- allow(Rollbar).to receive(:scope).and_return(rollbar)
76
- expect(rollbar).to receive(:error).with(exception, :use_exception_level_filters => true)
77
-
78
- described_class.handle_exception(ctx_hash, exception)
79
- end
80
-
81
- context 'with fields in job hash to be scrubbed' do
82
- let(:ctx_hash) do
83
- {
84
- :context => 'Job raised exception',
85
- :job => job_hash.merge(
86
- 'foo' => 'bar',
87
- 'secret' => 'foo',
88
- 'password' => 'foo',
89
- 'password_confirmation' => 'foo'
90
- )
91
- }
92
- end
93
-
94
- before { reconfigure_notifier }
95
-
96
- it 'sends a report with the scrubbed fields' do
97
- described_class.handle_exception(ctx_hash, exception)
98
-
99
- expect(Rollbar.last_report[:request][:params]).to be_eql_hash_with_regexes(
100
- 'foo' => 'bar',
101
- 'secret' => /\*+/,
102
- 'password' => /\*+/,
103
- 'password_confirmation' => /\*+/
104
- )
105
- end
106
- end
107
-
108
- context 'with a sidekiq_threshold set' do
109
- before do
110
- Rollbar.configuration.sidekiq_threshold = 2
111
- end
112
-
113
- it 'does not send error to rollbar under the threshold' do
114
- allow(Rollbar).to receive(:scope).and_return(rollbar)
115
- expect(rollbar).to receive(:error).never
116
-
117
- described_class.handle_exception(
118
- { :job => { 'retry' => true, 'retry_count' => 1 } },
119
- exception
120
- )
121
- end
122
-
123
- it 'sends the error to rollbar above the threshold' do
124
- allow(Rollbar).to receive(:scope).and_return(rollbar)
125
- expect(rollbar).to receive(:error)
126
-
127
- described_class.handle_exception(
128
- { :job => { 'retry' => true, 'retry_count' => 2 } },
129
- exception
130
- )
131
- end
132
-
133
- it 'sends the error to rollbar if not retry' do
134
- allow(Rollbar).to receive(:scope).and_return(rollbar)
135
- expect(rollbar).to receive(:error)
136
-
137
- described_class.handle_exception(
138
- { :job => { 'retry' => false } },
139
- exception
140
- )
141
- end
142
-
143
- it 'does not blow up and sends the error to rollbar if retry is true but there is no retry count' do
144
- allow(Rollbar).to receive(:scope).and_return(rollbar)
145
- expect(rollbar).to receive(:error)
146
-
147
- expect do
148
- described_class.handle_exception(
149
- { :job => { 'retry' => true } },
150
- exception
151
- )
152
- end.to_not raise_error
153
- end
154
- end
155
- end
156
-
157
- describe '#call' do
158
- let(:msg) { ['hello'] }
159
- let(:exception) { StandardError.new('oh noes') }
160
- let(:middleware_block) { proc { raise exception } }
161
-
162
- subject { Rollbar::Sidekiq.new }
163
-
164
- it 'sends the error to Rollbar::Sidekiq.handle_exception' do
165
- expect(Rollbar).to receive(:reset_notifier!)
166
- expect(Rollbar::Sidekiq).to receive(:handle_exception).with(msg, exception)
167
-
168
- expect { subject.call(nil, msg, nil, &middleware_block) }.to raise_error(exception)
169
- end
170
- end
171
- end unless RUBY_VERSION == '1.8.7'
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
- require 'rollbar'
3
-
4
- Rollbar.plugins.load!
5
-
6
- describe Rollbar::ActiveRecordExtension do
7
- it 'has the extensions loaded into ActiveRecord::Base' do
8
- expect(ActiveModel::Validations.ancestors).to include(described_class)
9
- expect(ActiveModel::Validations.instance_methods.map(&:to_sym)).to include(:report_validation_errors_to_rollbar)
10
- end
11
-
12
- context 'with an ActiveRecord::Base instance' do
13
- let(:user) { User.new }
14
-
15
- it 'calls report_validation_errors_to_rollbar' do
16
- expect(user).to receive(:report_validation_errors_to_rollbar)
17
-
18
- user.valid?
19
- end
20
-
21
- context 'using Rails 5.0' do
22
- next unless Gem::Version.new(Rails.version) >= Gem::Version.new('5.0')
23
-
24
- context 'with belongs_to' do
25
- let(:book) { Book.new }
26
-
27
- it 'report validations error' do
28
- expect(book).to receive(:report_validation_errors_to_rollbar)
29
- book.valid?
30
- end
31
- end
32
- end
33
- end
34
-
35
- context 'with class using ActiveModel::Validations' do
36
- let(:post) { Post.new }
37
-
38
- it 'calls report_validation_errors_to_rollbar' do
39
- expect(post).to receive(:report_validation_errors_to_rollbar)
40
-
41
- post.valid?
42
- end
43
- end
44
-
45
- describe '#report_validation_errors_to_rollbar', :reconfigure_notifier => true do
46
- context 'having validation errors' do
47
- let(:user) { User.new }
48
-
49
- it 'send the errors to Rollbar' do
50
- expect(Rollbar).to receive(:warning)
51
-
52
- user.valid?
53
- end
54
- end
55
- end
56
- end
@@ -1,68 +0,0 @@
1
- require 'spec_helper'
2
- require 'rollbar/plugins'
3
- require 'rollbar/plugin'
4
-
5
- describe Rollbar::Plugins do
6
- let(:plugin_files_path) do
7
- File.expand_path('../../fixtures/plugins/**/*.rb', __FILE__)
8
- end
9
- let!(:current_plugins) do
10
- Rollbar.plugins
11
- end
12
-
13
- let(:plugin1_proc) do
14
- proc do
15
- dependency { true }
16
- end
17
- end
18
-
19
- before do
20
- Rollbar.plugins = nil
21
- allow_any_instance_of(described_class).to receive(:plugin_files).and_return(plugin_files_path)
22
- end
23
-
24
- after do
25
- Rollbar.plugins = current_plugins
26
- end
27
-
28
- describe '#require_all' do
29
- it 'loads the plugins' do
30
- expect(Rollbar.plugins).to receive(:define).with(:dummy1)
31
- expect(Rollbar.plugins).to receive(:define).with(:dummy2)
32
-
33
- subject.require_all
34
- end
35
- end
36
-
37
- describe '#define' do
38
- it 'evals the plugin DSL and adds it to the collection' do
39
- expect_any_instance_of(Rollbar::Plugin).to receive(:dependency)
40
- expect do
41
- subject.define(:name, &plugin1_proc)
42
- end.to change(subject.collection, :size).by(1)
43
- end
44
-
45
- context 'with a plugin already defined' do
46
- it 'doesnt load the plugin twice' do
47
- subject.define(:name, &plugin1_proc)
48
-
49
- expect_any_instance_of(Rollbar::Plugin).not_to receive(:instance_eval)
50
- expect do
51
- subject.define(:name, &plugin1_proc)
52
- end.to change(subject.collection, :size).by(0)
53
- end
54
- end
55
- end
56
-
57
- describe '#load!' do
58
- before do
59
- subject.define(:plugin1, &plugin1_proc)
60
- end
61
-
62
- it 'calls load! in the plugins' do
63
- expect_any_instance_of(Rollbar::Plugin).to receive(:load!).once
64
-
65
- subject.load!
66
- end
67
- end
68
- end
@@ -1,270 +0,0 @@
1
- require 'spec_helper'
2
- require 'rack/mock'
3
-
4
- require 'rollbar/request_data_extractor'
5
-
6
- class ExtractorDummy
7
- include Rollbar::RequestDataExtractor
8
- end
9
-
10
- describe Rollbar::RequestDataExtractor do
11
- subject { ExtractorDummy.new }
12
-
13
- let(:env) do
14
- Rack::MockRequest.env_for('/', 'HTTP_HOST' => 'localhost:81', 'HTTP_X_FORWARDED_HOST' => 'example.org:9292')
15
- end
16
-
17
- describe '#scrub_url' do
18
- let(:url) { 'http://this-is-the-url.com/foobar?param1=value1' }
19
- let(:sensitive_params) { [:param1, :param2] }
20
- let(:scrub_fields) { [:password, :secret] }
21
-
22
- before do
23
- allow(Rollbar.configuration).to receive(:scrub_fields).and_return(scrub_fields)
24
- allow(Rollbar.configuration).to receive(:scrub_user).and_return(true)
25
- allow(Rollbar.configuration).to receive(:scrub_password).and_return(true)
26
- allow(Rollbar.configuration).to receive(:randomize_secret_length).and_return(true)
27
- end
28
-
29
- it 'calls the scrubber with the correct options' do
30
- expected_options = {
31
- :url => url,
32
- :scrub_fields => [:password, :secret, :param1, :param2],
33
- :scrub_user => true,
34
- :scrub_password => true,
35
- :randomize_scrub_length => true
36
- }
37
-
38
- expect(Rollbar::Scrubbers::URL).to receive(:call).with(expected_options)
39
-
40
- subject.scrub_url(url, sensitive_params)
41
- end
42
- end
43
-
44
- describe '#scrub_params' do
45
- let(:params) do
46
- {
47
- :param1 => 'value1',
48
- :param2 => 'value2'
49
- }
50
- end
51
- let(:sensitive_params) { [:param1, :param2] }
52
- let(:scrub_fields) { [:password, :secret] }
53
-
54
- before do
55
- allow(Rollbar.configuration).to receive(:scrub_fields).and_return(scrub_fields)
56
- end
57
-
58
- it 'calls the scrubber with the correct options' do
59
- expected_options = {
60
- :params => params,
61
- :config => scrub_fields,
62
- :extra_fields => sensitive_params
63
- }
64
-
65
- expect(Rollbar::Scrubbers::Params).to receive(:call).with(expected_options)
66
-
67
- subject.scrub_params(params, sensitive_params)
68
- end
69
- end
70
-
71
- describe '#extract_request_data_from_rack' do
72
- it 'returns a Hash object' do
73
- expect(Rollbar::Scrubbers::URL).to receive(:call).with(kind_of(Hash)).and_call_original
74
- expect(Rollbar::Scrubbers::Params).to receive(:call).with(kind_of(Hash)).and_call_original.exactly(6)
75
-
76
- result = subject.extract_request_data_from_rack(env)
77
-
78
- expect(result).to be_kind_of(Hash)
79
- end
80
-
81
- context 'with invalid utf8 sequence in key', :if => RUBY_VERSION != '1.8.7' do
82
- let(:data) do
83
- File.read(File.expand_path('../../support/encodings/iso_8859_9', __FILE__)).force_encoding(Encoding::ISO_8859_9)
84
- end
85
- let(:env) do
86
- env = Rack::MockRequest.env_for('/',
87
- 'HTTP_HOST' => 'localhost:81',
88
- 'HTTP_X_FORWARDED_HOST' => 'example.org:9292',
89
- 'CONTENT_TYPE' => 'application/json')
90
-
91
- env['rack.session'] = { data => 'foo' }
92
- env
93
- end
94
-
95
- it 'doesnt crash' do
96
- result = subject.extract_request_data_from_rack(env)
97
-
98
- expect(result).to be_kind_of(Hash)
99
- end
100
-
101
- context 'with CONTENT_TYPE and CONTENT_LENGTH headers' do
102
- let(:env) do
103
- Rack::MockRequest.env_for('/',
104
- 'HTTP_HOST' => 'localhost:81',
105
- 'HTTP_X_FORWARDED_HOST' => 'example.org:9292',
106
- 'CONTENT_TYPE' => 'application/json',
107
- 'CONTENT_LENGTH' => 20)
108
-
109
-
110
- end
111
-
112
- it 'adds the content type header to the headers key' do
113
- result = subject.extract_request_data_from_rack(env)
114
-
115
- expect(result[:headers]['Content-Type']).to be_eql('application/json')
116
- expect(result[:headers]['Content-Length']).to be_eql(20)
117
- end
118
- end
119
- end
120
-
121
- context 'with multiple addresses in X-Forwarded-For' do
122
- let(:env) do
123
- Rack::MockRequest.env_for('/',
124
- 'HTTP_HOST' => 'localhost:81',
125
- 'HTTP_X_FORWARDED_FOR' => header_value,
126
- 'REMOTE_ADDR' => '3.3.3.3',
127
- 'CONTENT_TYPE' => 'application/json',
128
- 'CONTENT_LENGTH' => 20)
129
-
130
-
131
- end
132
-
133
- context 'with public client IP' do
134
- let(:header_value) { '2.2.2.2, 3.3.3.3' }
135
-
136
- it 'extracts the correct user IP' do
137
- result = subject.extract_request_data_from_rack(env)
138
-
139
- expect(result[:user_ip]).to be_eql('2.2.2.2')
140
- end
141
-
142
- context 'with collect_user_ip configuration option disabled' do
143
- before do
144
- Rollbar.configuration.collect_user_ip = false
145
- end
146
-
147
- it 'does not extract user\'s IP' do
148
- result = subject.extract_request_data_from_rack(env)
149
-
150
- expect(result[:user_ip]).to be_nil
151
- end
152
-
153
- it 'does not extract user\'s IP on X-Forwarded-For header' do
154
- result = subject.extract_request_data_from_rack(env)
155
-
156
- expect(result[:headers]['X-Forwarded-For']).to be_nil
157
- end
158
- end
159
-
160
- context 'with anonymize_user_ip configuration option enabled' do
161
- before do
162
- Rollbar.configuration.anonymize_user_ip = true
163
- end
164
-
165
- it 'it anonymizes the IPv4 address' do
166
- result = subject.extract_request_data_from_rack(env)
167
-
168
- expect(result[:user_ip]).to be_eql('2.2.2.0')
169
- end
170
- end
171
- end
172
-
173
- context 'with private first client IP' do
174
- let(:header_value) { '192.168.1.1, 2.2.2.2, 3.3.3.3' }
175
-
176
- it 'extracts the correct user IP' do
177
- result = subject.extract_request_data_from_rack(env)
178
-
179
- expect(result[:user_ip]).to be_eql('2.2.2.2')
180
- end
181
- end
182
- end
183
-
184
- context 'with JSON POST body' do
185
- let(:params) { { 'key' => 'value' } }
186
- let(:body) { params.to_json }
187
- let(:env) do
188
- Rack::MockRequest.env_for('/?foo=bar',
189
- 'CONTENT_TYPE' => 'application/json',
190
- :input => body,
191
- :method => 'POST')
192
-
193
-
194
- end
195
-
196
- it 'extracts the correct user IP' do
197
- result = subject.extract_request_data_from_rack(env)
198
- expect(result[:body]).to be_eql(body)
199
- end
200
- end
201
-
202
- context 'with JSON DELETE body' do
203
- let(:params) { { 'key' => 'value' } }
204
- let(:body) { params.to_json }
205
- let(:env) do
206
- Rack::MockRequest.env_for('/?foo=bar',
207
- 'CONTENT_TYPE' => 'application/json',
208
- :input => body,
209
- :method => 'DELETE')
210
-
211
-
212
- end
213
-
214
- it 'extracts the correct user IP' do
215
- result = subject.extract_request_data_from_rack(env)
216
- expect(result[:body]).to be_eql(body)
217
- end
218
- end
219
-
220
- context 'with JSON PUT body' do
221
- let(:params) { { 'key' => 'value' } }
222
- let(:body) { params.to_json }
223
- let(:env) do
224
- Rack::MockRequest.env_for('/?foo=bar',
225
- 'CONTENT_TYPE' => 'application/json',
226
- :input => body,
227
- :method => 'PUT')
228
-
229
-
230
- end
231
-
232
- it 'extracts the correct user IP' do
233
- result = subject.extract_request_data_from_rack(env)
234
- expect(result[:body]).to be_eql(body)
235
- end
236
- end
237
-
238
- context 'with POST params' do
239
- let(:params) { { 'key' => 'value' } }
240
- let(:env) do
241
- Rack::MockRequest.env_for('/?foo=bar',
242
- :params => params,
243
- :method => 'POST')
244
-
245
-
246
- end
247
-
248
- it 'extracts the correct user IP' do
249
- result = subject.extract_request_data_from_rack(env)
250
- expect(result[:POST]).to be_eql(params)
251
- end
252
- end
253
-
254
- context 'with GET params' do
255
- let(:params) { { 'key' => 'value' } }
256
- let(:env) do
257
- Rack::MockRequest.env_for('/?foo=bar',
258
- :params => params,
259
- :method => 'GET')
260
-
261
-
262
- end
263
-
264
- it 'extracts the correct user IP' do
265
- result = subject.extract_request_data_from_rack(env)
266
- expect(result[:GET]).to be_eql(params)
267
- end
268
- end
269
- end
270
- end