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
@@ -211,6 +212,24 @@ def null_coalesce_body
211
212
hashed_params [ :body ] ||= { }
212
213
end
213
214
215
+ def validate_content_type!
216
+ unless request_content_type_is_json?
217
+ logger . error ( "Content-type isn't json: #{ request . content_type } " )
218
+ bad_request! ( 'Content-Type must be json' )
219
+ end
220
+ unless requested_format_is_json_or_none?
221
+ bad_request! ( 'Requested format must be json or none' )
222
+ end
223
+ end
224
+
225
+ def request_content_type_is_json?
226
+ Mime ::Type . lookup ( request . content_type ) == :json
227
+ end
228
+
229
+ def requested_format_is_json_or_none?
230
+ !hashed_params . include? ( :format ) || hashed_params [ :format ] == 'json'
231
+ end
232
+
214
233
def membership
215
234
@membership ||= Membership . new ( current_user )
216
235
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 . guid , space . organization . guid )
@@ -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