Merge "Fix glance ignored a headers when created artifact"
This commit is contained in:
commit
8d01ba841a
@ -554,17 +554,26 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer,
|
||||
except exception.ArtifactPluginNotFound as e:
|
||||
raise webob.exc.HTTPBadRequest(explanation=e.msg)
|
||||
|
||||
def _validate_headers(self, req, content_type='application/json'):
|
||||
header = req.headers.get('Content-Type')
|
||||
if header != content_type:
|
||||
msg = _('Invalid headers "Content-Type": %s') % header
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
def create(self, req):
|
||||
self._validate_headers(req)
|
||||
res = self._process_type_from_request(req, True)
|
||||
res["artifact_data"] = self._get_request_body(req)
|
||||
return res
|
||||
|
||||
def update(self, req):
|
||||
self._validate_headers(req)
|
||||
res = self._process_type_from_request(req)
|
||||
res["changes"] = self.validate_body(req)
|
||||
return res
|
||||
|
||||
def update_property(self, req):
|
||||
self._validate_headers(req)
|
||||
"""Data is expected in form {'data': ...}"""
|
||||
res = self._process_type_from_request(req)
|
||||
data_schema = {
|
||||
@ -590,6 +599,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer,
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
def upload(self, req):
|
||||
self._validate_headers(req, content_type='application/octet-stream')
|
||||
res = self._process_type_from_request(req)
|
||||
index = req.urlvars.get('path_left')
|
||||
try:
|
||||
|
@ -1379,6 +1379,13 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
|
||||
|
||||
self.assertEqual(actual, response)
|
||||
|
||||
def test_invalid_content_type(self):
|
||||
data = {'name': 'name1', 'version': '2.2'}
|
||||
self._check_artifact_post('/withprops/v1.0/drafts',
|
||||
data=data,
|
||||
status=400,
|
||||
headers={'Content-Type': 'lalala'})
|
||||
|
||||
def test_filter_by_non_dict_props(self):
|
||||
data = {'name': 'art1',
|
||||
'version': '4.2',
|
||||
|
Loading…
x
Reference in New Issue
Block a user