get_console_output with body 'os-getConsoleOutput' set to non-integer doe not respond with HTTPBadRequest

Bug #1027069 reported by Roland Hochmuth
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Undecided
Roland Hochmuth

Bug Description

"ConsoleOutputController:get_console_output" in "nova/api/openstack/compute/contrib/console_output.py", does not validate if the value of 'length' supplied in the request body can be converted to an integer. As a result, a HTTP 500 error is return, instead of a HTTPBadRequest.

To test, I added a unit test in

    api/openstack/compute/contrib/test_console_output.py

    def test_get_console_output_with_non_integer_tail(self):
        body = {'os-getConsoleOutput': {'length': 'NaN'}}
        req = webob.Request.blank('/v2/fake/servers/1/action')
        req.method = "POST"
        req.body = jsonutils.dumps(body)
        req.headers["content-type"] = "application/json"
        res = req.get_response(fakes.wsgi_app())
        output = jsonutils.loads(res.body)
        self.assertEqual(res.status_int, 400)

which supplies the value "NaN", and the test fails as 500 is returned.

Revision history for this message
Roland Hochmuth (roland-hochmuth) wrote :

I have a fix ready to go that adds validation on the type of "length" and the unit test above.

Changed in nova:
assignee: nobody → Roland Hochmuth (roland-hochmuth-s)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

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

Changed in nova:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/10093
Committed: http://github.com/openstack/nova/commit/5522507bd7ff51ad8a55f8318c327ace3157675d
Submitter: Jenkins
Branch: master

commit 5522507bd7ff51ad8a55f8318c327ace3157675d
Author: Roland Hochmuth <email address hidden>
Date: Sat Jul 21 10:52:41 2012 +0100

    Return 400 in get_console_output for bad length.

    Fixes bug 1027069. Prior to this fix if the length in the
    request body was set to a non-integer value a error code of 500
    was returned. The documentation also shows an integer in the
    example request body.

    The fix tests if the optional length is provided and
    if it is either an "int" or "long". If not, a 400 error
    is returned.

    Additionally, cleaned up some error message to be more
    descriptive.

    Change-Id: I27a66fb1111e74665969f98e1101a9c37c665abc

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

Duplicates of this bug

Other bug subscribers

Remote bug watches

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