airbrake 5.6.0 → 5.6.1

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: 0101d07aaa70ffe17d357dbeefd3c00b0e750ac0
4
- data.tar.gz: c6642bb8d3f2515bad7f22b79b0d96119609d536
3
+ metadata.gz: 74d407054008e4b64ea9fd13bbbb4e4b5532ef4e
4
+ data.tar.gz: 8d39d898036c546a052c211191419d5448495970
5
5
  SHA512:
6
- metadata.gz: 6e3be8dd51149933fa2cbc6c92a972f0c029b1c649377e2b55e9a476d119725d65d98554cbfc103e15d698f992d964cac8c910af4b44fce6502a6ea57d930d9e
7
- data.tar.gz: 0c4295e72b8e09e5d9cc30146d6b43f8aa7c9f48a579b7ef4f60ac56bd0514f41f560acb58ce62f51bd9b1c336c911a541bf893266b375b5a6e647d63129830e
6
+ metadata.gz: 25563fe3c612bc3ce4eb0b7b3320f893e26f1be866781673f5866d896804801ca5427d007c14b8f7a62afa2733ea25d9031b6a49fa2b1d09b0ae62e5650497c4
7
+ data.tar.gz: 6b66de7a73b659090fe9f5526d0d69631938c52b74042a332424a2e8e735255a855bc8dd35c58dec1ce3dfab46d107011d8f30da08bb2830b2899753097a1bde
@@ -90,8 +90,10 @@ module Airbrake
90
90
  ##
91
91
  # Adds HTTP request parameters.
92
92
  add_builder do |notice, request|
93
- params = request.env['action_dispatch.request.parameters']
94
- notice[:params] = params if params
93
+ notice[:params] = request.params
94
+
95
+ rails_params = request.env['action_dispatch.request.parameters']
96
+ notice[:params].merge!(rails_params) if rails_params
95
97
  end
96
98
 
97
99
  ##
@@ -110,6 +112,15 @@ module Airbrake
110
112
  referer: request.referer,
111
113
  headers: http_headers
112
114
  )
115
+
116
+ notice[:environment][:body] =
117
+ if request.body
118
+ data = request.body.read(512)
119
+ request.body.rewind
120
+ data
121
+ end
122
+
123
+ notice[:environment]
113
124
  end
114
125
  end
115
126
  end
@@ -17,10 +17,17 @@ module Airbrake
17
17
  end
18
18
 
19
19
  # Fallback mode (OmniAuth support included). Works only for Rails.
20
+ user = try_current_user(rack_env)
21
+ new(user) if user
22
+ end
23
+
24
+ def self.try_current_user(rack_env)
20
25
  controller = rack_env['action_controller.instance']
21
26
  return unless controller.respond_to?(:current_user)
22
- new(controller.current_user) if controller.current_user
27
+ return unless [-1, 0].include?(controller.method(:current_user).arity)
28
+ controller.current_user
23
29
  end
30
+ private_class_method :try_current_user
24
31
 
25
32
  def initialize(user)
26
33
  @user = user
@@ -2,5 +2,5 @@
2
2
  # We use Semantic Versioning v2.0.0
3
3
  # More information: http://semver.org/
4
4
  module Airbrake
5
- AIRBRAKE_VERSION = '5.6.0'.freeze
5
+ AIRBRAKE_VERSION = '5.6.1'.freeze
6
6
  end
@@ -1,9 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Airbrake::Rack::NoticeBuilder do
4
+ def env_for(url, opts = {})
5
+ Rack::MockRequest.env_for(url, opts)
6
+ end
7
+
4
8
  describe "#build_notice" do
5
- it "doesn't overwrite session with nil" do
6
- notice_builder = described_class.new('rack.session' => nil)
9
+ it "doesn't overwrite the session key with nil" do
10
+ notice_builder = described_class.new(env_for('/', 'rack.session' => nil))
7
11
  notice = notice_builder.build_notice(AirbrakeTestError.new)
8
12
 
9
13
  expect(notice[:session]).to eq({})
@@ -11,34 +15,47 @@ RSpec.describe Airbrake::Rack::NoticeBuilder do
11
15
 
12
16
  it "sets session if it is present" do
13
17
  session = { a: 1, b: 2 }
14
- notice_builder = described_class.new('rack.session' => session)
18
+ notice_builder = described_class.new(env_for('/', 'rack.session' => session))
15
19
  notice = notice_builder.build_notice(AirbrakeTestError.new)
16
20
 
17
21
  expect(notice[:session]).to eq(session)
18
22
  end
19
23
 
