Skip to content

Commit cbf7dbc

Browse files
author
Joshua Wood
committed
Require API key in production sender
1 parent 6f24eef commit cbf7dbc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/honeybadger/sender.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ def initialize(options = {})
3434
#
3535
# Returns error id from successful response
3636
def send_to_honeybadger(notice)
37+
if api_key.nil?
38+
log(:error, "API key not found.")
39+
return nil
40+
end
41+
3742
data = notice.is_a?(String) ? notice : notice.to_json
3843

3944
http = setup_http_connection
4045
headers = HEADERS
4146

42-
headers.merge!({ 'X-API-Key' => api_key}) unless api_key.nil?
47+
headers.merge!({ 'X-API-Key' => api_key})
4348

4449
response = begin
4550
http.post(url.path, data, headers)

test/unit/sender_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def stub_http(options = {})
7171
assert_equal nil, send_exception(:secure => false)
7272
end
7373

74+
should "log missing API key and return nil" do
75+
sender = build_sender({ :api_key => nil })
76+
sender.expects(:log).with(:error, includes('API key'))
77+
assert_equal nil, send_exception(:sender => sender, :secure => false)
78+
end
79+
7480
should "should log success" do
7581
http = stub_http
7682
sender = build_sender

0 commit comments

Comments
 (0)