airbrake 3.1.6 → 11.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. data/lib/airbrake.rb +23 -150
  3. data/lib/airbrake/capistrano.rb +6 -42
  4. data/lib/airbrake/capistrano/capistrano2.rb +40 -0
  5. data/lib/airbrake/capistrano/capistrano3.rb +23 -0
  6. data/lib/airbrake/delayed_job.rb +66 -0
  7. data/lib/airbrake/logger.rb +103 -0
  8. data/lib/airbrake/rack.rb +30 -45
  9. data/lib/airbrake/rack/context_filter.rb +65 -0
  10. data/lib/airbrake/rack/http_headers_filter.rb +44 -0
  11. data/lib/airbrake/rack/http_params_filter.rb +27 -0
  12. data/lib/airbrake/rack/instrumentable.rb +136 -0
  13. data/lib/airbrake/rack/middleware.rb +102 -0
  14. data/lib/airbrake/rack/request_body_filter.rb +33 -0
  15. data/lib/airbrake/rack/request_store.rb +34 -0
  16. data/lib/airbrake/rack/route_filter.rb +51 -0
  17. data/lib/airbrake/rack/session_filter.rb +25 -0
  18. data/lib/airbrake/rack/user.rb +74 -0
  19. data/lib/airbrake/rack/user_filter.rb +25 -0
  20. data/lib/airbrake/rails.rb +25 -31
  21. data/lib/airbrake/rails/action_cable.rb +35 -0
  22. data/lib/airbrake/rails/action_cable/notify_callback.rb +22 -0
  23. data/lib/airbrake/rails/action_controller.rb +40 -0
  24. data/lib/airbrake/rails/action_controller_notify_subscriber.rb +32 -0
  25. data/lib/airbrake/rails/action_controller_performance_breakdown_subscriber.rb +51 -0
  26. data/lib/airbrake/rails/action_controller_route_subscriber.rb +33 -0
  27. data/lib/airbrake/rails/active_job.rb +50 -0
  28. data/lib/airbrake/rails/active_record.rb +36 -0
  29. data/lib/airbrake/rails/active_record_subscriber.rb +46 -0
  30. data/lib/airbrake/rails/app.rb +78 -0
  31. data/lib/airbrake/rails/backtrace_cleaner.rb +23 -0
  32. data/lib/airbrake/rails/curb.rb +32 -0
  33. data/lib/airbrake/rails/event.rb +81 -0
  34. data/lib/airbrake/rails/excon_subscriber.rb +25 -0
  35. data/lib/airbrake/rails/http.rb +14 -0
  36. data/lib/airbrake/rails/http_client.rb +16 -0
  37. data/lib/airbrake/rails/net_http.rb +18 -0
  38. data/lib/airbrake/rails/railtie.rb +151 -0
  39. data/lib/airbrake/rails/typhoeus.rb +16 -0
  40. data/lib/airbrake/rake.rb +65 -0
  41. data/lib/airbrake/rake/tasks.rb +112 -0
  42. data/lib/airbrake/resque.rb +61 -0
  43. data/lib/airbrake/shoryuken.rb +54 -0
  44. data/lib/airbrake/sidekiq.rb +55 -0
  45. data/lib/airbrake/sidekiq/retryable_jobs_filter.rb +53 -0
  46. data/lib/airbrake/sneakers.rb +72 -0
  47. data/lib/airbrake/version.rb +5 -1
  48. data/lib/generators/airbrake_generator.rb +25 -0
  49. data/lib/generators/airbrake_initializer.rb.erb +80 -0
  50. metadata +206 -259
  51. data/CHANGELOG +0 -944
  52. data/Gemfile +0 -3
  53. data/Guardfile +0 -6
  54. data/INSTALL +0 -20
  55. data/MIT-LICENSE +0 -22
  56. data/README.md +0 -556
  57. data/README_FOR_HEROKU_ADDON.md +0 -94
  58. data/Rakefile +0 -223
  59. data/SUPPORTED_RAILS_VERSIONS +0 -38
  60. data/TESTING.md +0 -41
  61. data/airbrake.gemspec +0 -40
  62. data/bin/airbrake +0 -12
  63. data/features/metal.feature +0 -18
  64. data/features/rack.feature +0 -60
  65. data/features/rails.feature +0 -272
  66. data/features/rails_with_js_notifier.feature +0 -97
  67. data/features/rake.feature +0 -27
  68. data/features/sinatra.feature +0 -29
  69. data/features/step_definitions/file_steps.rb +0 -10
  70. data/features/step_definitions/metal_steps.rb +0 -23
  71. data/features/step_definitions/rack_steps.rb +0 -23
  72. data/features/step_definitions/rails_application_steps.rb +0 -478
  73. data/features/step_definitions/rake_steps.rb +0 -17
  74. data/features/support/airbrake_shim.rb.template +0 -16
  75. data/features/support/env.rb +0 -18
  76. data/features/support/matchers.rb +0 -35
  77. data/features/support/rails.rb +0 -201
  78. data/features/support/rake/Rakefile +0 -68
  79. data/features/support/terminal.rb +0 -107
  80. data/features/user_informer.feature +0 -63
  81. data/generators/airbrake/airbrake_generator.rb +0 -94
  82. data/generators/airbrake/lib/insert_commands.rb +0 -34
  83. data/generators/airbrake/lib/rake_commands.rb +0 -24
  84. data/generators/airbrake/templates/airbrake_tasks.rake +0 -25
  85. data/generators/airbrake/templates/capistrano_hook.rb +0 -6
  86. data/generators/airbrake/templates/initializer.rb +0 -6
  87. data/install.rb +0 -1
  88. data/lib/airbrake/backtrace.rb +0 -108
  89. data/lib/airbrake/cli/client.rb +0 -68
  90. data/lib/airbrake/cli/options.rb +0 -41
  91. data/lib/airbrake/cli/printer.rb +0 -30
  92. data/lib/airbrake/cli/project.rb +0 -17
  93. data/lib/airbrake/cli/project_factory.rb +0 -36
  94. data/lib/airbrake/cli/runner.rb +0 -48
  95. data/lib/airbrake/cli/validator.rb +0 -8
  96. data/lib/airbrake/configuration.rb +0 -311
  97. data/lib/airbrake/extensions/blank.rb +0 -73
  98. data/lib/airbrake/notice.rb +0 -390
  99. data/lib/airbrake/rails/action_controller_catcher.rb +0 -30
  100. data/lib/airbrake/rails/controller_methods.rb +0 -87
  101. data/lib/airbrake/rails/error_lookup.rb +0 -33
  102. data/lib/airbrake/rails/javascript_notifier.rb +0 -47
  103. data/lib/airbrake/rails/middleware/exceptions_catcher.rb +0 -33
  104. data/lib/airbrake/rails3_tasks.rb +0 -98
  105. data/lib/airbrake/railtie.rb +0 -48
  106. data/lib/airbrake/rake_handler.rb +0 -71
  107. data/lib/airbrake/sender.rb +0 -128
  108. data/lib/airbrake/shared_tasks.rb +0 -47
  109. data/lib/airbrake/tasks.rb +0 -83
  110. data/lib/airbrake/user_informer.rb +0 -27
  111. data/lib/airbrake_tasks.rb +0 -64
  112. data/lib/rails/generators/airbrake/airbrake_generator.rb +0 -100
  113. data/lib/templates/javascript_notifier.erb +0 -15
  114. data/lib/templates/rescue.erb +0 -91
  115. data/rails/init.rb +0 -1
  116. data/resources/README.md +0 -34
  117. data/resources/ca-bundle.crt +0 -3376
  118. data/script/integration_test.rb +0 -38
  119. data/test/airbrake_2_3.xsd +0 -88
  120. data/test/airbrake_tasks_test.rb +0 -170
  121. data/test/backtrace_test.rb +0 -162
  122. data/test/capistrano_test.rb +0 -34
  123. data/test/catcher_test.rb +0 -333
  124. data/test/configuration_test.rb +0 -233
  125. data/test/helper.rb +0 -263
  126. data/test/javascript_notifier_test.rb +0 -51
  127. data/test/logger_test.rb +0 -79
  128. data/test/notice_test.rb +0 -490
  129. data/test/notifier_test.rb +0 -276
  130. data/test/rack_test.rb +0 -58
  131. data/test/rails_initializer_test.rb +0 -36
  132. data/test/recursion_test.rb +0 -10
  133. data/test/sender_test.rb +0 -288
  134. data/test/user_informer_test.rb +0 -29
