airbrake 5.6.1 → 5.7.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/airbrake.rb +26 -2
  3. data/lib/airbrake/delayed_job/plugin.rb +6 -5
  4. data/lib/airbrake/rack/context_filter.rb +52 -0
  5. data/lib/airbrake/rack/http_headers_filter.rb +38 -0
  6. data/lib/airbrake/rack/http_params_filter.rb +20 -0
  7. data/lib/airbrake/rack/middleware.rb +30 -1
  8. data/lib/airbrake/rack/request_body_filter.rb +30 -0
  9. data/lib/airbrake/rack/session_filter.rb +18 -0
  10. data/lib/airbrake/rack/user.rb +5 -3
  11. data/lib/airbrake/rails/action_controller.rb +10 -8
  12. data/lib/airbrake/resque/failure.rb +4 -5
  13. data/lib/airbrake/sidekiq/error_handler.rb +5 -2
  14. data/lib/airbrake/version.rb +1 -1
  15. data/lib/generators/airbrake_initializer.rb.erb +2 -4
  16. data/spec/apps/rails/dummy_app.rb +1 -2
  17. data/spec/apps/rails/logs/32.log +639 -0
  18. data/spec/apps/rails/logs/40.log +1 -0
  19. data/spec/apps/rails/logs/41.log +1 -0
  20. data/spec/apps/rails/logs/42.log +1000 -0
  21. data/spec/apps/rails/logs/50.log +10 -465
  22. data/spec/integration/rails/rails_spec.rb +15 -14
  23. data/spec/spec_helper.rb +17 -18
  24. data/spec/unit/airbrake_spec.rb +65 -0
  25. data/spec/unit/rack/context_filter_spec.rb +70 -0
  26. data/spec/unit/rack/http_headers_filter_spec.rb +48 -0
  27. data/spec/unit/rack/http_params_filter_spec.rb +56 -0
  28. data/spec/unit/rack/request_body_filter_spec.rb +48 -0
  29. data/spec/unit/rack/session_filter_spec.rb +48 -0
  30. metadata +63 -17
  31. data/lib/airbrake/rack/notice_builder.rb +0 -127
  32. data/spec/airbrake_spec.rb +0 -17
  33. data/spec/apps/rails/logs/51.log +0 -1405
  34. data/spec/unit/rack/notice_builder_spec.rb +0 -157
@@ -1,157 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Airbrake::Rack::NoticeBuilder do
4
- def env_for(url, opts = {})
5
- Rack::MockRequest.env_for(url, opts)
6
- end
7
-
8
- describe "#build_notice" do
9
- it "doesn't overwrite the session key with nil" do
10
- notice_builder = described_class.new(env_for('/', 'rack.session' => nil))
11
- notice = notice_builder.build_notice(AirbrakeTestError.new)
12
-
13
- expect(notice[:session]).to eq({})
14
- end
15
-
16
- it "sets session if it is present" do
17
- session = { a: 1, b: 2 }
18
- notice_builder = described_class.new(env_for('/', 'rack.session' => session))
19
- notice = notice_builder.build_notice(AirbrakeTestError.new)
20
-
21
- expect(notice[:session]).to eq(session)
22
- end
23
-
24
- it "doesn't overwrite the params key with nil" do
25
- notice_builder = described_class.new(env_for('/'))
26
- notice = notice_builder.build_notice(AirbrakeTestError.new)
27
-
28
- expect(notice[:session]).to eq({})
29
- end
30
-
31
- it "sets form params if they're present" do
32
- params = { a: 1, b: 2 }
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
- )
40
- notice = notice_builder.build_notice(AirbrakeTestError.new)
41
-
42
- expect(notice[:params]).to eq(params)
43
- end
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
-
52
- it "adds CONTENT_TYPE, CONTENT_LENGTH and HTTP_* headers in the environment" do
53
- headers = {
54
- "HTTP_HOST" => "example.com",
55
- "CONTENT_TYPE" => "text/html",
56
- "CONTENT_LENGTH" => 100500
57
- }
58
- notice_builder = described_class.new(env_for('/', headers.dup))
59
- notice = notice_builder.build_notice(AirbrakeTestError.new)
60
- expect(notice[:environment][:headers]).to eq(headers)
61
- end
62
-
63
- it "skips headers that were not selected to be stored in the environment" do
64
- headers = {
65
- "HTTP_HOST" => "example.com",
66
- "CONTENT_TYPE" => "text/html",
67
- "CONTENT_LENGTH" => 100500
68
- }
69
- notice_builder = described_class.new(
70
- env_for('/', headers.merge("X-SOME-HEADER" => "value"))
71
- )
72
- notice = notice_builder.build_notice(AirbrakeTestError.new)
73
-
74
- expect(notice[:environment][:headers]).to eq(headers)
75
- end
76
-
77
- it "preserves data that already has been added to the environment" do
78
- headers = {
79
- "HTTP_HOST" => "example.com",
80
- "CONTENT_TYPE" => "text/html",
81
- "CONTENT_LENGTH" => 100500
82
- }
83
- allow(Airbrake).to receive(:build_notice).and_wrap_original do |method, *args|
84
- notice = method.call(*args)
85
- notice[:environment]["SOME_KEY"] = "SOME_VALUE"
86
- notice
87
- end
88
- notice_builder = described_class.new(env_for('/', headers))
89
- notice = notice_builder.build_notice(AirbrakeTestError.new)
90
-
91
- expect(notice[:environment]["SOME_KEY"]).to eq("SOME_VALUE")
92
- end
93
-
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")
110
- end
111
- end
112
-
113
- context "when Airbrake is not configured" do
114
- it "returns nil" do
115
- allow(Airbrake).to receive(:build_notice).and_return(nil)
116
- notice_builder = described_class.new(env_for('/', 'bingo' => 'bango'))
117
-
118
- expect(notice_builder.build_notice('bongo')).to be_nil
119
- expect(Airbrake).to have_received(:build_notice)
120
- end
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
156
- end
157
- end