diff --git a/lib/insights/api/common/application_controller_mixins/request_body_validation.rb b/lib/insights/api/common/application_controller_mixins/request_body_validation.rb index 670ac152..a35cb414 100644 --- a/lib/insights/api/common/application_controller_mixins/request_body_validation.rb +++ b/lib/insights/api/common/application_controller_mixins/request_body_validation.rb @@ -18,11 +18,9 @@ def self.included(other) def body_params @body_params ||= begin - raw_body = request.body.read - parsed_body = raw_body.blank? ? {} : JSON.parse(raw_body) - ActionController::Parameters.new(parsed_body).permit! - rescue JSON::ParserError - raise Insights::API::Common::ApplicationControllerMixins::RequestBodyValidation::BodyParseError, "Failed to parse request body, expected JSON" + ActionController::Parameters.new( + params.permit!.to_h.except(*request.path_parameters.keys) + ).permit! end end @@ -38,7 +36,8 @@ def validate_request request.method, request.path, api_version, - body_params.as_json + body_params.to_h, + request.content_type ) end end diff --git a/spec/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb deleted file mode 100644 index bbfc3961..00000000 --- a/spec/dummy/config/initializers/wrap_parameters.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# This file contains settings for ActionController::ParamsWrapper which -# is enabled by default. - -# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] -end - -# To enable root element in JSON for ActiveRecord objects. -# ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true -# end diff --git a/spec/requests/request_body_validation_spec.rb b/spec/requests/request_body_validation_spec.rb index 2e370a9c..bfe8b8c6 100644 --- a/spec/requests/request_body_validation_spec.rb +++ b/spec/requests/request_body_validation_spec.rb @@ -4,16 +4,6 @@ before { stub_const("ENV", "BYPASS_TENANCY" => true) } let(:default_params) { { "authtype" => "openshift" } } - context "when there is an invalid body" do - let(:default_as) { :text } - - it "returns a 400" do - post("/api/v1.0/authentications", :headers => {"CONTENT_TYPE" => "application/text"}, :params => "{") - - expect(response.status).to eq(400) - end - end - it "unpermitted key" do post("/api/v1.0/authentications", :headers => headers, :params => default_params.merge("garbage" => "abc"))