summaryrefslogtreecommitdiff
path: root/spec/controllers/application_controller_spec.rb
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2018-09-05 16:41:59 -0300
committerFelipe Artur <felipefac@gmail.com>2018-09-22 12:15:53 -0300
commit1fcc7f9ba23a5ca02773e080ccb66f37435150ff (patch)
tree7da14469edc854dd004f38ba6a31ba89a689663e /spec/controllers/application_controller_spec.rb
parent7dd8d37984efb93c58f0f56fe7394ff5d90fbe11 (diff)
downloadgitlab-ce-1fcc7f9ba23a5ca02773e080ccb66f37435150ff.tar.gz
Render 412 for invalid UTF-8 parametersfa-handle_invalid_utf8_errors
Renders 412 error page when invalid UTF-8 is passed as parameters in controllers.
Diffstat (limited to 'spec/controllers/application_controller_spec.rb')
-rw-r--r--spec/controllers/application_controller_spec.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index fbf116e533b..7202cee04ea 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -694,4 +694,38 @@ describe ApplicationController do
expect(response).to have_gitlab_http_status(403)
end
end
+
+ context 'when invalid UTF-8 parameters are received' do
+ controller(described_class) do
+ def index
+ params[:text].split(' ')
+
+ render json: :ok
+ end
+ end
+
+ before do
+ sign_in user
+ end
+
+ context 'html' do
+ it 'renders 412' do
+ get :index, text: "hi \255"
+
+ expect(response).to have_gitlab_http_status(412)
+ expect(response).to render_template :precondition_failed
+ end
+ end
+
+ context 'js' do
+ it 'renders 412' do
+ get :index, text: "hi \255", format: :js
+
+ json_response = JSON.parse(response.body)
+
+ expect(response).to have_gitlab_http_status(412)
+ expect(json_response['error']).to eq('Invalid UTF-8')
+ end
+ end
+ end
end