Check body type when patching subscription

When passing an invalid body type to subscription patching, we can an
ugly error in the logs "xx has no attribute get". Let's verify that's
it's a dict in validation to get a proper error.

Change-Id: I0c251b15a02f481c1d80afd7908a665c861b8aa7
This commit is contained in:
Thomas Herve 2017-02-17 13:32:15 +01:00
parent 5ec4d100ec
commit c870911cd7
2 changed files with 13 additions and 0 deletions

View File

@ -364,6 +364,15 @@ class TestSubscriptionsMongoDB(base.V2Base):
headers=self.headers)
self.assertEqual(falcon.HTTP_400, self.srmock.status)
def test_patch_invalid_body(self):
resp = self.simulate_patch(self.subscription_path + '/x',
body='[1]',
headers=self.headers)
self.assertEqual(falcon.HTTP_400, self.srmock.status)
resp_doc = jsonutils.loads(resp[0])
self.assertEqual('Subscriptions must be a dict.',
resp_doc['description'])
def test_delete_works(self):
self._create_subscription()
resp = self.simulate_get(self.subscription_path,

View File

@ -521,6 +521,10 @@ class Validator(object):
if not subscription:
raise ValidationFailed(_(u'No subscription to create.'))
if not isinstance(subscription, dict):
msg = _('Subscriptions must be a dict.')
raise ValidationFailed(msg)
subscriber = subscription.get('subscriber', None)
subscriber_type = None