20
- it "doesn't overwrite params with nil" do
21
- notice_builder = described_class.new('action_dispatch.request.parameters' => nil)
24
+ it "doesn't overwrite the params key with nil" do
25
+ notice_builder = described_class.new(env_for('/'))
22
26
  notice = notice_builder.build_notice(AirbrakeTestError.new)
23
27
 
24
28
  expect(notice[:session]).to eq({})
25
29
  end
26
30
 
27
- it "sets params if they're present" do
31
+ it "sets form params if they're present" do
28
32
  params = { a: 1, b: 2 }
29
- notice_builder = described_class.new('action_dispatch.request.parameters' => params)
33
+ input = StringIO.new
34
+
35
+ notice_builder = described_class.new(
36
+ 'rack.request.form_hash' => params,
37
+ 'rack.request.form_input' => input,
38
+ 'rack.input' => input
39
+ )
30
40
  notice = notice_builder.build_notice(AirbrakeTestError.new)
31
41
 
32
42
  expect(notice[:params]).to eq(params)
33
43
  end
34
44
 
45
+ it "sets query string params if they're present" do
46
+ notice_builder = described_class.new(env_for('/?bingo=bango&bongo=bish'))
47
+ notice = notice_builder.build_notice(AirbrakeTestError.new)
48
+
49
+ expect(notice[:params]).to eq('bingo' => 'bango', 'bongo' => 'bish')
50
+ end
51
+
35
52
  it "adds CONTENT_TYPE, CONTENT_LENGTH and HTTP_* headers in the environment" do
36
53
  headers = {
37
54
  "HTTP_HOST" => "example.com",
38
55
  "CONTENT_TYPE" => "text/html",
39
56
  "CONTENT_LENGTH" => 100500
40
57
  }
41
- notice_builder = described_class.new(headers.dup)
58
+ notice_builder = described_class.new(env_for('/', headers.dup))
42
59
  notice = notice_builder.build_notice(AirbrakeTestError.new)
43
60
  expect(notice[:environment][:headers]).to eq(headers)
44
61
  end
@@ -49,8 +66,11 @@ RSpec.describe Airbrake::Rack::NoticeBuilder do
49
66
  "CONTENT_TYPE" => "text/html",
50
67
  "CONTENT_LENGTH" => 100500
51
68
  }
52
- notice_builder = described_class.new(headers.merge("X-SOME-HEADER" => "value"))
69
+ notice_builder = described_class.new(
70
+ env_for('/', headers.merge("X-SOME-HEADER" => "value"))
71
+ )
53
72
  notice = notice_builder.build_notice(AirbrakeTestError.new)
73
+
54
74
  expect(notice[:environment][:headers]).to eq(headers)
55
75
  end
56
76
 
@@ -65,29 +85,73 @@ RSpec.describe Airbrake::Rack::NoticeBuilder do
65
85
  notice[:environment]["SOME_KEY"] = "SOME_VALUE"
66
86
  notice
67
87
  end
68
- notice_builder = described_class.new(headers)
88
+ notice_builder = described_class.new(env_for('/', headers))
69
89
  notice = notice_builder.build_notice(AirbrakeTestError.new)
90
+
70
91
  expect(notice[:environment]["SOME_KEY"]).to eq("SOME_VALUE")
71
92
  end
72
93
 
73
- it "runs user defined builders against notices" do
74
- extended_class = described_class.dup
75
- extended_class.add_builder do |notice, request|
76
- notice[:params][:remoteIp] = request.env['REMOTE_IP']
94
+ context "when a custom builder is defined" do
95
+ before do
96
+ described_class.add_builder do |notice, request|
97
+ notice[:params][:remoteIp] = request.env['REMOTE_IP']
98
+ end
99
+ end
100
+
101
+ after do
102
+ described_class.instance_variable_get(:@builders).pop
103
+ end
104
+
105
+ it "runs the builder against notices" do
106
+ notice_builder = described_class.new(env_for('/', 'REMOTE_IP' => '127.0.0.1'))
107
+ notice = notice_builder.build_notice(AirbrakeTestError.new)
108
+
109
+ expect(notice[:params][:remoteIp]).to eq("127.0.0.1")
77
110
  end
78
- notice_builder = extended_class.new('REMOTE_IP' => '127.0.0.1')
79
- notice = notice_builder.build_notice(AirbrakeTestError.new)
80
- expect(notice[:params][:remoteIp]).to eq("127.0.0.1")
81
111
  end
82
112
 
83
113
  context "when Airbrake is not configured" do
84
114
  it "returns nil" do
