airbrake 9.2.1 → 9.2.2
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.
- checksums.yaml +4 -4
- data/lib/airbrake/rack/middleware.rb +21 -13
- data/lib/airbrake/rails/action_controller_performance_breakdown_subscriber.rb +20 -2
- data/lib/airbrake/version.rb +1 -1
- metadata +5 -81
- data/spec/apps/rack/dummy_app.rb +0 -17
- data/spec/apps/rails/dummy_app.rb +0 -258
- data/spec/apps/rails/dummy_task.rake +0 -15
- data/spec/apps/rails/logs/32.log +0 -34094
- data/spec/apps/rails/logs/42.log +0 -1488
- data/spec/apps/rails/logs/52.log +0 -6321
- data/spec/apps/sinatra/sinatra_test_app.rb +0 -12
- data/spec/integration/rack/rack_spec.rb +0 -19
- data/spec/integration/rails/rails_spec.rb +0 -430
- data/spec/integration/rails/rake_spec.rb +0 -97
- data/spec/integration/shared_examples/rack_examples.rb +0 -110
- data/spec/integration/sinatra/sinatra_spec.rb +0 -30
- data/spec/spec_helper.rb +0 -105
- data/spec/support/matchers/a_notice_with.rb +0 -29
- data/spec/unit/logger_spec.rb +0 -125
- data/spec/unit/rack/context_filter_spec.rb +0 -90
- data/spec/unit/rack/http_headers_filter_spec.rb +0 -44
- data/spec/unit/rack/http_params_filter_spec.rb +0 -58
- data/spec/unit/rack/instrumentable_spec.rb +0 -105
- data/spec/unit/rack/middleware_spec.rb +0 -98
- data/spec/unit/rack/rack_spec.rb +0 -46
- data/spec/unit/rack/request_body_filter_spec.rb +0 -44
- data/spec/unit/rack/request_store_spec.rb +0 -36
- data/spec/unit/rack/route_filter_spec.rb +0 -52
- data/spec/unit/rack/session_filter_spec.rb +0 -44
- data/spec/unit/rack/user_filter_spec.rb +0 -30
- data/spec/unit/rack/user_spec.rb +0 -218
- data/spec/unit/rails/action_cable/notify_callback_spec.rb +0 -26
- data/spec/unit/rails/action_controller_notify_subscriber_spec.rb +0 -43
- data/spec/unit/rails/action_controller_performance_breakdown_subscriber_spec.rb +0 -63
- data/spec/unit/rails/action_controller_route_subscriber_spec.rb +0 -84
- data/spec/unit/rails/active_record_subscriber_spec.rb +0 -70
- data/spec/unit/rails/excon_spec.rb +0 -46
- data/spec/unit/rake/tasks_spec.rb +0 -70
- data/spec/unit/shoryuken_spec.rb +0 -55
- data/spec/unit/sidekiq/retryable_jobs_filter_spec.rb +0 -36
- data/spec/unit/sidekiq_spec.rb +0 -33
- data/spec/unit/sneakers_spec.rb +0 -83
@@ -1,36 +0,0 @@
|
|
1
|
-
RSpec.describe Airbrake::Rack::RequestStore do
|
2
|
-
after { described_class.clear }
|
3
|
-
|
4
|
-
describe "#store" do
|
5
|
-
it "returns an empty Hash" do
|
6
|
-
expect(subject.store).to be_a(Hash)
|
7
|
-
expect(subject.store).to be_empty
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#[]=" do
|
12
|
-
it "writes a value under a key" do
|
13
|
-
subject[:foo] = :bar
|
14
|
-
expect(subject.store).to eq(foo: :bar)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#[]" do
|
19
|
-
it "reads a value under a key" do
|
20
|
-
subject[:foo] = :bar
|
21
|
-
expect(subject[:foo]).to eq(:bar)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#clear" do
|
26
|
-
before do
|
27
|
-
subject[:foo] = 1
|
28
|
-
subject[:bar] = 2
|
29
|
-
end
|
30
|
-
|
31
|
-
it "clears everything in the store" do
|
32
|
-
subject.clear
|
33
|
-
expect(subject.store).to be_empty
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
RSpec.describe Airbrake::Rack::RouteFilter do
|
2
|
-
context "when there's no request object available" do
|
3
|
-
it "doesn't add context/route" do
|
4
|
-
notice = Airbrake.build_notice('oops')
|
5
|
-
subject.call(notice)
|
6
|
-
expect(notice[:context][:route]).to be_nil
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
context "when Sinatra route is unavailable" do
|
11
|
-
before { stub_const('Sinatra::Request', Class.new) }
|
12
|
-
|
13
|
-
let(:notice) do
|
14
|
-
notice = Airbrake.build_notice('oops')
|
15
|
-
|
16
|
-
request_mock = instance_double(Sinatra::Request)
|
17
|
-
expect(request_mock)
|
18
|
-
.to receive(:instance_of?).with(Sinatra::Request).and_return(true)
|
19
|
-
expect(request_mock).to receive(:env).and_return({})
|
20
|
-
|
21
|
-
notice.stash[:rack_request] = request_mock
|
22
|
-
notice
|
23
|
-
end
|
24
|
-
|
25
|
-
it "doesn't add context/route" do
|
26
|
-
subject.call(notice)
|
27
|
-
expect(notice[:context][:route]).to be_nil
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when Sinatra route is available" do
|
32
|
-
before { stub_const('Sinatra::Request', Class.new) }
|
33
|
-
|
34
|
-
let(:notice) do
|
35
|
-
notice = Airbrake.build_notice('oops')
|
36
|
-
|
37
|
-
request_mock = instance_double(Sinatra::Request)
|
38
|
-
expect(request_mock)
|
39
|
-
.to receive(:instance_of?).with(Sinatra::Request).and_return(true)
|
40
|
-
expect(request_mock)
|
41
|
-
.to receive(:env).and_return('sinatra.route' => 'GET /test-route')
|
42
|
-
|
43
|
-
notice.stash[:rack_request] = request_mock
|
44
|
-
notice
|
45
|
-
end
|
46
|
-
|
47
|
-
it "doesn't add context/route" do
|
48
|
-
subject.call(notice)
|
49
|
-
expect(notice[:context][:route]).to eq('/test-route')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
RSpec.describe Airbrake::Rack::SessionFilter do
|
2
|
-
def env_for(url, opts = {})
|
3
|
-
Rack::MockRequest.env_for(url, opts)
|
4
|
-
end
|
5
|
-
|
6
|
-
let(:notice) do
|
7
|
-
Airbrake.build_notice('oops').tap do |notice|
|
8
|
-
notice.stash[:rack_request] = Rack::Request.new(env_for(uri, opts))
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
context "when rack session is nil" do
|
13
|
-
let(:uri) { '/' }
|
14
|
-
|
15
|
-
let(:opts) do
|
16
|
-
{ 'rack.session' => nil }
|
17
|
-
end
|
18
|
-
|
19
|
-
it "doesn't overwrite the session key with nil" do
|
20
|
-
expect(notice[:session]).to eq({})
|
21
|
-
|
22
|
-
subject.call(notice)
|
23
|
-
|
24
|
-
expect(notice[:session]).to eq({})
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when session is present" do
|
29
|
-
let(:session) do
|
30
|
-
{ a: 1, b: 2 }
|
31
|
-
end
|
32
|
-
|
33
|
-
let(:uri) { '/' }
|
34
|
-
|
35
|
-
let(:opts) do
|
36
|
-
{ 'rack.session' => session }
|
37
|
-
end
|
38
|
-
|
39
|
-
it "sets session if it is present" do
|
40
|
-
subject.call(notice)
|
41
|
-
expect(notice[:session]).to eq(session)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
RSpec.describe Airbrake::Rack::UserFilter do
|
2
|
-
def env_for(url, opts = {})
|
3
|
-
Rack::MockRequest.env_for(url, opts)
|
4
|
-
end
|
5
|
-
|
6
|
-
let(:notice) do
|
7
|
-
Airbrake.build_notice('oops').tap do |notice|
|
8
|
-
notice.stash[:rack_request] = Rack::Request.new(env_for('/', {}))
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:user_payload) { { username: 'bingo' } }
|
13
|
-
let(:user) { Airbrake::Rack::User.new(double(user_payload)) }
|
14
|
-
|
15
|
-
it "delegates extraction of the current user information" do
|
16
|
-
expect(Airbrake::Rack::User).to receive(:extract).and_return(user)
|
17
|
-
subject.call(notice)
|
18
|
-
expect(notice[:context][:user]).to eq(user_payload)
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when no current user is found" do
|
22
|
-
let(:user) { Airbrake::Rack::User.new(double) }
|
23
|
-
|
24
|
-
it "does not include the user key in the payload" do
|
25
|
-
expect(Airbrake::Rack::User).to receive(:extract).and_return(user)
|
26
|
-
subject.call(notice)
|
27
|
-
expect(notice[:context].keys).not_to include(:user)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/unit/rack/user_spec.rb
DELETED
@@ -1,218 +0,0 @@
|
|
1
|
-
RSpec.describe Airbrake::Rack::User do
|
2
|
-
let(:endpoint) { 'https://api.airbrake.io/api/v3/projects/113743/notices' }
|
3
|
-
|
4
|
-
let(:user) do
|
5
|
-
OpenStruct.new(
|
6
|
-
id: 1,
|
7
|
-
email: 'qa@example.com',
|
8
|
-
username: 'qa-dept',
|
9
|
-
first_name: 'Bingo',
|
10
|
-
last_name: 'Bongo'
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
def env_for(url, opts = {})
|
15
|
-
Rack::MockRequest.env_for(url, opts)
|
16
|
-
end
|
17
|
-
|
18
|
-
before do
|
19
|
-
stub_request(:post, endpoint).to_return(status: 201, body: '{}')
|
20
|
-
end
|
21
|
-
|
22
|
-
describe ".extract" do
|
23
|
-
context "when the Warden authentication framework is present" do
|
24
|
-
it "returns the wrapped user" do
|
25
|
-
warden = instance_double('Warden::Proxy')
|
26
|
-
allow(warden).to receive(:user) { user }
|
27
|
-
|
28
|
-
retval = described_class.extract(env_for('/', 'warden' => warden))
|
29
|
-
expect(retval).to be_a(described_class)
|
30
|
-
end
|
31
|
-
|
32
|
-
context "and the warden user is nil" do
|
33
|
-
it "returns nil" do
|
34
|
-
warden = instance_double('Warden::Proxy')
|
35
|
-
allow(warden).to receive(:user) { nil }
|
36
|
-
|
37
|
-
retval = described_class.extract(env_for('/', 'warden' => warden))
|
38
|
-
expect(retval).to be_nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when the user was not found" do
|
44
|
-
it "returns nil" do
|
45
|
-
retval = described_class.extract(env_for('/'))
|
46
|
-
expect(retval).to be_nil
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when the current_user Rails controller method is defined" do
|
51
|
-
let(:controller) { instance_double('DummyController') }
|
52
|
-
let(:env) { env_for('/', 'action_controller.instance' => controller) }
|
53
|
-
|
54
|
-
context "and it is nil" do
|
55
|
-
it "returns nil" do
|
56
|
-
allow(controller).to receive(:current_user) { nil }
|
57
|
-
|
58
|
-
retval = described_class.extract(env)
|
59
|
-
expect(retval).to be_nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "and it is not nil" do
|
64
|
-
it "returns the wrapped user" do
|
65
|
-
allow(controller).to receive(:current_user) { user }
|
66
|
-
|
67
|
-
retval = described_class.extract(env)
|
68
|
-
expect(retval).to be_a(described_class)
|
69
|
-
end
|
70
|
-
|
71
|
-
context "but it requires parameters" do
|
72
|
-
let(:controller) { dummy_controller.new }
|
73
|
-
subject { described_class.extract(env) }
|
74
|
-
|
75
|
-
context ": current_user(a)" do
|
76
|
-
let(:dummy_controller) do
|
77
|
-
Class.new do
|
78
|
-
def current_user(_a)
|
79
|
-
"username"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
it { should be_nil }
|
85
|
-
end
|
86
|
-
|
87
|
-
context ": current_user(a, b)" do
|
88
|
-
let(:dummy_controller) do
|
89
|
-
Class.new do
|
90
|
-
def current_user(_a, _b)
|
91
|
-
"username"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it { should be_nil }
|
97
|
-
end
|
98
|
-
|
99
|
-
context ": current_user(a, *b)" do
|
100
|
-
let(:dummy_controller) do
|
101
|
-
Class.new do
|
102
|
-
def current_user(_a, *_b)
|
103
|
-
"username"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
it { should be_nil }
|
109
|
-
end
|
110
|
-
|
111
|
-
context ": current_user(a, b, *c, &d)" do
|
112
|
-
let(:dummy_controller) do
|
113
|
-
Class.new do
|
114
|
-
def current_user(_a, _b, *_c, &_d)
|
115
|
-
"username"
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
it { should be_nil }
|
121
|
-
end
|
122
|
-
|
123
|
-
context ": current_user(*a)" do
|
124
|
-
let(:dummy_controller) do
|
125
|
-
Class.new do
|
126
|
-
def current_user(*_a)
|
127
|
-
"username"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
it { should be_a(described_class) }
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'and it is a private method' do
|
138
|
-
context "and it is not nil" do
|
139
|
-
let(:dummy_controller) do
|
140
|
-
Class.new do
|
141
|
-
private
|
142
|
-
|
143
|
-
def current_user
|
144
|
-
"username"
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
let(:controller) { dummy_controller.new }
|
150
|
-
|
151
|
-
it "returns the wrapped user" do
|
152
|
-
retval = described_class.extract(env)
|
153
|
-
expect(retval).to be_a(described_class)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "#as_json" do
|
161
|
-
context "when Rack user contains all expect fields" do
|
162
|
-
let(:user_data) { described_class.new(user).as_json[:user] }
|
163
|
-
|
164
|
-
it "contains the 'id' key" do
|
165
|
-
expect(user_data).to include(:id)
|
166
|
-
end
|
167
|
-
|
168
|
-
it "contains the 'name' key" do
|
169
|
-
expect(user_data).to include(:name)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "contains the 'username' key" do
|
173
|
-
expect(user_data).to include(:username)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "contains the 'email' key" do
|
177
|
-
expect(user_data).to include(:email)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
context "when Rack user doesn't contain any of the expect fields" do
|
182
|
-
let(:user_data) { described_class.new(OpenStruct.new).as_json }
|
183
|
-
|
184
|
-
it "is empty" do
|
185
|
-
expect(user_data).to be_empty
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context "when Rack user's field expects a parameter" do
|
190
|
-
let(:user_data) do
|
191
|
-
described_class.new(
|
192
|
-
Class.new do
|
193
|
-
def name(required_param)
|
194
|
-
"my name is #{required_param}"
|
195
|
-
end
|
196
|
-
|
197
|
-
def id(required_param, *optional_params)
|
198
|
-
"id is #{required_param} #{optional_params.inspect}"
|
199
|
-
end
|
200
|
-
|
201
|
-
def username(*optional_params)
|
202
|
-
"username is #{optional_params.inspect}"
|
203
|
-
end
|
204
|
-
end.new
|
205
|
-
).as_json
|
206
|
-
end
|
207
|
-
|
208
|
-
it "does not call the method if it has required parameters" do
|
209
|
-
expect(user_data[:user]).not_to include(:id)
|
210
|
-
expect(user_data[:user]).not_to include(:name)
|
211
|
-
end
|
212
|
-
|
213
|
-
it "calls the method if it has a variable number of optional parameters" do
|
214
|
-
expect(user_data[:user]).to include(:username)
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'airbrake/rails/action_cable/notify_callback'
|
2
|
-
|
3
|
-
RSpec.describe Airbrake::Rails::ActionCable::NotifyCallback do
|
4
|
-
describe ".call" do
|
5
|
-
context "when block raises exception" do
|
6
|
-
let(:channel) { double }
|
7
|
-
let(:block) { proc { raise AirbrakeTestError } }
|
8
|
-
|
9
|
-
before do
|
10
|
-
expect(channel).to receive(:channel_name).and_return('web_notifications')
|
11
|
-
end
|
12
|
-
|
13
|
-
it "notifies Airbrake" do
|
14
|
-
expect(Airbrake).to(
|
15
|
-
receive(:notify).with(an_instance_of(Airbrake::Notice))
|
16
|
-
) do |notice|
|
17
|
-
expect(notice[:context][:component]).to eq('action_cable')
|
18
|
-
expect(notice[:context][:action]).to eq('web_notifications')
|
19
|
-
end
|
20
|
-
|
21
|
-
expect { described_class.call(channel, block) }
|
22
|
-
.to raise_error(AirbrakeTestError)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'airbrake/rails/action_controller_notify_subscriber'
|
2
|
-
|
3
|
-
RSpec.describe Airbrake::Rails::ActionControllerNotifySubscriber do
|
4
|
-
after { Airbrake::Rack::RequestStore.clear }
|
5
|
-
|
6
|
-
describe "#call" do
|
7
|
-
let(:event) { double(Airbrake::Rails::Event) }
|
8
|
-
|
9
|
-
before do
|
10
|
-
allow(Airbrake::Rails::Event).to receive(:new).and_return(event)
|
11
|
-
end
|
12
|
-
|
13
|
-
context "when there are no routes in the request store" do
|
14
|
-
it "doesn't notify requests" do
|
15
|
-
expect(Airbrake).not_to receive(:notify_request)
|
16
|
-
subject.call([])
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when there's a route in the request store" do
|
21
|
-
before do
|
22
|
-
Airbrake::Rack::RequestStore[:routes] = {
|
23
|
-
'/test-route' => { method: 'GET', response_type: :html }
|
24
|
-
}
|
25
|
-
|
26
|
-
expect(event).to receive(:method).and_return('GET')
|
27
|
-
expect(event).to receive(:status_code).and_return(200)
|
28
|
-
expect(event).to receive(:time).and_return(Time.now)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "sends request info to Airbrake" do
|
32
|
-
expect(Airbrake).to receive(:notify_request).with(
|
33
|
-
hash_including(
|
34
|
-
method: 'GET',
|
35
|
-
route: '/test-route',
|
36
|
-
status_code: 200
|
37
|
-
)
|
38
|
-
)
|
39
|
-
subject.call([])
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|