File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ class ApplicationController < ActionController::Base
6868 before_action :check_write_permissions! , if : :enforce_write_scope?
6969 before_action :hashify_params
7070 before_action :null_coalesce_body
71+ before_action :validate_content_type!
7172
7273 rescue_from CloudController ::Blobstore ::BlobstoreError , with : :handle_blobstore_error
7374 rescue_from CloudController ::Errors ::NotAuthenticated , with : :handle_not_authenticated
@@ -223,6 +224,24 @@ def null_coalesce_body
223224 hashed_params [ :body ] ||= { }
224225 end
225226
227+ def validate_content_type!
228+ unless request_content_type_is_json?
229+ logger . error ( "Content-type isn't json: #{ request . content_type } " )
230+ bad_request! ( 'Content-Type must be json' )
231+ end
232+ unless requested_format_is_json_or_none?
233+ bad_request! ( 'Requested format must be json or none' )
234+ end
235+ end
236+
237+ def request_content_type_is_json?
238+ Mime ::Type . lookup ( request . content_type ) == :json
239+ end
240+
241+ def requested_format_is_json_or_none?
242+ !hashed_params . include? ( :format ) || hashed_params [ :format ] == 'json'
243+ end
244+
226245 def membership
227246 @membership ||= Membership . new ( current_user )
228247 end
Original file line number Diff line number Diff line change 88class SpaceManifestsController < ApplicationController
99 wrap_parameters :body , format : [ :yaml ]
1010
11- before_action :validate_content_type!
12-
1311 def apply_manifest
1412 space = Space . find ( guid : hashed_params [ :guid ] )
1513 space_not_found! unless space && permission_queryer . can_read_from_space? ( space . id , space . organization_id )
@@ -86,16 +84,23 @@ def compound_error!(error_messages)
8684 end
8785
8886 def validate_content_type!
89- if ! request_content_type_is_yaml?
87+ unless request_content_type_is_yaml?
9088 logger . error ( "Content-type isn't yaml: #{ request . content_type } " )
9189 bad_request! ( 'Content-Type must be yaml' )
9290 end
91+ unless requested_format_is_yaml_or_none?
92+ bad_request! ( 'Requested format must be yaml or none' )
93+ end
9394 end
9495
9596 def request_content_type_is_yaml?
9697 Mime ::Type . lookup ( request . content_type ) == :yaml
9798 end
9899
100+ def requested_format_is_yaml_or_none?
101+ !hashed_params . include? ( :format ) || %w[ yaml yml ] . include? ( hashed_params [ :format ] )
102+ end
103+
99104 def check_version_is_supported!
100105 version = parsed_yaml [ 'version' ]
101106 raise unprocessable! ( 'Unsupported manifest schema version. Currently supported versions: [1].' ) unless !version || version == 1
You can’t perform that action at this time.
0 commit comments