Update order returns 500 when body is not JSON

Bug #1376438 reported by John Vrbanac
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Barbican
Fix Released
High
Juan Antonio Osorio Robles

Bug Description

The server returns a 500 when attempting to update an order with the body being invalid json or a string.

Steps to Reproduce:

Create and Order:
----------------------------------
curl -X POST -H "X-Auth-Token:$AUTH_TOKEN" -H "Content-Type:application/json" -H "X-Project-Id:$PROJECT_ID" -d '{
  "type": "key",
  "meta": {
    "mode": "cbc",
    "bit_length": 256,
    "name": "secretname",
    "algorithm": "aes",
    "payload_content_type": "application/octet-stream"
  }
}' http://localhost:9311/v1/orders

Attempt to update the order with string instead of valid json
--------------------------------------------------------------
curl -X PUT -H "X-Auth-Token:$AUTH_TOKEN" -H "Content-Type:application/json" -d 'blarg' http://localhost:9311/v1/orders/20433fca-4f6d-4320-be04-97adb18feb48

Server Traceback:
--------------------------------
2014-10-01 15:32:25.750 10530 ERROR barbican.api.controllers [-] Order update failure seen - please contact site administrator.
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers Traceback (most recent call last):
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/__init__.py", line 96, in handler
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers return fn(inst, *args, **kwargs)
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/__init__.py", line 82, in enforcer
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers return fn(inst, *args, **kwargs)
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/__init__.py", line 130, in content_types_enforcer
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers return fn(inst, *args, **kwargs)
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/orders.py", line 105, in on_put
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers order_type = json.loads(raw_body).get('type')
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/openstack/common/jsonutils.py", line 172, in loads
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers return json.loads(strutils.safe_decode(s, encoding))
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers File "/home/john/.pyenv/versions/2.7.8/lib/python2.7/json/__init__.py", line 338, in loads
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers return _default_decoder.decode(s)
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers File "/home/john/.pyenv/versions/2.7.8/lib/python2.7/json/decoder.py", line 366, in decode
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers obj, end = self.raw_decode(s, idx=_w(s, 0).end())
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers File "/home/john/.pyenv/versions/2.7.8/lib/python2.7/json/decoder.py", line 384, in raw_decode
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers raise ValueError("No JSON object could be decoded")
2014-10-01 15:32:25.750 10530 TRACE barbican.api.controllers ValueError: No JSON object could be decoded

description: updated
Changed in barbican:
assignee: nobody → Chelsea Winfree (chelsea-winfree)
description: updated
Changed in barbican:
assignee: Chelsea Winfree (chelsea-winfree) → Douglas Mendizábal (dougmendizabal)
importance: Undecided → Critical
milestone: none → juno-rc1
Changed in barbican:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to barbican (master)

Fix proposed to branch: master
Review: https://review.openstack.org/125516

Changed in barbican:
milestone: juno-rc1 → kilo-1
importance: Critical → High
Changed in barbican:
milestone: kilo-1 → none
Revision history for this message
John Vrbanac (john.vrbanac) wrote :

Unassigning and moving back to confirmed as the patch stalled out a few months ago.

Changed in barbican:
status: In Progress → Confirmed
assignee: Douglas Mendizábal (dougmendizabal) → nobody
Changed in barbican:
assignee: nobody → Juan Antonio Osorio Robles (juan-osorio-robles)
Changed in barbican:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to barbican (master)

Reviewed: https://review.openstack.org/125516
Committed: https://git.openstack.org/cgit/openstack/barbican/commit/?id=5df7bbf3f84a491010e6e5f532d3dd041bbab98c
Submitter: Jenkins
Branch: master

commit 5df7bbf3f84a491010e6e5f532d3dd041bbab98c
Author: Douglas Mendizabal <email address hidden>
Date: Wed Oct 1 17:56:28 2014 -0500

    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

Changed in barbican:
status: In Progress → Fix Committed
Changed in barbican:
milestone: none → kilo-2
Thierry Carrez (ttx)
Changed in barbican:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in barbican:
milestone: kilo-2 → 2015.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.