rollbar 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 848cb96180e379178a47ca132eb966b8564907f6
4
- data.tar.gz: 59a914a93b7358d55000ab5ed4c56ec66bff6661
3
+ metadata.gz: 76e11bf57c6ee70f276c3434d3e28c529db808cb
4
+ data.tar.gz: 676d76874780fc5656d1648c7ae156592308d50d
5
5
  SHA512:
6
- metadata.gz: 6548900e375f976d9a07bd1a9c3c466315ce71eebd076c67f008926fc697a3dbdceacca958ff3cae0dd7d6c435af43fd3be89bf29ac53ef139d134458488a2ff
7
- data.tar.gz: f4cae49db511b1ee6ec231eabde6090e5a37344b4f25d23bc5adee7815d3bb8db77fcd2db3d810ecc521f36ed89bd94b5b20e2402127029327784c1a0031b39b
6
+ metadata.gz: 049de0ce6da8c17708748cde99eb4c183caa8614eff619400ea019be2b1531edfd34a50fdb842f67063d71cd12c05c4e5b2b9ce8db5ad93d53726cc0d8758b79
7
+ data.tar.gz: 85d20e995d647bef3ec5eb4996de93147c7562a33ed03874f3e60ed5157c1d297f8ab82d8597e30bae6a8733cdd7b02beb900e2b2ade04d99df52b1b7f52f829
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ **1.2.5**
4
+ - Fix issues handling hashes, arrays, and other values as the raw POST body. See [#153](https://github.com/rollbar/rollbar-gem/pull/153)
5
+
3
6
  **1.2.4**
4
7
  - Fix issue where requiring 'rack' unnecessarily broke things in non-rack apps. See [#150](https://github.com/rollbar/rollbar-gem/pull/150)
5
8
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rollbar notifier for Ruby [![Build Status](https://api.travis-ci.org/rollbar/rollbar-gem.svg?branch=v1.1.0)](https://travis-ci.org/rollbar/rollbar-gem/branches)
1
+ # Rollbar notifier for Ruby [![Build Status](https://api.travis-ci.org/rollbar/rollbar-gem.svg?branch=v1.2.5)](https://travis-ci.org/rollbar/rollbar-gem/branches)
2
2
 
3
3
  <!-- RemoveNext -->
4
4
  Ruby gem for reporting exceptions, errors, and log messages to [Rollbar](https://rollbar.com).
@@ -9,7 +9,7 @@ Ruby gem for reporting exceptions, errors, and log messages to [Rollbar](https:/
9
9
 
10
10
  Add this line to your application's Gemfile:
11
11
 
12
- gem 'rollbar', '~> 1.1.0'
12
+ gem 'rollbar', '~> 1.2.5'
13
13
 
14
14
  And then execute:
15
15
 
@@ -21,12 +21,12 @@ module Rollbar
21
21
  request_params = rollbar_filtered_params(sensitive_params, rollbar_request_params(env))
22
22
  get_params = rollbar_filtered_params(sensitive_params, rollbar_get_params(rack_req))
23
23
  post_params = rollbar_filtered_params(sensitive_params, rollbar_post_params(rack_req))
24
- raw_post_params = rollbar_filtered_params(sensitive_params, rollbar_raw_post_params(rack_req))
24
+ raw_body_params = rollbar_filtered_params(sensitive_params, mergeable_raw_body_params(rack_req))
25
25
  cookies = rollbar_filtered_params(sensitive_params, rollbar_request_cookies(rack_req))
26
26
  session = rollbar_filtered_params(sensitive_params, env['rack.session.options'])
27
27
  route_params = rollbar_filtered_params(sensitive_params, rollbar_route_params(env))
28
28
 
29
- params = request_params.merge(get_params).merge(post_params).merge(raw_post_params)
29
+ params = request_params.merge(get_params).merge(post_params).merge(raw_body_params)
30
30
 
31
31
  data = {
32
32
  :params => params,
@@ -48,6 +48,18 @@ module Rollbar
48
48
 
49
49
  private
50
50
 
51
+ def mergeable_raw_body_params(rack_req)
52
+ raw_body_params = rollbar_raw_body_params(rack_req)
53
+
54
+ if raw_body_params.is_a?(Hash)
55
+ raw_body_params
56
+ elsif raw_body_params.is_a?(Array)
57
+ { 'body.multi' => raw_body_params }
58
+ else
59
+ { 'body.value' => raw_body_params }
60
+ end
61
+ end
62
+
51
63
  def rollbar_request_method(env)
52
64
  env['REQUEST_METHOD'] || env[:method]
53
65
  end
@@ -100,7 +112,10 @@ module Rollbar
100
112
  {}
101
113
  end
102
114
 
103
- def rollbar_raw_post_params(rack_req)
115
+ def rollbar_raw_body_params(rack_req)
116
+ correct_method = rack_req.post? || rack_req.put? || rack_req.patch?
117
+
118
+ return {} unless correct_method
104
119
  return {} unless rack_req.env['CONTENT_TYPE'] =~ %r{application/json}i
105
120
 
106
121
  MultiJson.decode(rack_req.body.read)
@@ -115,8 +130,11 @@ module Rollbar
115
130
  end
116
131
 
117
132
  def rollbar_route_params(env)
133
+ return {} unless defined?(Rails)
134
+
118
135
  begin
119
136
  route = ::Rails.application.routes.recognize_path(env['PATH_INFO'])
137
+
120
138
  {
121
139
  :controller => route[:controller],
122
140
  :action => route[:action],
@@ -136,30 +154,28 @@ module Rollbar
136
154
  def rollbar_filtered_params(sensitive_params, params)
137
155
  sensitive_params_regexp = Regexp.new(sensitive_params.map{ |val| Regexp.escape(val.to_s).to_s }.join('|'), true)
138
156
 
139
- if params.nil?
140
- {}
141
- else
142
- params.to_hash.inject({}) do |result, (key, value)|
143
- if sensitive_params_regexp =~ key.to_s
144
- result[key] = rollbar_scrubbed(value)
145
- elsif value.is_a?(Hash)
146
- result[key] = rollbar_filtered_params(sensitive_params, value)
147
- elsif value.is_a?(Array)
148
- result[key] = value.map do |v|
149
- v.is_a?(Hash) ? rollbar_filtered_params(sensitive_params, v) : v
150
- end
151
- elsif ATTACHMENT_CLASSES.include?(value.class.name)
152
- result[key] = {
153
- :content_type => value.content_type,
154
- :original_filename => value.original_filename,
155
- :size => value.tempfile.size
156
- } rescue 'Uploaded file'
157
- else
158
- result[key] = value
159
- end
157
+ return {} unless params
160
158
 
161
- result
159
+ params.to_hash.inject({}) do |result, (key, value)|
160
+ if sensitive_params_regexp =~ key.to_s
161
+ result[key] = rollbar_scrubbed(value)
162
+ elsif value.is_a?(Hash)
163
+ result[key] = rollbar_filtered_params(sensitive_params, value)
164
+ elsif value.is_a?(Array)
165
+ result[key] = value.map do |v|
166
+ v.is_a?(Hash) ? rollbar_filtered_params(sensitive_params, v) : v
167
+ end
168
+ elsif ATTACHMENT_CLASSES.include?(value.class.name)
169
+ result[key] = {
170
+ :content_type => value.content_type,
171
+ :original_filename => value.original_filename,
172
+ :size => value.tempfile.size
173
+ } rescue 'Uploaded file'
174
+ else
175
+ result[key] = value
162
176
  end
177
+
178
+ result
163
179
  end
164
180
  end
165
181
 
@@ -1,3 +1,3 @@
1
1
  module Rollbar
2
- VERSION = "1.2.4"
2
+ VERSION = "1.2.5"
3
3
  end
@@ -56,17 +56,33 @@ describe Rollbar::Middleware::Rack::Builder do
56
56
 
57
57
  expect(Rollbar.last_report[:request][:params]).to be_eql(params)
58
58
  end
59
+ end
60
+
61
+ context 'with array POST parameters' do
62
+ let(:params) do
63
+ [{ :key => 'value'}, 'string', 10]
64
+ end
65
+
66
+ it 'sends a body.multi key in params' do
67
+ expect do
68
+ request.post('/will_crash', :input => params.to_json, 'CONTENT_TYPE' => 'application/json')
69
+ end.to raise_error(exception)
70
+
71
+ reported_params = Rollbar.last_report[:request][:params]
72
+ expect(reported_params['body.multi']).to be_eql([{'key' => 'value'}, 'string', 10])
73
+ end
74
+ end
59
75
 
60
- context 'with crashing payload' do
61
- let(:body) { 'this is not a valid json' }
76
+ context 'with not array or hash POST parameters' do
77
+ let(:params) { 1000 }
62
78
 
63
- it 'returns {} and doesnt raise' do
64
- expect do
65
- request.post('/dont_crash', :input => body, 'CONTENT_TYPE' => 'application/json')
66
- end.to raise_error(exception)
79
+ it 'sends a body.multi key in params' do
80
+ expect do
81
+ request.post('/will_crash', :input => params.to_json, 'CONTENT_TYPE' => 'application/json')
82
+ end.to raise_error(exception)
67
83
 
68
- expect(Rollbar.last_report[:request][:params]).to be_eql({})
69
- end
84
+ reported_params = Rollbar.last_report[:request][:params]
85
+ expect(reported_params['body.value']).to be_eql(1000)
70
86
  end
71
87
  end
72
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rollbar, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json