diff options
author | Kiall Mac Innes <kiall@macinnes.ie> | 2016-08-25 15:48:06 +0100 |
---|---|---|
committer | Kiall Mac Innes <kiall@macinnes.ie> | 2016-08-25 16:00:44 +0100 |
commit | 6ac58041ddbeacce2cf8525b2e86c1c3aae91533 (patch) | |
tree | d6687b0db18947e7f8d2baedc203fd2638d90830 | |
parent | 86fcdd48e83c0106ddecddaa6056b7a34c70c16f (diff) | |
download | designate-6ac58041ddbeacce2cf8525b2e86c1c3aae91533.tar.gz |
Fix ZTA API to prevent HTTP 500 upon empty body
2016-08-25 13:20:34.576 28114 ERROR designate.api.middleware File "/opt/stack/new/designate/designate/api/v2/controllers/zones/tasks/transfer_requests.py", line 92, in post_all
2016-08-25 13:20:34.576 28114 ERROR designate.api.middleware body['zone_name'] = zone.name
2016-08-25 13:20:34.576 28114 ERROR designate.api.middleware TypeError: 'NoneType' object does not support item assignment
Needed for the new ZTA tempest tests
Change-Id: I5fdefa64480f118dad898ed4651036f9b9b16fe9
Needed-By: I843701655f3fd07245b79e37fa286f05f20bf7a3
-rw-r--r-- | designate/api/v2/patches.py | 8 | ||||
-rw-r--r-- | designate/tests/test_api/test_v2/test_zone_transfers.py | 10 |
2 files changed, 16 insertions, 2 deletions
diff --git a/designate/api/v2/patches.py b/designate/api/v2/patches.py index c99c6c6b..6a0555b4 100644 --- a/designate/api/v2/patches.py +++ b/designate/api/v2/patches.py @@ -39,9 +39,13 @@ class Request(pecan.core.Request): """ if self.content_type in JSON_TYPES: try: - return jsonutils.load(self.body_file) + json_dict = jsonutils.load(self.body_file) + if json_dict is None: + # NOTE(kiall): Somehow, json.load(fp) is returning None. + raise exceptions.EmptyRequestBody('Request Body is empty') + return json_dict except ValueError as valueError: - if len(self.body) == 0: + if len(self.body) == 0 or self.body is None: raise exceptions.EmptyRequestBody('Request Body is empty') else: raise exceptions.InvalidJson(six.text_type(valueError)) diff --git a/designate/tests/test_api/test_v2/test_zone_transfers.py b/designate/tests/test_api/test_v2/test_zone_transfers.py index ce2fc50a..1db6518f 100644 --- a/designate/tests/test_api/test_v2/test_zone_transfers.py +++ b/designate/tests/test_api/test_v2/test_zone_transfers.py @@ -75,6 +75,16 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase): response.json['zone_id']) self.assertIsNone(response.json['updated_at']) + def test_create_zone_transfer_request_empty_body(self): + # Send an empty ("None") body + response = self.client.post_json( + '/zones/%s/tasks/transfer_requests' % (self.zone.id), + None) + + # Check the headers are what we expect + self.assertEqual(201, response.status_int) + self.assertEqual('application/json', response.content_type) + def test_get_zone_transfer_request(self): initial = self.client.post_json( '/zones/%s/tasks/transfer_requests' % (self.zone.id), |