Merge "Fix multiple image imports if boolean input passed as string"

This commit is contained in:
Zuul 2020-04-09 18:13:35 +00:00 committed by Gerrit Code Review
commit b66342a3d8
2 changed files with 37 additions and 0 deletions

View File

@ -1115,6 +1115,17 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
msg = _("Unknown import method name '%s'.") % method_name
raise webob.exc.HTTPBadRequest(explanation=msg)
# Validate 'all_stores_must_succeed' and 'all_stores'
all_stores_must_succeed = body.get('all_stores_must_succeed', True)
if not isinstance(all_stores_must_succeed, bool):
msg = (_("'all_stores_must_succeed' must be boolean value only"))
raise webob.exc.HTTPBadRequest(explanation=msg)
all_stores = body.get('all_stores', False)
if not isinstance(all_stores, bool):
msg = (_("'all_stores' must be boolean value only"))
raise webob.exc.HTTPBadRequest(explanation=msg)
def import_image(self, request):
body = self._get_request_body(request)
self._validate_import_body(body)

View File

@ -4127,6 +4127,32 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
self.deserializer.import_image,
request)
def test_import_image_with_all_stores_not_boolean(self):
request = unit_test_utils.get_fake_request()
import_body = {
'method': {
'name': 'glance-direct'
},
'all_stores': "true"
}
request.body = jsonutils.dump_as_bytes(import_body)
self.assertRaises(webob.exc.HTTPBadRequest,
self.deserializer.import_image,
request)
def test_import_image_with_allow_failure_not_boolean(self):
request = unit_test_utils.get_fake_request()
import_body = {
'method': {
'name': 'glance-direct'
},
'all_stores_must_succeed': "true"
}
request.body = jsonutils.dump_as_bytes(import_body)
self.assertRaises(webob.exc.HTTPBadRequest,
self.deserializer.import_image,
request)
def _get_request_for_method(self, method_name):
request = unit_test_utils.get_fake_request()
import_body = {