Commit 1cc587c03ea31a193b804779791ebc4be6e8ac36
1 parent
aa2e8315
Exists in
master
and in
1 other branch
refs #934 catch and provide error on invalid xml
Showing
2 changed files
with
11 additions
and
0 deletions
Show diff stats
app/controllers/notices_controller.rb
@@ -24,6 +24,8 @@ class NoticesController < ApplicationController | @@ -24,6 +24,8 @@ class NoticesController < ApplicationController | ||
24 | else | 24 | else |
25 | render :text => "Your API key is unknown", :status => 422 | 25 | render :text => "Your API key is unknown", :status => 422 |
26 | end | 26 | end |
27 | + rescue Nokogiri::XML::SyntaxError | ||
28 | + render :text => 'The provided XML was not well-formed', :status => 422 | ||
27 | end | 29 | end |
28 | 30 | ||
29 | # Redirects a notice to the problem page. Useful when using User Information at Airbrake gem. | 31 | # Redirects a notice to the problem page. Useful when using User Information at Airbrake gem. |
spec/controllers/notices_controller_spec.rb
@@ -7,6 +7,15 @@ describe NoticesController, type: 'controller' do | @@ -7,6 +7,15 @@ describe NoticesController, type: 'controller' do | ||
7 | let(:error_report) { double(:valid? => true, :generate_notice! => true, :notice => notice, :should_keep? => true) } | 7 | let(:error_report) { double(:valid? => true, :generate_notice! => true, :notice => notice, :should_keep? => true) } |
8 | 8 | ||
9 | context 'notices API' do | 9 | context 'notices API' do |
10 | + context "with bogus xml" do | ||
11 | + it "returns an error" do | ||
12 | + expect(request).to receive(:raw_post).and_return('<r><b>notxml</r>') | ||
13 | + post :create, :format => :xml | ||
14 | + expect(response.status).to eq(422) | ||
15 | + expect(response.body).to eq('The provided XML was not well-formed') | ||
16 | + end | ||
17 | + end | ||
18 | + | ||
10 | context "with all params" do | 19 | context "with all params" do |
11 | before do | 20 | before do |
12 | expect(ErrorReport).to receive(:new).with(xml).and_return(error_report) | 21 | expect(ErrorReport).to receive(:new).with(xml).and_return(error_report) |