Fix 500 error when PUTing an order
Since the load_body function was not being used to parse the request initially for orders, it was resulting in the exception that is seen in the bug description. So, load_body was introduced. But, since load_body uses a "read" for the ByteIO stream that contains the request's payload, it could only be used once. So a "seek(0)" was introduced to address this. Change-Id: I66e9b2b6dbb7196cf5a639db52f9f25e82da1765 Closes-Bug: #1376438
This commit is contained in:
parent
becfe39215
commit
5df7bbf3f8
|
@ -58,6 +58,7 @@ def load_body(req, resp=None, validator=None):
|
|||
"""
|
||||
try:
|
||||
body = req.body_file.read(CONF.max_allowed_request_size_in_bytes)
|
||||
req.body_file.seek(0)
|
||||
except IOError:
|
||||
LOG.exception(u._LE("Problem reading request JSON stream."))
|
||||
pecan.abort(500, u._('Read Error'))
|
||||
|
|
|
@ -22,7 +22,6 @@ from barbican.common import validators
|
|||
from barbican import i18n as u
|
||||
from barbican.model import models
|
||||
from barbican.model import repositories as repo
|
||||
from barbican.openstack.common import jsonutils as json
|
||||
from barbican.queue import client as async_client
|
||||
|
||||
LOG = utils.getLogger(__name__)
|
||||
|
@ -106,7 +105,8 @@ class OrderController(object):
|
|||
raw_body = pecan.request.body
|
||||
order_type = None
|
||||
if raw_body:
|
||||
order_type = json.loads(raw_body).get('type')
|
||||
unvalidated_body = api.load_body(pecan.request)
|
||||
order_type = unvalidated_body.get('type')
|
||||
|
||||
if not order_type:
|
||||
_order_type_not_in_order()
|
||||
|
|
|
@ -1536,6 +1536,17 @@ class WhenCreatingOrdersUsingOrdersResource(FunctionalTest):
|
|||
order = args[0]
|
||||
self.assertIsInstance(order, models.Order)
|
||||
|
||||
def test_should_fail_creating_order_with_bogus_content(self):
|
||||
resp = self.app.post(
|
||||
'/orders/',
|
||||
'bogus',
|
||||
headers={
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
expect_errors=True
|
||||
)
|
||||
self.assertEqual(resp.status_int, 400)
|
||||
|
||||
def test_should_allow_add_new_order_unsupported_algorithm(self):
|
||||
# TODO(john-wood-w) Allow until plugin validation is added.
|
||||
|
||||
|
@ -1826,6 +1837,17 @@ class WhenPuttingOrderWithMetadataUsingOrderResource(FunctionalTest):
|
|||
external_project_id=self.external_project_id,
|
||||
suppress_exception=True)
|
||||
|
||||
def test_should_fail_with_bogus_content(self):
|
||||
resp = self.app.put(
|
||||
'/orders/{0}/'.format(self.order.id),
|
||||
'bogus',
|
||||
headers={
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
expect_errors=True
|
||||
)
|
||||
self.assertEqual(resp.status_int, 400)
|
||||
|
||||
def test_should_fail_bad_type(self):
|
||||
self.order['type'] = 'secret'
|
||||
resp = self.app.put_json(
|
||||
|
|
Loading…
Reference in New Issue