rollbar 2.18.2 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -0
  3. data/.travis.yml +155 -93
  4. data/Gemfile +19 -13
  5. data/README.md +12 -0
  6. data/gemfiles/rails30.gemfile +17 -10
  7. data/gemfiles/rails31.gemfile +20 -12
  8. data/gemfiles/rails32.gemfile +16 -7
  9. data/gemfiles/rails40.gemfile +16 -5
  10. data/gemfiles/rails41.gemfile +15 -5
  11. data/gemfiles/rails42.gemfile +25 -14
  12. data/gemfiles/rails50.gemfile +15 -8
  13. data/gemfiles/rails51.gemfile +15 -8
  14. data/gemfiles/rails52.gemfile +62 -0
  15. data/gemfiles/ruby_1_8_and_1_9_2.gemfile +2 -2
  16. data/lib/rails/rollbar_runner.rb +16 -1
  17. data/lib/rollbar/capistrano.rb +71 -39
  18. data/lib/rollbar/capistrano3.rb +53 -1
  19. data/lib/rollbar/capistrano_tasks.rb +131 -0
  20. data/lib/rollbar/configuration.rb +13 -4
  21. data/lib/rollbar/delay/active_job.rb +17 -0
  22. data/lib/rollbar/delay/sidekiq.rb +3 -1
  23. data/lib/rollbar/delay/thread.rb +1 -1
  24. data/lib/rollbar/deploy.rb +69 -0
  25. data/lib/rollbar/item.rb +17 -6
  26. data/lib/rollbar/middleware/js.rb +25 -3
  27. data/lib/rollbar/middleware/js/json_value.rb +26 -0
  28. data/lib/rollbar/notifier.rb +32 -13
  29. data/lib/rollbar/plugins/active_job.rb +3 -0
  30. data/lib/rollbar/plugins/rails/controller_methods.rb +2 -1
  31. data/lib/rollbar/plugins/rails/railtie_mixin.rb +7 -1
  32. data/lib/rollbar/rake_tasks.rb +126 -67
  33. data/lib/rollbar/scrubbers/params.rb +6 -0
  34. data/lib/rollbar/util.rb +75 -45
  35. data/lib/rollbar/util/hash.rb +15 -6
  36. data/lib/rollbar/version.rb +1 -1
  37. data/rollbar.gemspec +2 -3
  38. metadata +9 -261
  39. data/lib/rollbar/tasks/rollbar.cap +0 -47
  40. data/spec/cacert.pem +0 -3988
  41. data/spec/controllers/home_controller_spec.rb +0 -480
  42. data/spec/delay/sidekiq_spec.rb +0 -61
  43. data/spec/delay/sucker_punch_spec.rb +0 -25
  44. data/spec/delayed/backend/test.rb +0 -140
  45. data/spec/delayed/serialization/test.rb +0 -0
  46. data/spec/dummyapp/.gitignore +0 -73
  47. data/spec/dummyapp/Rakefile +0 -7
  48. data/spec/dummyapp/app/assets/javascripts/application.js +0 -3
  49. data/spec/dummyapp/app/assets/stylesheets/application.css.scss +0 -37
  50. data/spec/dummyapp/app/controllers/application_controller.rb +0 -3
  51. data/spec/dummyapp/app/controllers/home_controller.rb +0 -60
  52. data/spec/dummyapp/app/controllers/users_controller.rb +0 -17
  53. data/spec/dummyapp/app/helpers/.gitkeep +0 -0
  54. data/spec/dummyapp/app/mailers/.gitkeep +0 -0
  55. data/spec/dummyapp/app/models/.gitkeep +0 -0
  56. data/spec/dummyapp/app/models/book.rb +0 -5
  57. data/spec/dummyapp/app/models/post.rb +0 -9
  58. data/spec/dummyapp/app/models/user.rb +0 -9
  59. data/spec/dummyapp/app/views/devise/registrations/edit.html.erb +0 -27
  60. data/spec/dummyapp/app/views/devise/registrations/new.html.erb +0 -20
  61. data/spec/dummyapp/app/views/devise/shared/_links.html.erb +0 -25
  62. data/spec/dummyapp/app/views/home/cause_exception.html.erb +0 -1
  63. data/spec/dummyapp/app/views/home/index.html.erb +0 -4
  64. data/spec/dummyapp/app/views/home/report_exception.html.erb +0 -1
  65. data/spec/dummyapp/app/views/js/test.html.erb +0 -1
  66. data/spec/dummyapp/app/views/layouts/_messages.html.erb +0 -5
  67. data/spec/dummyapp/app/views/layouts/_navigation.html.erb +0 -21
  68. data/spec/dummyapp/app/views/layouts/application.html.erb +0 -25
  69. data/spec/dummyapp/app/views/layouts/simple.html.erb +0 -18
  70. data/spec/dummyapp/app/views/users/index.html.erb +0 -8
  71. data/spec/dummyapp/app/views/users/show.html.erb +0 -3
  72. data/spec/dummyapp/config.ru +0 -4
  73. data/spec/dummyapp/config/application.rb +0 -59
  74. data/spec/dummyapp/config/boot.rb +0 -10
  75. data/spec/dummyapp/config/database.yml +0 -25
  76. data/spec/dummyapp/config/environment.rb +0 -5
  77. data/spec/dummyapp/config/environments/development.rb +0 -37
  78. data/spec/dummyapp/config/environments/production.rb +0 -67
  79. data/spec/dummyapp/config/environments/test.rb +0 -37
  80. data/spec/dummyapp/config/initializers/backtrace_silencers.rb +0 -7
  81. data/spec/dummyapp/config/initializers/inflections.rb +0 -15
  82. data/spec/dummyapp/config/initializers/mime_types.rb +0 -5
  83. data/spec/dummyapp/config/initializers/rollbar.rb +0 -26
  84. data/spec/dummyapp/config/initializers/secret_token.rb +0 -7
  85. data/spec/dummyapp/config/initializers/session_store.rb +0 -8
  86. data/spec/dummyapp/config/initializers/wrap_parameters.rb +0 -16
  87. data/spec/dummyapp/config/locales/devise.en.yml +0 -58
  88. data/spec/dummyapp/config/locales/en.yml +0 -5
  89. data/spec/dummyapp/config/routes.rb +0 -17
  90. data/spec/dummyapp/config/secrets.yml +0 -2
  91. data/spec/dummyapp/db/migrate/20121121184652_devise_create_users.rb +0 -46
  92. data/spec/dummyapp/db/migrate/20121121184654_add_name_to_users.rb +0 -5
  93. data/spec/dummyapp/db/migrate/20161219184410_create_books.rb +0 -10
  94. data/spec/dummyapp/db/migrate/20161219185529_add_username_to_users.rb +0 -5
  95. data/spec/dummyapp/db/schema.rb +0 -41
  96. data/spec/dummyapp/db/seeds.rb +0 -12
  97. data/spec/dummyapp/lib/assets/.gitkeep +0 -0
  98. data/spec/dummyapp/public/404.html +0 -26
  99. data/spec/dummyapp/public/422.html +0 -26
  100. data/spec/dummyapp/public/500.html +0 -25
  101. data/spec/dummyapp/public/favicon.ico +0 -0
  102. data/spec/dummyapp/script/rails +0 -6
  103. data/spec/fixtures/file1 +0 -1
  104. data/spec/fixtures/file2 +0 -1
  105. data/spec/fixtures/payloads/message.json +0 -25
  106. data/spec/fixtures/payloads/sample.trace.json +0 -275
  107. data/spec/fixtures/payloads/sample.trace_chain.json +0 -530
  108. data/spec/fixtures/plugins/dummy1.rb +0 -5
  109. data/spec/fixtures/plugins/dummy2.rb +0 -5
  110. data/spec/generators/rollbar/rollbar_generator_rails30_spec.rb +0 -31
  111. data/spec/generators/rollbar/rollbar_generator_spec.rb +0 -51
  112. data/spec/requests/home_spec.rb +0 -49
  113. data/spec/rollbar/configuration_spec.rb +0 -74
  114. data/spec/rollbar/delay/delayed_job_spec.rb +0 -22
  115. data/spec/rollbar/delay/girl_friday_spec.rb +0 -41
  116. data/spec/rollbar/delay/resque_spec.rb +0 -37
  117. data/spec/rollbar/delay/shoryuken_spec.rb +0 -44
  118. data/spec/rollbar/delay/thread_spec.rb +0 -27
  119. data/spec/rollbar/encoding/encoder_spec.rb +0 -63
  120. data/spec/rollbar/item/backtrace_spec.rb +0 -26
  121. data/spec/rollbar/item/frame_spec.rb +0 -267
  122. data/spec/rollbar/item_spec.rb +0 -736
  123. data/spec/rollbar/json/oj_spec.rb +0 -18
  124. data/spec/rollbar/json_spec.rb +0 -110
  125. data/spec/rollbar/lazy_store_spec.rb +0 -99
  126. data/spec/rollbar/logger_proxy_spec.rb +0 -69
  127. data/spec/rollbar/logger_spec.rb +0 -124
  128. data/spec/rollbar/middleware/js_spec.rb +0 -428
  129. data/spec/rollbar/middleware/sinatra_spec.rb +0 -197
  130. data/spec/rollbar/notifier_spec.rb +0 -67
  131. data/spec/rollbar/plugin_spec.rb +0 -209
  132. data/spec/rollbar/plugins/active_job_spec.rb +0 -45
  133. data/spec/rollbar/plugins/delayed_job/job_data_spec.rb +0 -48
  134. data/spec/rollbar/plugins/delayed_job_spec.rb +0 -129
  135. data/spec/rollbar/plugins/rack_spec.rb +0 -152
  136. data/spec/rollbar/plugins/rails_js_spec.rb +0 -19
  137. data/spec/rollbar/plugins/rake_spec.rb +0 -34
  138. data/spec/rollbar/plugins/resque/failure_spec.rb +0 -36
  139. data/spec/rollbar/plugins/sidekiq_spec.rb +0 -169
  140. data/spec/rollbar/plugins/validations_spec.rb +0 -56
  141. data/spec/rollbar/plugins_spec.rb +0 -68
  142. data/spec/rollbar/request_data_extractor_spec.rb +0 -321
  143. data/spec/rollbar/scrubbers/params_spec.rb +0 -598
  144. data/spec/rollbar/scrubbers/url_spec.rb +0 -240
  145. data/spec/rollbar/scrubbers_spec.rb +0 -31
  146. data/spec/rollbar/sidekig/clear_scope_spec.rb +0 -19
  147. data/spec/rollbar/truncation/frames_strategy_spec.rb +0 -70
  148. data/spec/rollbar/truncation/min_body_strategy_spec.rb +0 -57
  149. data/spec/rollbar/truncation/strings_strategy_spec.rb +0 -89
  150. data/spec/rollbar/truncation_spec.rb +0 -27
  151. data/spec/rollbar/util/hash_spec.rb +0 -22
  152. data/spec/rollbar/util/ip_anonymizer_spec.rb +0 -30
  153. data/spec/rollbar/util_spec.rb +0 -80
  154. data/spec/rollbar_bc_spec.rb +0 -380
  155. data/spec/rollbar_spec.rb +0 -1737
  156. data/spec/spec_helper.rb +0 -84
  157. data/spec/support/cause_exception.rb +0 -1
  158. data/spec/support/encoding_helpers.rb +0 -8
  159. data/spec/support/encodings/iso_8859_9 +0 -1
  160. data/spec/support/fixture_helpers.rb +0 -10
  161. data/spec/support/get_ip_raising.rb +0 -7
  162. data/spec/support/helpers.rb +0 -5
  163. data/spec/support/matchers.rb +0 -23
  164. data/spec/support/notifier_helpers.rb +0 -57
  165. data/spec/support/rollbar_api.rb +0 -57
  166. data/spec/support/secure_headers_mocks.rb +0 -83
  167. data/spec/support/shared_contexts.rb +0 -12
