airbrake-ruby 2.9.0 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/airbrake-ruby.rb +40 -18
- data/lib/airbrake-ruby/async_sender.rb +0 -6
- data/lib/airbrake-ruby/backtrace.rb +0 -10
- data/lib/airbrake-ruby/code_hunk.rb +0 -4
- data/lib/airbrake-ruby/config.rb +23 -22
- data/lib/airbrake-ruby/config/validator.rb +0 -10
- data/lib/airbrake-ruby/file_cache.rb +0 -6
- data/lib/airbrake-ruby/filter_chain.rb +0 -5
- data/lib/airbrake-ruby/filters/context_filter.rb +1 -0
- data/lib/airbrake-ruby/filters/dependency_filter.rb +31 -0
- data/lib/airbrake-ruby/filters/exception_attributes_filter.rb +45 -0
- data/lib/airbrake-ruby/filters/gem_root_filter.rb +2 -3
- data/lib/airbrake-ruby/filters/keys_blacklist.rb +1 -2
- data/lib/airbrake-ruby/filters/keys_filter.rb +9 -14
- data/lib/airbrake-ruby/filters/keys_whitelist.rb +0 -2
- data/lib/airbrake-ruby/filters/root_directory_filter.rb +2 -3
- data/lib/airbrake-ruby/filters/system_exit_filter.rb +2 -3
- data/lib/airbrake-ruby/filters/thread_filter.rb +2 -4
- data/lib/airbrake-ruby/nested_exception.rb +0 -2
- data/lib/airbrake-ruby/notice.rb +6 -44
- data/lib/airbrake-ruby/notifier.rb +4 -40
- data/lib/airbrake-ruby/promise.rb +0 -6
- data/lib/airbrake-ruby/response.rb +0 -4
- data/lib/airbrake-ruby/sync_sender.rb +0 -4
- data/lib/airbrake-ruby/version.rb +1 -3
- data/spec/airbrake_spec.rb +71 -140
- data/spec/async_sender_spec.rb +9 -0
- data/spec/config_spec.rb +4 -0
- data/spec/filters/dependency_filter_spec.rb +16 -0
- data/spec/filters/exception_attributes_filter_spec.rb +65 -0
- data/spec/filters/keys_whitelist_spec.rb +17 -23
- data/spec/notice_spec.rb +111 -69
- data/spec/notifier_spec.rb +304 -495
- data/spec/response_spec.rb +82 -0
- data/spec/sync_sender_spec.rb +31 -14
- metadata +10 -2
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Airbrake::Response do
|
4
|
+
describe ".parse" do
|
5
|
+
let(:out) { StringIO.new }
|
6
|
+
let(:logger) { Logger.new(out) }
|
7
|
+
|
8
|
+
context "when response code is 201" do
|
9
|
+
it "logs response body" do
|
10
|
+
described_class.parse(OpenStruct.new(code: 201, body: '{}'), logger)
|
11
|
+
expect(out.string).to match(/Airbrake: {}/)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
[400, 401, 403, 420].each do |code|
|
16
|
+
context "when response code is #{code}" do
|
17
|
+
it "logs response message" do
|
18
|
+
described_class.parse(
|
19
|
+
OpenStruct.new(code: code, body: '{"message":"foo"}'), logger
|
20
|
+
)
|
21
|
+
expect(out.string).to match(/Airbrake: foo/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when response code is 429" do
|
27
|
+
let(:response) { OpenStruct.new(code: 429, body: '{"message":"rate limited"}') }
|
28
|
+
it "logs response message" do
|
29
|
+
described_class.parse(response, logger)
|
30
|
+
expect(out.string).to match(/Airbrake: rate limited/)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns an error response" do
|
34
|
+
time = Time.now
|
35
|
+
allow(Time).to receive(:now).and_return(time)
|
36
|
+
|
37
|
+
resp = described_class.parse(response, logger)
|
38
|
+
expect(resp).to include(
|
39
|
+
'error' => '**Airbrake: rate limited',
|
40
|
+
'rate_limit_reset' => time
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when response code is unhandled" do
|
46
|
+
let(:response) { OpenStruct.new(code: 500, body: 'foo') }
|
47
|
+
|
48
|
+
it "logs response body" do
|
49
|
+
described_class.parse(response, logger)
|
50
|
+
expect(out.string).to match(/Airbrake: unexpected code \(500\)\. Body: foo/)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns an error response" do
|
54
|
+
resp = described_class.parse(response, logger)
|
55
|
+
expect(resp).to eq('error' => 'foo')
|
56
|
+
end
|
57
|
+
|
58
|
+
it "truncates body" do
|
59
|
+
response.body *= 1000
|
60
|
+
resp = described_class.parse(response, logger)
|
61
|
+
expect(resp).to eq('error' => ('foo' * 33) + 'fo...')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when response body can't be parsed as JSON" do
|
66
|
+
let(:response) { OpenStruct.new(code: 201, body: 'foo') }
|
67
|
+
|
68
|
+
it "logs response body" do
|
69
|
+
described_class.parse(response, logger)
|
70
|
+
expect(out.string).to match(
|
71
|
+
/Airbrake: error while parsing body \(.*unexpected token.*\)\. Body: foo/
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns an error message" do
|
76
|
+
expect(described_class.parse(response, logger)['error']).to match(
|
77
|
+
/\A#<JSON::ParserError.+>/
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/sync_sender_spec.rb
CHANGED
@@ -25,31 +25,48 @@ RSpec.describe Airbrake::SyncSender do
|
|
25
25
|
|
26
26
|
let(:sender) { described_class.new(config) }
|
27
27
|
let(:notice) { Airbrake::Notice.new(config, AirbrakeTestError.new) }
|
28
|
+
let(:endpoint) { 'https://airbrake.io/api/v3/projects/1/notices' }
|
28
29
|
|
29
|
-
|
30
|
-
https = double("foo")
|
31
|
-
allow(sender).to receive(:build_https).and_return(https)
|
32
|
-
allow(https).to receive(:request).and_raise(StandardError.new('foo'))
|
33
|
-
expect(sender.send(notice, promise)).to be_an(Airbrake::Promise)
|
34
|
-
expect(promise.value).to eq('error' => '**Airbrake: HTTP error: foo')
|
35
|
-
expect(stdout.string).to match(/ERROR -- : .+ HTTP error: foo/)
|
36
|
-
end
|
30
|
+
before { stub_request(:post, endpoint).to_return(body: '{}') }
|
37
31
|
|
38
|
-
it "
|
39
|
-
stub_request(:post, 'https://airbrake.io/api/v3/projects/1/notices').
|
40
|
-
to_return(body: '{}')
|
32
|
+
it "sets the Content-Type header to JSON" do
|
41
33
|
sender.send(notice, promise)
|
34
|
+
expect(
|
35
|
+
a_request(:post, endpoint).with(
|
36
|
+
headers: { 'Content-Type' => 'application/json' }
|
37
|
+
)
|
38
|
+
).to have_been_made.once
|
39
|
+
end
|
42
40
|
|
41
|
+
it "sets the User-Agent header to the notifier slug" do
|
42
|
+
sender.send(notice, promise)
|
43
43
|
expect(
|
44
|
-
a_request(:post,
|
44
|
+
a_request(:post, endpoint).with(
|
45
45
|
headers: {
|
46
|
-
'
|
47
|
-
'Content-Type' => 'application/json'
|
46
|
+
'User-Agent' => %r{airbrake-ruby/\d+\.\d+\.\d+ Ruby/\d+\.\d+\.\d+}
|
48
47
|
}
|
49
48
|
)
|
50
49
|
).to have_been_made.once
|
51
50
|
end
|
52
51
|
|
52
|
+
it "sets the Authorization header to the project key" do
|
53
|
+
sender.send(notice, promise)
|
54
|
+
expect(
|
55
|
+
a_request(:post, endpoint).with(
|
56
|
+
headers: { 'Authorization' => 'Bearer banana' }
|
57
|
+
)
|
58
|
+
).to have_been_made.once
|
59
|
+
end
|
60
|
+
|
61
|
+
it "catches exceptions raised while sending" do
|
62
|
+
https = double("foo")
|
63
|
+
allow(sender).to receive(:build_https).and_return(https)
|
64
|
+
allow(https).to receive(:request).and_raise(StandardError.new('foo'))
|
65
|
+
expect(sender.send(notice, promise)).to be_an(Airbrake::Promise)
|
66
|
+
expect(promise.value).to eq('error' => '**Airbrake: HTTP error: foo')
|
67
|
+
expect(stdout.string).to match(/ERROR -- : .+ HTTP error: foo/)
|
68
|
+
end
|
69
|
+
|
53
70
|
context "when request body is nil" do
|
54
71
|
it "doesn't send a notice" do
|
55
72
|
expect_any_instance_of(Airbrake::Truncator).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airbrake-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.10.0
|
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: 2018-
|
11
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -124,6 +124,8 @@ files:
|
|
124
124
|
- lib/airbrake-ruby/file_cache.rb
|
125
125
|
- lib/airbrake-ruby/filter_chain.rb
|
126
126
|
- lib/airbrake-ruby/filters/context_filter.rb
|
127
|
+
- lib/airbrake-ruby/filters/dependency_filter.rb
|
128
|
+
- lib/airbrake-ruby/filters/exception_attributes_filter.rb
|
127
129
|
- lib/airbrake-ruby/filters/gem_root_filter.rb
|
128
130
|
- lib/airbrake-ruby/filters/keys_blacklist.rb
|
129
131
|
- lib/airbrake-ruby/filters/keys_filter.rb
|
@@ -148,6 +150,8 @@ files:
|
|
148
150
|
- spec/file_cache.rb
|
149
151
|
- spec/filter_chain_spec.rb
|
150
152
|
- spec/filters/context_filter_spec.rb
|
153
|
+
- spec/filters/dependency_filter_spec.rb
|
154
|
+
- spec/filters/exception_attributes_filter_spec.rb
|
151
155
|
- spec/filters/gem_root_filter_spec.rb
|
152
156
|
- spec/filters/keys_blacklist_spec.rb
|
153
157
|
- spec/filters/keys_whitelist_spec.rb
|
@@ -166,6 +170,7 @@ files:
|
|
166
170
|
- spec/notifier_spec.rb
|
167
171
|
- spec/notifier_spec/options_spec.rb
|
168
172
|
- spec/promise_spec.rb
|
173
|
+
- spec/response_spec.rb
|
169
174
|
- spec/spec_helper.rb
|
170
175
|
- spec/sync_sender_spec.rb
|
171
176
|
- spec/truncator_spec.rb
|
@@ -196,10 +201,12 @@ summary: Ruby notifier for https://airbrake.io
|
|
196
201
|
test_files:
|
197
202
|
- spec/truncator_spec.rb
|
198
203
|
- spec/helpers.rb
|
204
|
+
- spec/filters/exception_attributes_filter_spec.rb
|
199
205
|
- spec/filters/root_directory_filter_spec.rb
|
200
206
|
- spec/filters/keys_whitelist_spec.rb
|
201
207
|
- spec/filters/system_exit_filter_spec.rb
|
202
208
|
- spec/filters/thread_filter_spec.rb
|
209
|
+
- spec/filters/dependency_filter_spec.rb
|
203
210
|
- spec/filters/context_filter_spec.rb
|
204
211
|
- spec/filters/keys_blacklist_spec.rb
|
205
212
|
- spec/filters/gem_root_filter_spec.rb
|
@@ -215,6 +222,7 @@ test_files:
|
|
215
222
|
- spec/notifier_spec.rb
|
216
223
|
- spec/nested_exception_spec.rb
|
217
224
|
- spec/filter_chain_spec.rb
|
225
|
+
- spec/response_spec.rb
|
218
226
|
- spec/file_cache.rb
|
219
227
|
- spec/code_hunk_spec.rb
|
220
228
|
- spec/fixtures/notroot.txt
|