Skip to content

Commit

Permalink
#1225 use X-Airbrake-Token header when present (#1227)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmreis authored and stevecrozz committed Sep 19, 2017
1 parent 7d7c81f commit 24b824d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/controllers/api/v3/notices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def create
response.headers['Access-Control-Allow-Headers'] = 'origin, content-type, accept'
return render(status: 200, text: '') if request.method == 'OPTIONS'

report = AirbrakeApi::V3::NoticeParser.new(
params.merge(JSON.parse(request.raw_post) || {})).report
merged_params = params.merge(JSON.parse(request.raw_post) || {})
merged_params = merged_params.merge('key' => request.headers['X-Airbrake-Token']) if request.headers['X-Airbrake-Token']
report = AirbrakeApi::V3::NoticeParser.new(merged_params).report

return render text: UNKNOWN_API_KEY, status: 422 unless report.valid?
return render text: VERSION_TOO_OLD, status: 422 unless report.should_keep?
Expand Down
6 changes: 6 additions & 0 deletions spec/controllers/api/v3/notices_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
expect(response.status).to be(201)
end

it 'responds with 201 created on success with token in headers' do
request.headers['X-Airbrake-Token'] = project_id
post :create, legit_body, project_id: 123
expect(response.status).to be(201)
end

it 'responds with 400 when request attributes are not valid' do
allow_any_instance_of(AirbrakeApi::V3::NoticeParser).
to receive(:report).and_raise(AirbrakeApi::ParamsError)
Expand Down

0 comments on commit 24b824d

Please sign in to comment.