@@ -1,169 +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 = 3
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 doesn't send 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).never
146
-
147
- described_class.handle_exception(
148
- { :job => { 'retry' => true } },
149
- exception
150
- )
151
- end
152
- end
153
- end
154
-
155
- describe '#call' do
156
- let(:msg) { ['hello'] }
157
- let(:exception) { StandardError.new('oh noes') }
158
- let(:middleware_block) { proc { raise exception } }
159
-
160
- subject { Rollbar::Sidekiq.new }
161
-
162
- it 'sends the error to Rollbar::Sidekiq.handle_exception' do
163
- expect(Rollbar).to receive(:reset_notifier!)
164
- expect(Rollbar::Sidekiq).to receive(:handle_exception).with(msg, exception)
165
-
166
- expect { subject.call(nil, msg, nil, &middleware_block) }.to raise_error(exception)
167
- end
168
- end
169
- 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,321 +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
- let(:scrub_whitelist) { false }
22
-
23
- before do
24
- allow(Rollbar.configuration).to receive(:scrub_fields).and_return(scrub_fields)
25
- allow(Rollbar.configuration).to receive(:scrub_user).and_return(true)
26
- allow(Rollbar.configuration).to receive(:scrub_password).and_return(true)
27
- allow(Rollbar.configuration).to receive(:randomize_secret_length).and_return(true)
28
- allow(Rollbar.configuration).to receive(:scrub_whitelist).and_return(false)
29
- end
30
-
31
- it 'calls the scrubber with the correct options' do
32
- expected_options = {
33
- :url => url,
34
- :scrub_fields => [:password, :secret, :param1, :param2],
35
- :scrub_user => true,
36
- :scrub_password => true,
37
- :randomize_scrub_length => true,
38
- :whitelist => false
39
- }
40
-
41
- expect(Rollbar::Scrubbers::URL).to receive(:call).with(expected_options)
42
-
43
- subject.scrub_url(url, sensitive_params)
44
- end
45
- end
46
-
47
- describe '#scrub_params' do
48
- let(:params) do
49
- {
50
- :param1 => 'value1',
51
- :param2 => 'value2'
52
- }
53
- end
54
- let(:sensitive_params) { [:param1, :param2] }
55
- let(:scrub_fields) { [:password, :secret] }
56
- let(:scrub_whitelist) { false }
57
-
58
- before do
59
- allow(Rollbar.configuration).to receive(:scrub_fields).and_return(scrub_fields)
60
- allow(Rollbar.configuration).to receive(:scrub_whitelist).and_return(scrub_whitelist)
61
- end
62
-
63
- it 'calls the scrubber with the correct options' do
64
- expected_options = {
65
- :params => params,
66
- :config => scrub_fields,
67
- :extra_fields => sensitive_params,
68
- :whitelist => scrub_whitelist
69
- }
70
-
71
- expect(Rollbar::Scrubbers::Params).to receive(:call).with(expected_options)
72
-
73
- subject.scrub_params(params, sensitive_params)
74
- end
75
- end
76
-
77
- describe '#extract_request_data_from_rack' do
78
- it 'returns a Hash object' do
79
- expect(Rollbar::Scrubbers::URL).to receive(:call).with(kind_of(Hash)).and_call_original
80
- expect(Rollbar::Scrubbers::Params).to receive(:call).with(kind_of(Hash)).and_call_original.exactly(6)
81
-
82
- result = subject.extract_request_data_from_rack(env)
83
-
84
- expect(result).to be_kind_of(Hash)
85
- end
86
-
87
- context 'with invalid utf8 sequence in key', :if => RUBY_VERSION != '1.8.7' do
88
- let(:data) do
89
- File.read(File.expand_path('../../support/encodings/iso_8859_9', __FILE__)).force_encoding(Encoding::ISO_8859_9)
90
- end
91
- let(:env) do
92
- env = Rack::MockRequest.env_for('/',
93
- 'HTTP_HOST' => 'localhost:81',
94
- 'HTTP_X_FORWARDED_HOST' => 'example.org:9292',
95
- 'CONTENT_TYPE' => 'application/json')
96
-
97
- env['rack.session'] = { data => 'foo' }
98
- env
99
- end
100
-
101
- it 'doesnt crash' do
102
- result = subject.extract_request_data_from_rack(env)
103
-
104
- expect(result).to be_kind_of(Hash)
105
- end
106
-
107
- context 'with CONTENT_TYPE and CONTENT_LENGTH headers' do
108
- let(:env) do
109
- Rack::MockRequest.env_for('/',
110
- 'HTTP_HOST' => 'localhost:81',
111
- 'HTTP_X_FORWARDED_HOST' => 'example.org:9292',
112
- 'CONTENT_TYPE' => 'application/json',
113
- 'CONTENT_LENGTH' => 20)
114
-
115
-
116
- end
117
-
118
- it 'adds the content type header to the headers key' do
119
- result = subject.extract_request_data_from_rack(env)
120
-
121
- expect(result[:headers]['Content-Type']).to be_eql('application/json')
122
- expect(result[:headers]['Content-Length']).to be_eql(20)
123
- end
124
- end
125
- end
126
-
127
- context 'with multiple IP addresses in headers and in user ip' do
128
- let(:env) do
129
- Rack::MockRequest.env_for('/',
130
- 'HTTP_HOST' => 'localhost:81',
131
- 'HTTP_X_FORWARDED_FOR' => x_forwarded_for,
132
- 'HTTP_X_REAL_IP' => x_real_ip,
133
- 'REMOTE_ADDR' => '3.3.3.3',
134
- 'CONTENT_TYPE' => 'application/json',
135
- 'CONTENT_LENGTH' => 20)
136
-
137
-
138
- end
139
-
140
- context 'with public client IP' do
141
- let(:x_forwarded_for) { '2.2.2.2, 3.3.3.3' }
142
- let(:x_real_ip) { '2.2.2.2' }
143
-
144
- it 'extracts the correct user IP' do
145
- result = subject.extract_request_data_from_rack(env)
146
-
147
- expect(result[:user_ip]).to be_eql('2.2.2.2')
148
- end
149
-
150
- it 'extracts the correct X-Forwarded-For' do
151
- result = subject.extract_request_data_from_rack(env)
152
-
153
- expect(result[:headers]['X-Forwarded-For']).to be_eql('2.2.2.2, 3.3.3.3')
154
- end
155
-
156
- it 'extracts the correct X-Real-Ip' do
157
- result = subject.extract_request_data_from_rack(env)
158
-
159
- expect(result[:headers]['X-Real-Ip']).to be_eql('2.2.2.2')
160
- end
161
-
162
- context 'with collect_user_ip configuration option disabled' do
163
- before do
164
- Rollbar.configuration.collect_user_ip = false
165
- end
166
-
167
- it 'does not extract user\'s IP' do
168
- result = subject.extract_request_data_from_rack(env)
169
-
170
- expect(result[:user_ip]).to be_nil
171
- end
172
-
173
- it 'does not extract user\'s IP on X-Forwarded-For header' do
174
- result = subject.extract_request_data_from_rack(env)
175
-
176
- expect(result[:headers]['X-Forwarded-For']).to be_nil
177
- end
178
-
179
- it 'does not extract user\'s IP on X-Real-Ip header' do
180
- result = subject.extract_request_data_from_rack(env)
181
-
182
- expect(result[:headers]['X-Real-Ip']).to be_nil
183
- end
184
- end
185
-
186
- context 'with anonymize_user_ip configuration option enabled' do
187
- before do
188
- Rollbar.configuration.anonymize_user_ip = true
189
- end
190
-
191
- it 'it anonymizes the IPv4 address' do
192
- result = subject.extract_request_data_from_rack(env)
193
-
194
- expect(result[:user_ip]).to be_eql('2.2.2.0')
195
- end
196
-
197
- it 'it anonymizes IP addresses in X-Forwarded-For' do
198
- result = subject.extract_request_data_from_rack(env)
199
-
200
- expect(result[:headers]['X-Forwarded-For']).to be_eql('2.2.2.0, 3.3.3.0')
201
- end
202
-
203
- it 'it anonymizes IP addresses in X-Real-Ip' do
204
- result = subject.extract_request_data_from_rack(env)
205
-
206
- expect(result[:headers]['X-Real-Ip']).to be_eql('2.2.2.0')
207
- end
208
- end
209
- end
210
-
211
- context 'with private first client IP' do
212
- let(:x_forwarded_for) { '192.168.1.1, 2.2.2.2, 3.3.3.3' }
213
- let(:x_real_ip) { '2.2.2.2' }
214
-
215
- it 'extracts the correct user IP' do
216
- result = subject.extract_request_data_from_rack(env)
217
-
218
- expect(result[:user_ip]).to be_eql('2.2.2.2')
219
- end
220
-
221
- it 'extracts the correct X-Forwarded-For' do
222
- result = subject.extract_request_data_from_rack(env)
223
-
224
- expect(result[:headers]['X-Forwarded-For']).to be_eql('192.168.1.1, 2.2.2.2, 3.3.3.3')
225
- end
226
-
227
- it 'extracts the correct X-Real-Ip' do
228
- result = subject.extract_request_data_from_rack(env)
229
-
230
- expect(result[:headers]['X-Real-Ip']).to be_eql('2.2.2.2')
231
- end
232
- end
233
- end
234
-
235
- context 'with JSON POST body' do
236
- let(:params) { { 'key' => 'value' } }
237
- let(:body) { params.to_json }
238
- let(:env) do
239
- Rack::MockRequest.env_for('/?foo=bar',
240
- 'CONTENT_TYPE' => 'application/json',
241
- :input => body,
242
- :method => 'POST')
243
-
244
-
245
- end
246
-
247
- it 'extracts the correct user IP' do
248
- result = subject.extract_request_data_from_rack(env)
249
- expect(result[:body]).to be_eql(body)
250
- end
251
- end
252
-
253
- context 'with JSON DELETE body' do
254
- let(:params) { { 'key' => 'value' } }
255
- let(:body) { params.to_json }
256
- let(:env) do
257
- Rack::MockRequest.env_for('/?foo=bar',
258
- 'CONTENT_TYPE' => 'application/json',
259
- :input => body,
260
- :method => 'DELETE')
261
-
262
-
263
- end
264
-
265
- it 'extracts the correct user IP' do
266
- result = subject.extract_request_data_from_rack(env)
267
- expect(result[:body]).to be_eql(body)
268
- end
269
- end
270
-
271
- context 'with JSON PUT body' do
272
- let(:params) { { 'key' => 'value' } }
273
- let(:body) { params.to_json }
274
- let(:env) do
275
- Rack::MockRequest.env_for('/?foo=bar',
276
- 'CONTENT_TYPE' => 'application/json',
277
- :input => body,
278
- :method => 'PUT')
279
-
280
-
281
- end
282
-
283
- it 'extracts the correct user IP' do
284
- result = subject.extract_request_data_from_rack(env)
285
- expect(result[:body]).to be_eql(body)
286
- end
287
- end
288
-
289
- context 'with POST params' do
290
- let(:params) { { 'key' => 'value' } }
291
- let(:env) do
292
- Rack::MockRequest.env_for('/?foo=bar',
293
- :params => params,
294
- :method => 'POST')
295
-
296
-
297
- end
298
-
299
- it 'extracts the correct user IP' do
300
- result = subject.extract_request_data_from_rack(env)
301
- expect(result[:POST]).to be_eql(params)
302
- end
303
- end
304
-
305
- context 'with GET params' do
306
- let(:params) { { 'key' => 'value' } }
307
- let(:env) do
308
- Rack::MockRequest.env_for('/?foo=bar',
309
- :params => params,
310
- :method => 'GET')
311
-
312
-
313
- end
314
-
315
- it 'extracts the correct user IP' do
316
- result = subject.extract_request_data_from_rack(env)
317
- expect(result[:GET]).to be_eql(params)
318
- end
319
- end
320
- end
321
- end