Merge "Fix 500 error when we specify invalid headers when work with blob/bloblist"

This commit is contained in:
Jenkins 2016-01-19 17:21:01 +00:00 committed by Gerrit Code Review
commit 454dddd650
2 changed files with 16 additions and 0 deletions

View File

@ -184,6 +184,10 @@ class ArtifactsController(object):
type_name,
type_version)
self._ensure_write_access(artifact, req.context)
if artifact.metadata.attributes.blobs.get(path) is not None:
msg = _('Invalid Content-Type for work with %s') % path
raise webob.exc.HTTPBadRequest(explanation=msg)
# use updater mixin to perform updates: generate update path
if req.method == "PUT":
# replaces existing value or creates a new one

View File

@ -1104,6 +1104,18 @@ paste.filter_factory = glance.tests.utils:FakeAuthMiddleware.factory
headers=headers,
data='ZZZZZ', status=200)
def test_upload_file_with_invalid_content_type(self):
art = self._create_artifact('withblob')
data = {'data': 'jjjjjj'}
res = self._check_artifact_post('/withblob/v1/%s/blob1' % art['id'],
data=data, status=400)
self.assertIn('Invalid Content-Type for work with blob1', res)
res = self._check_artifact_post('/withblob/v1/%s/blob_list'
% art['id'],
data=data, status=400)
self.assertIn('Invalid Content-Type for work with blob_list', res)
def test_upload_list_files(self):
art = self._create_artifact('withblob')
headers = self._headers({'Content-Type': 'application/octet-stream'})