Use config opt value to determine import methods
Instead of validating import requests by checking the provided
import-method against a hard-coded list, use the values in the
appropriate configuration option.
Change-Id: Iefac190a4adf5f08df538e04db3e07e261ad1bd9
Closes-bug: #1754634
(cherry picked from commit e1738033df
)
This commit is contained in:
parent
5fc7148271
commit
2221868690
|
@ -817,7 +817,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
|
|||
except KeyError:
|
||||
msg = _("Import request requires a 'name' field.")
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
if method_name not in ['glance-direct', 'web-download']:
|
||||
if method_name not in CONF.enabled_import_methods:
|
||||
msg = _("Unknown import method name '%s'.") % method_name
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
|
|
|
@ -3158,10 +3158,13 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
|
|||
|
||||
def test_image_import(self):
|
||||
self.config(enable_image_import=True)
|
||||
# Bug 1754634: make sure that what's considered valid
|
||||
# is determined by the config option
|
||||
self.config(enabled_import_methods=['party-time'])
|
||||
request = unit_test_utils.get_fake_request()
|
||||
import_body = {
|
||||
"method": {
|
||||
"name": "glance-direct"
|
||||
"name": "party-time"
|
||||
}
|
||||
}
|
||||
request.body = jsonutils.dump_as_bytes(import_body)
|
||||
|
@ -3202,18 +3205,29 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
|
|||
self.deserializer.import_image,
|
||||
request)
|
||||
|
||||
def test_import_image_invalid_import_method(self):
|
||||
self.config(enable_image_import=True)
|
||||
def _get_request_for_method(self, method_name):
|
||||
request = unit_test_utils.get_fake_request()
|
||||
import_body = {
|
||||
"method": {
|
||||
"name": "abcd"
|
||||
"name": method_name
|
||||
}
|
||||
}
|
||||
request.body = jsonutils.dump_as_bytes(import_body)
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.deserializer.import_image,
|
||||
request)
|
||||
return request
|
||||
|
||||
KNOWN_IMPORT_METHODS = ['glance-direct', 'web-download']
|
||||
|
||||
def test_import_image_invalid_import_method(self):
|
||||
self.config(enable_image_import=True)
|
||||
# Bug 1754634: make sure that what's considered valid
|
||||
# is determined by the config option. So put known bad
|
||||
# name in config, and known good name in request
|
||||
self.config(enabled_import_methods=['bad-method-name'])
|
||||
for m in self.KNOWN_IMPORT_METHODS:
|
||||
request = self._get_request_for_method(m)
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.deserializer.import_image,
|
||||
request)
|
||||
|
||||
|
||||
class TestImagesDeserializerWithExtendedSchema(test_utils.BaseTestCase):
|
||||
|
|
Loading…
Reference in New Issue