@@ -1,276 +0,0 @@
1
- require File.expand_path '../helper', __FILE__
2
-
3
- class NotifierTest < Test::Unit::TestCase
4
-
5
- class OriginalException < Exception
6
- end
7
-
8
- class ContinuedException < Exception
9
- end
10
-
11
- include DefinesConstants
12
-
13
- def setup
14
- super
15
- reset_config
16
- end
17
-
18
- def assert_sent(notice, notice_args)
19
- assert_received(Airbrake::Notice, :new) {|expect| expect.with(has_entries(notice_args)) }
20
- assert_received(Airbrake.sender, :send_to_airbrake) {|expect| expect.with(notice) }
21
- end
22
-
23
- def set_public_env
24
- Airbrake.configure { |config| config.environment_name = 'production' }
25
- end
26
-
27
- def set_development_env
28
- Airbrake.configure { |config| config.environment_name = 'development' }
29
- end
30
-
31
- should "yield and save a configuration when configuring" do
32
- yielded_configuration = nil
33
- Airbrake.configure do |config|
34
- yielded_configuration = config
35
- end
36
-
37
- assert_kind_of Airbrake::Configuration, yielded_configuration
38
- assert_equal yielded_configuration, Airbrake.configuration
39
- end
40
-
41
- should "not remove existing config options when configuring twice" do
42
- first_config = nil
43
- Airbrake.configure do |config|
44
- first_config = config
45
- end
46
- Airbrake.configure do |config|
47
- assert_equal first_config, config
48
- end
49
- end
50
-
51
- should "configure the sender" do
52
- sender = stub_sender
53
- Airbrake::Sender.stubs(:new => sender)
54
- configuration = nil
55
-
56
- Airbrake.configure { |yielded_config| configuration = yielded_config }
57
-
58
- assert_received(Airbrake::Sender, :new) { |expect| expect.with(configuration) }
59
- assert_equal sender, Airbrake.sender
60
- end
61
-
62
- should "create and send a notice for an exception" do
63
- set_public_env
64
- exception = build_exception
65
- stub_sender!
66
- notice = stub_notice!
67
-
68
- Airbrake.notify(exception)
69
-
70
- assert_sent notice, :exception => exception
71
- end
72
-
73
- should "create and send a notice for a hash" do
74
- set_public_env
75
- notice = stub_notice!
76
- notice_args = { :error_message => 'uh oh' }
77
- stub_sender!
78
-
79
- Airbrake.notify(notice_args)
80
-
81
- assert_sent(notice, notice_args)
82
- end
83
-
84
- should "not pass the hash as an exception when sending a notice for it" do
85
- set_public_env
86
- notice = stub_notice!
87
- notice_args = { :error_message => 'uh oh' }
88
- stub_sender!
89
-
90
- Airbrake.notify(notice_args)
91
-
92
- assert_received(Airbrake::Notice, :new) {|expect| expect.with(Not(has_key(:exception))) }
93
- end
94
-
95
- should "create and send a notice for an exception that responds to to_hash" do
96
- set_public_env
97
- exception = build_exception
98
- notice = stub_notice!
99
- notice_args = { :error_message => 'uh oh' }
100
- exception.stubs(:to_hash).returns(notice_args)
101
- stub_sender!
102
-
103
- Airbrake.notify(exception)
104
-
105
- assert_sent(notice, notice_args.merge(:exception => exception))
106
- end
107
-
108
- should "create and sent a notice for an exception and hash" do
109
- set_public_env
110
- exception = build_exception
111
- notice = stub_notice!
112
- notice_args = { :error_message => 'uh oh' }
113
- stub_sender!
114
-
115
- Airbrake.notify(exception, notice_args)
116
-
117
- assert_sent(notice, notice_args.merge(:exception => exception))
118
- end
119
-
120
- should "not create a notice in a development environment" do
121
- set_development_env
122
- sender = stub_sender!
123
-
124
- Airbrake.notify(build_exception)
125
- Airbrake.notify_or_ignore(build_exception)
126
-
127
- assert_received(sender, :send_to_airbrake) {|expect| expect.never }
128
- end
129
-
130
- should "not deliver an ignored exception when notifying implicitly" do
131
- set_public_env
132
- exception = build_exception
133
- sender = stub_sender!
134
- notice = stub_notice!
135
- notice.stubs(:ignore? => true)
136
-
137
- Airbrake.notify_or_ignore(exception)
138
-
139
- assert_received(sender, :send_to_airbrake) {|expect| expect.never }
140
- end
141
-
142
- should "deliver exception in async-mode" do
143
- Airbrake.configure do |config|
144
- config.environment_name = 'production'
145
- config.async do |notice|
146
- Airbrake.sender.send_to_airbrake(notice)
147
- end
148
- end
149
- exception = build_exception
150
- sender = stub_sender!
151
- notice = stub_notice!
152
-
153
- Airbrake.notify(exception)
154
-
155
- assert_sent(notice, :exception => exception)
156
- end
157
-
158
- should "pass notice in async-mode" do
159
- received_notice = nil
160
- Airbrake.configure do |config|
161
- config.environment_name = 'production'
162
- config.async {|notice| received_notice = notice}
163
- end
164
- exception = build_exception
165
- sender = stub_sender!
166
- notice = stub_notice!
167
-
168
- Airbrake.notify(exception)
169
-
170
- assert_equal received_notice, notice
171
- end
172
-
173
- should "deliver an ignored exception when notifying manually" do
174
- set_public_env
175
- exception = build_exception
176
- sender = stub_sender!
177
- notice = stub_notice!
178
- notice.stubs(:ignore? => true)
179
-
180
- Airbrake.notify(exception)
181
-
182
- assert_sent(notice, :exception => exception)
183
- end
184
-
185
- should "pass config to created notices" do
186
- exception = build_exception
187
- config_opts = { 'one' => 'two', 'three' => 'four' }
188
- notice = stub_notice!
189
- stub_sender!
190
- Airbrake.configuration = stub('config', :merge => config_opts, :public? => true,:async? => nil)
191
-
192
- Airbrake.notify(exception)
193
-
194
- assert_received(Airbrake::Notice, :new) do |expect|
195
- expect.with(has_entries(config_opts))
196
- end
197
- end
198
-
199
- context "building notice JSON for an exception" do
200
- setup do
201
- @params = { :controller => "users", :action => "create" }
202
- @exception = build_exception
203
- @hash = Airbrake.build_lookup_hash_for(@exception, @params)
204
- end
205
-
206
- should "set action" do
207
- assert_equal @params[:action], @hash[:action]
208
- end
209
-
210
- should "set controller" do
211
- assert_equal @params[:controller], @hash[:component]
212
- end
213
-
214
- should "set line number" do
215
- assert @hash[:line_number] =~ /\d+/
216
- end
217
-
218
- should "set file" do
219
- assert_match /test\/helper\.rb$/, @hash[:file]
220
- end
221
-
222
- should "set rails_env to production" do
223
- assert_equal 'production', @hash[:environment_name]
224
- end
225
-
226
- should "set error class" do
227
- assert_equal @exception.class.to_s, @hash[:error_class]
228
- end
229
-
230
- should "not set file or line number with no backtrace" do
231
- @exception.stubs(:backtrace).returns([])
232
-
233
- @hash = Airbrake.build_lookup_hash_for(@exception)
234
-
235
- assert_nil @hash[:line_number]
236
- assert_nil @hash[:file]
237
- end
238
-
239
- should "not set action or controller when not provided" do
240
- @hash = Airbrake.build_lookup_hash_for(@exception)
241
-
242
- assert_nil @hash[:action]
243
- assert_nil @hash[:controller]
244
- end
245
-
246
- context "when an exception that provides #original_exception is raised" do
247
- setup do
248
- @exception.stubs(:original_exception).returns(begin
249
- raise NotifierTest::OriginalException.new
250
- rescue Exception => e
251
- e
252
- end)
253
- end
254
-
255
- should "unwrap exceptions that provide #original_exception" do
256
- @hash = Airbrake.build_lookup_hash_for(@exception)
257
- assert_equal "NotifierTest::OriginalException", @hash[:error_class]
258
- end
259
- end
260
-
261
- context "when an exception that provides #continued_exception is raised" do
262
- setup do
263
- @exception.stubs(:continued_exception).returns(begin
264
- raise NotifierTest::ContinuedException.new
265
- rescue Exception => e
266
- e
267
- end)
268
- end
269
-
270
- should "unwrap exceptions that provide #continued_exception" do
271
- @hash = Airbrake.build_lookup_hash_for(@exception)
272
- assert_equal "NotifierTest::ContinuedException", @hash[:error_class]
273
- end
274
- end
275
- end
276
- end
@@ -1,58 +0,0 @@
1
- require File.expand_path '../helper', __FILE__
2
-
3
- class RackTest < Test::Unit::TestCase
4
-
5
- should "call the upstream app with the environment" do
6
- environment = { 'key' => 'value' }
7
- app = lambda { |env| ['response', {}, env] }
8
- stack = Airbrake::Rack.new(app)
9
-
10
- response = stack.call(environment)
11
-
12
- assert_equal ['response', {}, environment], response
13
- end
14
-
15
- should "deliver an exception raised while calling an upstream app" do
16
- Airbrake.stubs(:notify_or_ignore)
17
-
18
- exception = build_exception
19
- environment = { 'key' => 'value' }
20
- app = lambda do |env|
21
- raise exception
22
- end
23
-
24
- begin
25
- stack = Airbrake::Rack.new(app)
26
- stack.call(environment)
27
- rescue Exception => raised
28
- assert_equal exception, raised
29
- else
30
- flunk "Didn't raise an exception"
31
- end
32
-
33
- assert_received(Airbrake, :notify_or_ignore) do |expect|
34
- expect.with(exception, :rack_env => environment)
35
- end
36
- end
37
-
38
- should "deliver an exception in rack.exception" do
39
- Airbrake.stubs(:notify_or_ignore)
40
- exception = build_exception
41
- environment = { 'key' => 'value' }
42
-
43
- response = [200, {}, ['okay']]
44
- app = lambda do |env|
45
- env['rack.exception'] = exception
46
- response
47
- end
48
- stack = Airbrake::Rack.new(app)
49
-
50
- actual_response = stack.call(environment)
51
-
52
- assert_equal response, actual_response
53
- assert_received(Airbrake, :notify_or_ignore) do |expect|
54
- expect.with(exception, :rack_env => environment)
55
- end
56
- end
57
-
58
- end
@@ -1,36 +0,0 @@
1
- require File.expand_path '../helper', __FILE__
2
-
3
- require 'airbrake/rails'
4
-
5
- class RailsInitializerTest < Test::Unit::TestCase
6
- include DefinesConstants
7
-
8
- should "trigger use of Rails' logger if logger isn't set and Rails' logger exists" do
9
- rails = Module.new do
10
- def self.logger
11
- "RAILS LOGGER"
12
- end
13
- end
14
- define_constant("Rails", rails)
15
- Airbrake::Rails.initialize
16
- assert_equal "RAILS LOGGER", Airbrake.logger
17
- end
18
-
19
- should "trigger use of Rails' default logger if logger isn't set and Rails.logger doesn't exist" do
20
- define_constant("RAILS_DEFAULT_LOGGER", "RAILS DEFAULT LOGGER")
21
-
22
- Airbrake::Rails.initialize
23
- assert_equal "RAILS DEFAULT LOGGER", Airbrake.logger
24
- end
25
-
26
- should "allow overriding of the logger if already assigned" do
27
- define_constant("RAILS_DEFAULT_LOGGER", "RAILS DEFAULT LOGGER")
28
- Airbrake::Rails.initialize
29
-
30
- Airbrake.configure(true) do |config|
31
- config.logger = "OVERRIDDEN LOGGER"
32
- end
33
-
34
- assert_equal "OVERRIDDEN LOGGER", Airbrake.logger
35
- end
36
- end
@@ -1,10 +0,0 @@
1
- require File.expand_path '../helper', __FILE__
2
-
3
- class RecursionTest < Test::Unit::TestCase
4
- should "not allow infinite recursion" do
5
- hash = {:a => :a}
6
- hash[:hash] = hash
7
- notice = Airbrake::Notice.new(:parameters => hash)
8
- assert_equal "[possible infinite recursion halted]", notice.parameters[:hash]
9
- end
10
- end
@@ -1,288 +0,0 @@
1
- require File.expand_path '../helper', __FILE__
2
-
3
- class SenderTest < Test::Unit::TestCase
4
-
5
- def setup
6
- reset_config
7
- end
8
-
9
- def build_sender(opts = {})
10
- Airbrake.configure do |conf|
11
- opts.each {|opt, value| conf.send(:"#{opt}=", value) }
12
- end
13
- end
14
-
15
- def send_exception(args = {})
16
- notice = args.delete(:notice) || build_notice_data
17
- notice.stubs(:to_xml)
18
- sender = args.delete(:sender) || build_sender(args)
19
- sender.send_to_airbrake(notice)
20
- end
21
-
22
- def stub_http(options = {})
23
- response = stub(:body => options[:body] || 'body')
24
- http = stub(:post => response,
25
- :read_timeout= => nil,
26
- :open_timeout= => nil,
27
- :ca_file= => nil,
28
- :verify_mode= => nil,
29
- :use_ssl= => nil)
30
- Net::HTTP.stubs(:new => http)
31
- http
32
- end
33
-
34
- should "post to Airbrake with XML passed" do
35
- xml_notice = Airbrake::Notice.new(:error_class => "FooBar", :error_message => "Foo Bar").to_xml
36
-
37
- http = stub_http
38
-
39
- sender = build_sender
40
- sender.send_to_airbrake(xml_notice)
41
-
42
- assert_received(http, :post) do |expect|
43
- expect.with(anything, xml_notice, Airbrake::HEADERS)
44
- end
45
- end
46
-
47
- should "post to Airbrake with a Notice instance passed" do
48
- notice = Airbrake::Notice.new(:error_class => "FooBar", :error_message => "Foo Bar")
49
-
50
- http = stub_http
51
-
52
- sender = build_sender
53
- sender.send_to_airbrake(notice)
54
-
55
- assert_received(http, :post) do |expect|
56
- expect.with(anything, notice.to_xml, Airbrake::HEADERS)
57
- end
58
- end
59
-
60
- should "post to Airbrake when using an HTTP proxy" do
61
- response = stub(:body => 'body')
62
- http = stub(:post => response,
63
- :read_timeout= => nil,
64
- :open_timeout= => nil,
65
- :use_ssl= => nil)
66
- proxy = stub(:new => http)
67
- Net::HTTP.stubs(:Proxy => proxy)
68
-
69
- url = "http://api.airbrake.io:80#{Airbrake::Sender::NOTICES_URI}"
70
- uri = URI.parse(url)
71
-
72
- proxy_host = 'some.host'
73
- proxy_port = 88
74
- proxy_user = 'login'
75
- proxy_pass = 'passwd'
76
-
77
- send_exception(:proxy_host => proxy_host,
78
- :proxy_port => proxy_port,
79
- :proxy_user => proxy_user,
80
- :proxy_pass => proxy_pass)
81
- assert_received(http, :post) do |expect|
82
- expect.with(uri.path, anything, Airbrake::HEADERS)
83
- end
84
- assert_received(Net::HTTP, :Proxy) do |expect|
85
- expect.with(proxy_host, proxy_port, proxy_user, proxy_pass)
86
- end
87
- end
88
-
89
- should "return the created group's id on successful posting" do
90
- http = stub_http(:body => '<id type="integer">3799307</id>')
91
- assert_equal "3799307", send_exception(:secure => false)
92
- end
93
-
94
- context "when encountering exceptions: " do
95
- context "HTTP connection setup problems" do
96
- should "not be rescued" do
97
- proxy = stub()
98
- proxy.stubs(:new).raises(NoMemoryError)
99
- Net::HTTP.stubs(:Proxy => proxy)
100
-
101
- assert_raise NoMemoryError do
102
- build_sender.send(:setup_http_connection)
103
- end
104
- end
105
-
106
- should "be logged" do
107
- proxy = stub()
108
- proxy.stubs(:new).raises(RuntimeError)
109
- Net::HTTP.stubs(:Proxy => proxy)
110
-
111
- sender = build_sender
112
- sender.expects(:log)
113
-
114
- assert_raise RuntimeError do
115
- sender.send(:setup_http_connection)
116
- end
117
-
118
- end
119
- end
120
-
121
- context "unexpected exception sending problems" do
122
- should "be logged" do
123
- sender = build_sender
124
- sender.stubs(:setup_http_connection).raises(RuntimeError.new)
125
-
126
- sender.expects(:log)
127
- send_exception(:sender => sender)
128
- end
129
-
130
- should "return nil no matter what" do
131
- sender = build_sender
132
- sender.stubs(:setup_http_connection).raises(LocalJumpError)
133
-
134
- assert_nothing_thrown do
135
- assert_nil sender.send_to_airbrake(build_notice_data)
136
- end
137
- end
138
- end
139
-
140
- should "return nil on failed posting" do
141
- http = stub_http
142
- http.stubs(:post).raises(Errno::ECONNREFUSED)
143
- assert_equal nil, send_exception(:secure => false)
144
- end
145
-
146
- should "not fail when posting and a timeout exception occurs" do
147
- http = stub_http
148
- http.stubs(:post).raises(TimeoutError)
149
- assert_nothing_thrown do
150
- send_exception(:secure => false)
151
- end
152
- end
153
-
154
- should "not fail when posting and a connection refused exception occurs" do
155
- http = stub_http
156
- http.stubs(:post).raises(Errno::ECONNREFUSED)
157
- assert_nothing_thrown do
158
- send_exception(:secure => false)
159
- end
160
- end
161
-
162
- should "not fail when posting any http exception occurs" do
163
- http = stub_http
164
- Airbrake::Sender::HTTP_ERRORS.each do |error|
165
- http.stubs(:post).raises(error)
166
- assert_nothing_thrown do
167
- send_exception(:secure => false)
168
- end
169
- end
170
- end
171
- end
172
-
173
- context "SSL" do
174
- should "post to the right url for non-ssl" do
175
- http = stub_http
176
- url = "http://api.airbrake.io:80#{Airbrake::Sender::NOTICES_URI}"
177
- uri = URI.parse(url)
178
- send_exception(:secure => false)
179
- assert_received(http, :post) {|expect| expect.with(uri.path, anything, Airbrake::HEADERS) }
180
- end
181
-
182
- should "post to the right path for ssl" do
183
- http = stub_http
184
- send_exception(:secure => true)
185
- assert_received(http, :post) {|expect| expect.with(Airbrake::Sender::NOTICES_URI, anything, Airbrake::HEADERS) }
186
- end
187
-
188
- should "verify the SSL peer when the use_ssl option is set to true" do
189
- url = "https://api.airbrake.io#{Airbrake::Sender::NOTICES_URI}"
190
- uri = URI.parse(url)
191
-
192
- real_http = Net::HTTP.new(uri.host, uri.port)
193
- real_http.stubs(:post => nil)
194
- proxy = stub(:new => real_http)
195
- Net::HTTP.stubs(:Proxy => proxy)
196
- File.stubs(:exist?).with(OpenSSL::X509::DEFAULT_CERT_FILE).returns(false)
197
-
198
- send_exception(:secure => true)
199
- assert(real_http.use_ssl?)
200
- assert_equal(OpenSSL::SSL::VERIFY_PEER, real_http.verify_mode)
201
- assert_equal(Airbrake.configuration.local_cert_path, real_http.ca_file)
202
- end
203
-
204
- should "use the default DEFAULT_CERT_FILE if asked to" do
205
- config = Airbrake::Configuration.new
206
- config.use_system_ssl_cert_chain = true
207
- sender = Airbrake::Sender.new(config)
208
-
209
- assert(sender.use_system_ssl_cert_chain?)
210
-
211
- http = sender.send(:setup_http_connection)
212
- assert_not_equal http.ca_file, config.local_cert_path
213
- end
214
-
215
- should "verify the connection when the use_ssl option is set (VERIFY_PEER)" do
216
- sender = build_sender(:secure => true)
217
- http = sender.send(:setup_http_connection)
218
- assert_equal(OpenSSL::SSL::VERIFY_PEER, http.verify_mode)
219
- end
220
-
221
- should "use the default cert (OpenSSL::X509::DEFAULT_CERT_FILE) only if explicitly told to" do
222
- sender = build_sender(:secure => true)
223
- http = sender.send(:setup_http_connection)
224
-
225
- assert_equal(Airbrake.configuration.local_cert_path, http.ca_file)
226
-
227
- File.stubs(:exist?).with(OpenSSL::X509::DEFAULT_CERT_FILE).returns(true)
228
- sender = build_sender(:secure => true, :use_system_ssl_cert_chain => true)
229
- http = sender.send(:setup_http_connection)
230
-
231
- assert_not_equal(Airbrake.configuration.local_cert_path, http.ca_file)
232
- assert_equal(OpenSSL::X509::DEFAULT_CERT_FILE, http.ca_file)
233
- end
234
-
235
- should "connect to the right port for ssl" do
236
- stub_http
237
- send_exception(:secure => true)
238
- assert_received(Net::HTTP, :new) {|expect| expect.with("api.airbrake.io", 443) }
239
- end
240
-
241
- should "connect to the right port for non-ssl" do
242
- stub_http
243
- send_exception(:secure => false)
244
- assert_received(Net::HTTP, :new) {|expect| expect.with("api.airbrake.io", 80) }
245
- end
246
-
247
- should "use ssl if secure" do
248
- stub_http
249
- send_exception(:secure => true, :host => 'example.org')
250
- assert_received(Net::HTTP, :new) {|expect| expect.with('example.org', 443) }
251
- end
252
-
253
- should "not use ssl if not secure" do
254
- stub_http
255
- send_exception(:secure => false, :host => 'example.org')
256
- assert_received(Net::HTTP, :new) {|expect| expect.with('example.org', 80) }
257
- end
258
-
259
-
260
- end
261
-
262
- context "network timeouts" do
263
- should "default the open timeout to 2 seconds" do
264
- http = stub_http
265
- send_exception
266
- assert_received(http, :open_timeout=) {|expect| expect.with(2) }
267
- end
268
-
269
- should "default the read timeout to 5 seconds" do
270
- http = stub_http
271
- send_exception
272
- assert_received(http, :read_timeout=) {|expect| expect.with(5) }
273
- end
274
-
275
- should "allow override of the open timeout" do
276
- http = stub_http
277
- send_exception(:http_open_timeout => 4)
278
- assert_received(http, :open_timeout=) {|expect| expect.with(4) }
279
- end
280
-
281
- should "allow override of the read timeout" do
282
- http = stub_http
283
- send_exception(:http_read_timeout => 10)
284
- assert_received(http, :read_timeout=) {|expect| expect.with(10) }
285
- end
286
- end
287
-
288
- end