Merge "Return 400 Bad Request for extra capability keys longer than 64 chars"
This commit is contained in:
commit
991bbd52c4
|
@ -153,6 +153,11 @@ class MissingParameter(exceptions.BlazarException):
|
|||
msg_fmt = _("Missing parameter %(param)s")
|
||||
|
||||
|
||||
class ExtraCapabilityTooLong(exceptions.BlazarException):
|
||||
code = 400
|
||||
msg_fmt = _("Extra capability key too long")
|
||||
|
||||
|
||||
class InvalidState(exceptions.BlazarException):
|
||||
code = 409
|
||||
msg_fmt = _("Invalid State %(state)s for %(id)s")
|
||||
|
|
|
@ -341,6 +341,10 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
|
|||
extra_capabilities = dict(
|
||||
(key, host_values[key]) for key in extra_capabilities_keys
|
||||
)
|
||||
|
||||
if any([len(key) > 64 for key in extra_capabilities_keys]):
|
||||
raise manager_ex.ExtraCapabilityTooLong()
|
||||
|
||||
pool = nova.ReservationPool()
|
||||
pool.add_computehost(self.freepool_name,
|
||||
host_details['service_name'])
|
||||
|
|
|
@ -221,6 +221,19 @@ class PhysicalHostPluginTestCase(tests.TestCase):
|
|||
self.db_host_extra_capability_create.assert_called_once_with(fake_capa)
|
||||
self.assertEqual(host, fake_host)
|
||||
|
||||
def test_create_host_with_capabilities_too_long(self):
|
||||
fake_host = self.fake_host.copy()
|
||||
fake_host.update({'foo': 'bar'})
|
||||
# NOTE(sbauza): 'id' will be pop'd, we need to keep track of it
|
||||
fake_request = fake_host.copy()
|
||||
long_key = ""
|
||||
for i in range(65):
|
||||
long_key += "0"
|
||||
fake_request[long_key] = "foo"
|
||||
self.assertRaises(manager_exceptions.ExtraCapabilityTooLong,
|
||||
self.fake_phys_plugin.create_computehost,
|
||||
fake_request)
|
||||
|
||||
def test_create_host_without_trust_id(self):
|
||||
self.assertRaises(manager_exceptions.MissingTrustId,
|
||||
self.fake_phys_plugin.create_computehost, {})
|
||||
|
|
Loading…
Reference in New Issue