rollbar 1.1.0 → 1.2.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.
@@ -1,3 +1,3 @@
1
1
  module Rollbar
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -2,8 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe HomeController do
4
4
  let(:logger_mock) { double("Rails.logger").as_null_object }
5
+ let(:notifier) { Rollbar.notifier }
5
6
 
6
- before(:each) do
7
+ before do
7
8
  reset_configuration
8
9
  Rollbar::Rails.initialize
9
10
  Rollbar.configure do |config|
@@ -12,30 +13,29 @@ describe HomeController do
12
13
  config.request_timeout = 60
13
14
  end
14
15
  end
15
-
16
+
16
17
  context "rollbar base_data" do
17
18
  it 'should have the Rails environment' do
18
- data = Rollbar.send(:base_data)
19
- data[:environment].should == ::Rails.env
19
+ data = Rollbar.notifier.send(:build_payload, 'error', 'message', nil, nil)
20
+ data['data'][:environment].should == ::Rails.env
20
21
  end
21
-
22
+
22
23
  it 'should have an overridden environment' do
23
24
  Rollbar.configure do |config|
24
25
  config.environment = 'dev'
25
26
  end
26
-
27
- data = Rollbar.send(:base_data)
28
- data[:environment].should == 'dev'
27
+
28
+ data = Rollbar.notifier.send(:build_payload, 'error', 'message', nil, nil)
29
+ data['data'][:environment].should == 'dev'
29
30
  end
30
-
31
+
31
32
  it 'should use the default "unspecified" environment if rails env ends up being empty' do
32
- old_env = ::Rails.env
33
- ::Rails.env = ''
33
+ old_env, ::Rails.env = ::Rails.env, ''
34
34
  Rollbar::Rails.initialize
35
-
36
- data = Rollbar.send(:base_data)
37
- data[:environment].should == 'unspecified'
38
-
35
+
36
+ data = Rollbar.notifier.send(:build_payload, 'error', 'message', nil, nil)
37
+ data['data'][:environment].should == 'unspecified'
38
+
39
39
  ::Rails.env = old_env
40
40
  end
41
41
  end
@@ -58,104 +58,7 @@ describe HomeController do
58
58
  data.should == {}
59
59
  end
60
60
 
61
- context "rollbar_filter_params" do
62
- it "should filter files" do
63
- name = "John Doe"
64
- file_hash = {
65
- :filename => "test.txt",
66
- :type => "text/plain",
67
- :head => {},
68
- :tempfile => "dummy"
69
- }
70
- file = ActionDispatch::Http::UploadedFile.new(file_hash)
71
-
72
- params = {
73
- :name => name,
74
- :a_file => file
75
- }
76
-
77
- filtered = controller.send(:rollbar_filtered_params, Rollbar.configuration.scrub_fields, params)
78
-
79
- filtered[:name].should == name
80
- filtered[:a_file].should be_a_kind_of(Hash)
81
- filtered[:a_file][:content_type].should == file_hash[:type]
82
- filtered[:a_file][:original_filename].should == file_hash[:filename]
83
- filtered[:a_file][:size].should == file_hash[:tempfile].size
84
- end
85
-
86
- it "should filter files in nested params" do
87
- name = "John Doe"
88
- file_hash = {
89
- :filename => "test.txt",
90
- :type => "text/plain",
91
- :head => {},
92
- :tempfile => "dummy"
93
- }
94
- file = ActionDispatch::Http::UploadedFile.new(file_hash)
95
-
96
- params = {
97
- :name => name,
98
- :wrapper => {
99
- :wrapper2 => {
100
- :a_file => file,
101
- :foo => "bar"
102
- }
103
- }
104
- }
105
-
106
- filtered = controller.send(:rollbar_filtered_params, Rollbar.configuration.scrub_fields, params)
107
-
108
- filtered[:name].should == name
109
- filtered[:wrapper][:wrapper2][:foo].should == "bar"
110
-
111
- filtered_file = filtered[:wrapper][:wrapper2][:a_file]
112
- filtered_file.should be_a_kind_of(Hash)
113
- filtered_file[:content_type].should == file_hash[:type]
114
- filtered_file[:original_filename].should == file_hash[:filename]
115
- filtered_file[:size].should == file_hash[:tempfile].size
116
- end
117
-
118
- it "should scrub the default scrub_fields" do
119
- params = {
120
- :passwd => "hidden",
121
- :password => "hidden",
122
- :secret => "hidden",
123
- :notpass => "visible",
124
- :secret_token => "f6805fea1cae0fb79c5e63bbdcd12bc6",
125
- }
126
-
127
- filtered = controller.send(:rollbar_filtered_params, Rollbar.configuration.scrub_fields, params)
128
-
129
- filtered[:passwd].should == "******"
130
- filtered[:password].should == "******"
131
- filtered[:secret].should == "******"
132
- filtered[:notpass].should == "visible"
133
- filtered[:secret_token].should == "*" * 32
134
- end
135
-
136
- it "should scrub custom scrub_fields" do
137
- Rollbar.configure do |config|
138
- config.scrub_fields = [:notpass, :secret]
139
- end
140
-
141
- params = {
142
- :passwd => "visible",
143
- :password => "visible",
144
- :secret => "hidden",
145
- :notpass => "hidden"
146
- }
147
-
148
- filtered = controller.send(:rollbar_filtered_params, Rollbar.configuration.scrub_fields, params)
149
-
150
- filtered[:passwd].should == "visible"
151
- filtered[:password].should == "visible"
152
- filtered[:secret].should == "******"
153
- filtered[:notpass].should == "******"
154
- end
155
- end
156
-
157
61
  context 'rollbar_scrub_headers' do
