Permalink
Browse files

Merge pull request #268 from alphagov/disable_unless_configured

Only send notices if configured with an api_key
  • Loading branch information...
2 parents c720737 + ce0d0f1 commit e7bf49dcf43133fd32325960d10d8ae743d31f91 @alif alif committed May 2, 2014
Showing with 34 additions and 2 deletions.
  1. +1 −1 lib/airbrake.rb
  2. +4 −0 lib/airbrake/configuration.rb
  3. +21 −0 test/configuration_test.rb
  4. +7 −0 test/integration/catcher_test.rb
  5. +1 −1 test/notifier_test.rb
View
@@ -147,7 +147,7 @@ def build_lookup_hash_for(exception, options = {})
private
def send_notice(notice)
- if configuration.public?
+ if configuration.configured? && configuration.public?
if configuration.async?
configuration.async.call(notice)
nil # make sure we never set env["airbrake.error_id"] for async notices
@@ -256,6 +256,10 @@ def merge(hash)
to_hash.merge(hash)
end
+ def configured?
+ !api_key.nil? && !api_key.empty?
+ end
+
# Determines if the notifier will send notices.
# @return [Boolean] Returns +false+ if in a development environment, +true+ otherwise.
def public?
View
@@ -183,6 +183,27 @@ class ConfigurationTest < Test::Unit::TestCase
assert_same_elements %w(development test cucumber), config.development_environments
end
+ context "configured?" do
+ setup do
+ @config = Airbrake::Configuration.new
+ end
+
+ should "be true if given an api_key" do
+ @config.api_key = "1234"
+ assert @config.configured?
+ end
+
+ should "be false with a nil api_key" do
+ @config.api_key = nil
+ assert !@config.configured?
+ end
+
+ should "be false with a blank api_key" do
+ @config.api_key = ''
+ assert !@config.configured?
+ end
+ end
+
should "be public in a public environment" do
config = Airbrake::Configuration.new
config.development_environments = %w(development)
@@ -270,6 +270,13 @@ def test_not_deliver_notices_from_exceptions_in_development_environments
assert_caught_and_not_sent
end
+ def test_not_deliver_notices_from_exceptions_with_no_api_key
+ Airbrake.configuration.api_key = nil
+ @app = AirbrakeTestController.action(:boom)
+ get '/'
+ assert_caught_and_not_sent
+ end
+
def test_not_deliver_notices_from_actions_that_dont_raise
@app = AirbrakeTestController.action(:hello)
get '/'
View
@@ -187,7 +187,7 @@ def set_development_env
config_opts = { 'one' => 'two', 'three' => 'four' }
stub_notice!
stub_sender!
- Airbrake.configuration = stub('config', :merge => config_opts, :public? => true,:async? => nil)
+ Airbrake.configuration = stub('config', :merge => config_opts, :configured? => true, :public? => true,:async? => nil)
Airbrake.notify(exception)

0 comments on commit e7bf49d

Please sign in to comment.