85
115
  allow(Airbrake).to receive(:build_notice).and_return(nil)
86
- notice_builder = described_class.new('bingo' => 'bango')
116
+ notice_builder = described_class.new(env_for('/', 'bingo' => 'bango'))
87
117
 
88
118
  expect(notice_builder.build_notice('bongo')).to be_nil
89
119
  expect(Airbrake).to have_received(:build_notice)
90
120
  end
91
121
  end
122
+
123
+ context "when a request has a body" do
124
+ it "reads the body" do
125
+ body = StringIO.new('<bingo>bongo</bango>')
126
+ notice_builder = described_class.new(
127
+ env_for('/', 'rack.input' => body)
128
+ )
129
+ notice = notice_builder.build_notice(AirbrakeTestError.new)
130
+
131
+ expect(notice[:environment][:body]).to eq(body.string)
132
+ end
133
+
134
+ it "rewinds rack.input" do
135
+ body = StringIO.new('<bingo>bongo</bango>' * 512)
136
+ notice_builder = described_class.new(
137
+ env_for('/', 'rack.input' => body)
138
+ )
139
+
140
+ notice_builder.build_notice(AirbrakeTestError.new)
141
+
142
+ expect(body.pos).to be_zero
143
+ end
144
+
145
+ it "reads only first 512 bytes" do
146
+ len = 513
147
+ body = StringIO.new('a' * len)
148
+ notice_builder = described_class.new(
149
+ env_for('/', 'rack.input' => body)
150
+ )
151
+ notice = notice_builder.build_notice(AirbrakeTestError.new)
152
+
153
+ expect(notice[:environment][:body]).to eq(body.string[0...len - 1])
154
+ end
155
+ end
92
156
  end
93
157
  end
@@ -52,10 +52,11 @@ RSpec.describe Airbrake::Rack::User do
52
52
  end
53
53
 
54
54
  context "when the current_user Rails controller method is defined" do
55
+ let(:controller) { instance_double('DummyController') }
56
+ let(:env) { env_for('/', 'action_controller.instance' => controller) }
57
+
55
58
  context "and it is nil" do
56
59
  it "returns nil" do
57
- controller = instance_double('DummyController')
58
- env = env_for('/', 'action_controller.instance' => controller)
59
60
  allow(controller).to receive(:current_user) { nil }
60
61
 
61
62
  retval = described_class.extract(env)
@@ -65,13 +66,76 @@ RSpec.describe Airbrake::Rack::User do
65
66
 
66
67
  context "and it is not nil" do
67
68
  it "returns the wrapped user" do
68
- controller = instance_double('DummyController')
69
- env = env_for('/', 'action_controller.instance' => controller)
70
69
  allow(controller).to receive(:current_user) { user }
71
70
 
72
71
  retval = described_class.extract(env)
73
72
  expect(retval).to be_a(described_class)
74
73
  end
74
+
75
+ context "but it requires parameters" do
76
+ let(:controller) { dummy_controller.new }
77
+ subject { described_class.extract(env) }
78
+
79
+ context ": current_user(a)" do
80
+ let(:dummy_controller) do
81
+ Class.new do
82
+ def current_user(_a)
83
+ "username"
84
+ end
85
+ end
86
+ end
87
+
88
+ it { should be_nil }
89
+ end
90
+
91
+ context ": current_user(a, b)" do
92
+ let(:dummy_controller) do
93
+ Class.new do
94
+ def current_user(_a, _b)
95
+ "username"
96
+ end
97
+ end
98
+ end
99
+
100
+ it { should be_nil }
101
+ end
102
+
103
+ context ": current_user(a, *b)" do
104
+ let(:dummy_controller) do
105
+ Class.new do
106
+ def current_user(_a, *_b)
107
+ "username"
108
+ end
109
+ end
110
+ end
111
+
112
+ it { should be_nil }
113
+ end
114
+
115
+ context ": current_user(a, b, *c, &d)" do
116
+ let(:dummy_controller) do
117
+ Class.new do
118
+ def current_user(_a, _b, *_c, &_d)
119
+ "username"
120
+ end
121
+ end
122
+ end
123
+
124
+ it { should be_nil }
125
+ end
126
+
127
+ context ": current_user(*a)" do
128
+ let(:dummy_controller) do
129
+ Class.new do
130
+ def current_user(*_a)
131
+ "username"
132
+ end
133
+ end
134
+ end
135
+
136
+ it { should be_a(described_class) }
137
+ end
138
+ end
75
139
  end
76
140
  end
77
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airbrake
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.6.0
4
+ version: 5.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airbrake Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2016-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: airbrake-ruby