File tree 2 files changed +27
-3
lines changed
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ class ApplicationController < ActionController::Base
68
68
before_action :check_write_permissions! , if : :enforce_write_scope?
69
69
before_action :hashify_params
70
70
before_action :null_coalesce_body
71
+ before_action :validate_content_type!
71
72
72
73
rescue_from CloudController ::Blobstore ::BlobstoreError , with : :handle_blobstore_error
73
74
rescue_from CloudController ::Errors ::NotAuthenticated , with : :handle_not_authenticated
@@ -223,6 +224,24 @@ def null_coalesce_body
223
224
hashed_params [ :body ] ||= { }
224
225
end
225
226
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
+
226
245
def membership
227
246
@membership ||= Membership . new ( current_user )
228
247
end
Original file line number Diff line number Diff line change 8
8
class SpaceManifestsController < ApplicationController
9
9
wrap_parameters :body , format : [ :yaml ]
10
10
11
- before_action :validate_content_type!
12
-
13
11
def apply_manifest
14
12
space = Space . find ( guid : hashed_params [ :guid ] )
15
13
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)
86
84
end
87
85
88
86
def validate_content_type!
89
- if ! request_content_type_is_yaml?
87
+ unless request_content_type_is_yaml?
90
88
logger . error ( "Content-type isn't yaml: #{ request . content_type } " )
91
89
bad_request! ( 'Content-Type must be yaml' )
92
90
end
91
+ unless requested_format_is_yaml_or_none?
92
+ bad_request! ( 'Requested format must be yaml or none' )
93
+ end
93
94
end
94
95
95
96
def request_content_type_is_yaml?
96
97
Mime ::Type . lookup ( request . content_type ) == :yaml
97
98
end
98
99
100
+ def requested_format_is_yaml_or_none?
101
+ !hashed_params . include? ( :format ) || %w[ yaml yml ] . include? ( hashed_params [ :format ] )
102
+ end
103
+
99
104
def check_version_is_supported!
100
105
version = parsed_yaml [ 'version' ]
101
106
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