158
-
159
62
  it 'should filter authentication by default' do
160
63
  headers = {
161
64
  'HTTP_AUTHORIZATION' => 'some-user',
@@ -197,7 +100,7 @@ describe HomeController do
197
100
 
198
101
  controller.send(:rollbar_request_data)[:url].should == 'http://rollbar.com'
199
102
  end
200
-
103
+
201
104
  it "should respect forwarded host" do
202
105
  req = controller.request
203
106
  req.host = '127.0.0.1:8080'
@@ -205,7 +108,7 @@ describe HomeController do
205
108
 
206
109
  controller.send(:rollbar_request_data)[:url].should == 'http://test.com'
207
110
  end
208
-
111
+
209
112
  it "should respect forwarded proto" do
210
113
  req = controller.request
211
114
  req.host = 'rollbar.com'
@@ -213,7 +116,7 @@ describe HomeController do
213
116
 
214
117
  controller.send(:rollbar_request_data)[:url].should == 'https://rollbar.com'
215
118
  end
216
-
119
+
217
120
  it "should respect forwarded port" do
218
121
  req = controller.request
219
122
  req.host = '127.0.0.1:8080'
@@ -221,7 +124,7 @@ describe HomeController do
221
124
  req.env['HTTP_X_FORWARDED_PORT'] = '80'
222
125
 
223
126
  controller.send(:rollbar_request_data)[:url].should == 'http://test.com'
224
-
127
+
225
128
  req.env['HTTP_X_FORWARDED_PORT'] = '81'
226
129
  controller.send(:rollbar_request_data)[:url].should == 'http://test.com:81'
227
130
  end
@@ -243,32 +146,77 @@ describe HomeController do
243
146
  controller.send(:rollbar_request_data)[:user_ip].should == '0.0.0.0'
244
147
  end
245
148
  end
246
-
247
- context "rollbar_route_params" do
149
+
150
+ context "rollbar_route_params", :type => 'request' do
248
151
  it "should save route params in request[:route]" do
249
152
  route = controller.send(:rollbar_request_data)[:route]
250
-
153
+
251
154
  route.should have_key(:controller)
252
155
  route.should have_key(:action)
253
156
  route.should have_key(:format)
254
-
157
+
255
158
  route[:controller].should == 'home'
256
159
  route[:action].should == 'index'
257
160
  end
258
-
161
+
259
162
  it "should save controller and action in the payload body" do
260
163
  post 'report_exception'
261
-
164
+
262
165
  route = controller.send(:rollbar_request_data)[:route]
263
-
166
+
264
167
  route[:controller].should == 'home'
265
168
  route[:action].should == 'report_exception'
266
-
169
+
267
170
  Rollbar.last_report.should_not be_nil
268
171
  Rollbar.last_report[:context].should == 'home#report_exception'
269
172
  end
270
173
  end
174
+ end
175
+
176
+ context "param_scrubbing", :type => "request" do
177
+ it "should scrub the default scrub_fields" do
178
+ params = {
179
+ :passwd => "hidden",
180
+ :password => "hidden",
181
+ :secret => "hidden",
182
+ :notpass => "visible",
183
+ :secret_token => "f6805fea1cae0fb79c5e63bbdcd12bc6",
184
+ }
185
+
186
+ post 'report_exception', params
187
+
188
+ filtered = Rollbar.last_report[:request][:params]
189
+
190
+ filtered["passwd"].should == "******"
191
+ filtered["password"].should == "******"
192
+ filtered["secret"].should == "******"
193
+ filtered["notpass"].should == "visible"
194
+ filtered["secret_token"].should == "*" * 32
195
+ end
271
196
 
197
+ it "should scrub custom scrub_fields" do
198
+ Rollbar.configure do |config|
199
+ config.scrub_fields = [:notpass, :secret]
200
+ end
201
+
202
+ params = {
203
+ :passwd => "visible",
204
+ :password => "visible",
205
+ :secret => "hidden",
206
+ :notpass => "hidden"
207
+ }
208
+
209
+ post 'report_exception', params
210
+
211
+ filtered = Rollbar.last_report[:request][:params]
212
+
213
+ filtered["passwd"].should == "visible"
214
+ # config.filter_parameters is set to [:password] in
215
+ # spec/dummyapp/config/application.rb
216
+ filtered["password"].should == "*******"
217
+ filtered["secret"].should == "******"
218
+ filtered["notpass"].should == "******"
219
+ end
272
220
  end
273
221
 
274
222
  describe "GET 'index'" do
@@ -286,35 +234,46 @@ describe HomeController do
286
234
  get 'report_exception'
287
235
  response.should be_success
288
236
  end
289
-
237
+
290
238
  it "should raise a NameError and have PUT params in the reported exception" do
291
239
  logger_mock.should_receive(:info).with('[Rollbar] Success')
292
240
 
293
241
  put 'report_exception', :putparam => "putval"
294
-
242
+
295
243
  Rollbar.last_report.should_not be_nil
296
244
  Rollbar.last_report[:request][:params]["putparam"].should == "putval"
297
245
  end
298
-
246
+
247
+ context 'using deprecated report_exception' do
248
+ it 'reports the errors successfully' do
249
+ logger_mock.should_receive(:info).with('[Rollbar] Success')
250
+
251
+ put '/deprecated_report_exception', :putparam => "putval"
252
+
253
+ Rollbar.last_report.should_not be_nil
254
+ Rollbar.last_report[:request][:params]["putparam"].should == "putval"
255
+ end
256
+ end
257
+
299
258
  it "should raise a NameError and have JSON POST params" do
300
259
  logger_mock.should_receive(:info).with('[Rollbar] Success')
301
260
  @request.env["HTTP_ACCEPT"] = "application/json"
302
-
303
- params = {:jsonparam => 'jsonval'}.to_json
304
- post 'report_exception', params, {'CONTENT_TYPE' => 'application/json'}
305
-
261
+
262
+ params = { :jsonparam => 'jsonval' }.to_json
263
+ post 'report_exception', params, { 'CONTENT_TYPE' => 'application/json' }
264
+
306
265
  Rollbar.last_report.should_not be_nil
307
266
  Rollbar.last_report[:request][:params]['jsonparam'].should == 'jsonval'
308
267
  end
309
268
  end
310
-
269
+
311
270
  describe "'cause_exception'", :type => "request" do
312
271
  it "should raise an uncaught exception and report a message" do
313
272
  logger_mock.should_receive(:info).with('[Rollbar] Success').once
314
-
273
+
315
274
  expect { get 'cause_exception' }.to raise_exception
316
275
  end
317
-
276
+
318
277
  context 'show_exceptions' do
319
278
  before(:each) do
320
279
  if Dummy::Application.respond_to? :env_config
@@ -322,46 +281,52 @@ describe HomeController do
322
281
  else
323
282
  config = Dummy::Application.env_defaults
324
283
  end
325
-
284
+
326
285
  config['action_dispatch.show_exceptions'] = true
327
286
  end
328
-
287
+
329
288
  after(:each) do
330
289
  if Dummy::Application.respond_to? :env_config
331
290
  config = Dummy::Application.env_config
332
291
  else
333
292
  config = Dummy::Application.env_defaults
334
293
  end
335
-
294
+
336
295
  config['action_dispatch.show_exceptions'] = false
337
296
  end
338
-
297
+
339
298
  it "middleware should catch the exception and only report to rollbar once" do
340
299
  logger_mock.should_receive(:info).with('[Rollbar] Success').once
341
-
342
- get 'cause_exception'
343
- end
344
-
345
- it 'rollbar request store should extract person data and put it into the reqest' do
346
- Rollbar.configure do |config|
347
- config.person_method = 'custom_current_user'
348
- end
349
-
300
+
350
301
  get 'cause_exception'
351
-
352
- user = request.env['rollbar.person_data']
353
- user[:id].should == 123
354
- user[:username].should == 'test'
355
- user[:email].should == 'email@test.com'
356
302
  end
357
-
303
+
358
304
  it 'should not fail if the controller doesnt contain the person method' do
359
305
  Rollbar.configure do |config|
360
306
  config.person_method = 'invalid_method'
361
307
  end
362
-
308
+
363
309
  get 'cause_exception'
364
310
  end
311
+
312
+ context 'with logged user' do
313
+ let(:user) do
314
+ User.create(:email => 'foo@bar.com',
315
+ :username => 'the_username')
316
+ end
317
+
318
+ before { cookies[:session_id] = user.id }
319
+
320
+ it 'sends the current user data' do
321
+ put 'report_exception', 'foo' => 'bar'
322
+
323
+ person_data = Rollbar.last_report[:person]
324
+
325
+ expect(person_data[:id]).to be_eql(user.id)
326
+ expect(person_data[:email]).to be_eql(user.email)
327
+ expect(person_data[:username]).to be_eql(user.username)
328
+ end
329
+ end
365
330
  end
366
331
  end
367
332
 
@@ -2,27 +2,37 @@ class HomeController < ApplicationController
2
2
  def index
3
3
  @users = User.all
4
4
 
5
- Rollbar.report_message("Test message from controller with no data", "debug")
6
- Rollbar.report_message("Test message from controller with extra data", "debug",
7
- :foo => "bar", :num_users => @users.length)
5
+ Rollbar.debug("Test message from controller with no data")
6
+ Rollbar.debug("Test message from controller with extra data",
7
+ :foo => "bar", :num_users => @users.length)
8
8
  end
9
9
 
10
10
  def report_exception
11
11
  begin
12
12
  foo = bar
13
13
  rescue => e
14
- Rollbar.report_exception(e, rollbar_request_data, rollbar_person_data)
14
+ Rollbar.error(e)
15
15
  end
16
16
  end
17
17
 
18
+ def deprecated_report_exception
19
+ begin
20
+ foo = bar
21
+ rescue => e
22
+ Rollbar.report_exception(e)
23
+ end
24
+ render :json => {}
25
+ end
26
+
27
+
18
28
  def cause_exception
19
29
  foo = bar
20
30
  end
21
31
 
22
32
  def current_user
23
- User.find_by_encrypted_password(cookies[:session_id])
33
+ @current_user ||= User.find_by_id(cookies[:session_id])
24
34
  end
25
-
35
+
26
36
  def custom_current_user
27
37
  user = User.new
28
38
  user.id = 123