Bad query params on /v2/events can throw a 500

Bug #1423634 reported by jasonamyers
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ceilometer
Fix Released
Undecided
Chris Dent
WSME
Fix Released
Undecided
Unassigned

Bug Description

I made a GET request with to the following:

/v2/events?q=%7B%22field%22%3A%20%22event_type%22%2C%20%22op%22%3A%20%22eq%22%2C%20%22type%22%3A%20%22string%22%2C%20%22value%22%3A%20%22cookies_chocolate.chip%22%7D%0A

This was due to not understanding how to properly call the API; however, it resulted in a 500 instead of the expected 400

decoded that URL string contains [{"field": "event_type", "op": "eq", "type": "string", "value": "cookies_chocolate.chip"}]

Revision history for this message
jasonamyers (jason-jasonamyers) wrote :

You can also do this by misforming the data sent with the get request. For example if you send just a list of query params not in the query object it also occurs.

Example: '["field": "bad_field", "op": "eq", "type": "string", "value": "cookies_chocolate.chip"]' returns a 500 when the input is bad and should be '{"q": ["field": "bad_field", "op": "eq", "type": "string", "value": "cookies_chocolate.chip"]}'

Revision history for this message
jasonamyers (jason-jasonamyers) wrote :

Here is an example Gabbi test case that will trigger the bug:

- name: get events that match bad query via request data malformed list
  desc: https://bugs.launchpad.net/ceilometer/+bug/1423634
  url: /v2/events
  request_headers:
      content-type: application/json; charset=UTF-8
  data:
      - field: bad_field
        op: eq
        type: string
        value: cookies_chocolate.chip
  xfail: True
  status: 400

Revision history for this message
ZhiQiang Fan (aji-zqfan) wrote :

# ceilometer -d event-list -q event_type=string::cookies_chocolate.chip

curl -g -i -X 'GET' 'http://127.0.0.1:8777/v2/events?q.field=event_type&q.op=eq&q.type=string&q.value=cookies_chocolate.chip' -H 'User-Agent: ceilometerclient.openstack.common.apiclient' -H 'X-Auth-Token: {SHA1}9d65c43a3a909509641d9575c9e9f79446f333e7'

DEBUG (client) RESP BODY: []

+------------+------------+-----------+--------+
| Message ID | Event Type | Generated | Traits |
+------------+------------+-----------+--------+
+------------+------------+-----------+--------+

what version are you using?

what is the error message?

Changed in ceilometer:
status: New → Incomplete
Revision history for this message
jasonamyers (jason-jasonamyers) wrote :

This is against the master branch, and I agree you're example would work as it is properly formatted. However if I send the wrong data format as shown in my examples above I get back a 500 Internal server error, It should be a 400 error of some type to tell me I did not send the data properly.

Revision history for this message
jasonamyers (jason-jasonamyers) wrote :

The resulting error looks like:

2015-02-27 08:23:39.814 5690 ERROR wsme.api [-] Server-side error: "unhashable type: 'dict'". Detail:
Traceback (most recent call last):

  File "/Users/jasomyer/work_code/ceilometer/.tox/gabbi/lib/python2.7/site-packages/wsmeext/pecan.py", line 78, in callfunction
    pecan.request.body, pecan.request.content_type

  File "/Users/jasomyer/work_code/ceilometer/.tox/gabbi/lib/python2.7/site-packages/wsme/rest/args.py", line 292, in get_args
    from_body = args_from_body(funcdef, body, mimetype)

  File "/Users/jasomyer/work_code/ceilometer/.tox/gabbi/lib/python2.7/site-packages/wsme/rest/args.py", line 238, in args_from_body
    body, datatypes, bodyarg=funcdef.body_type is not None

  File "/Users/jasomyer/work_code/ceilometer/.tox/gabbi/lib/python2.7/site-packages/wsme/rest/json.py", line 227, in parse
    if key not in datatypes:

TypeError: unhashable type: 'dict'

======================================================================
FAIL: gabbi.driver.test_gabbi_api_events_with_data_get_events_that_match_bad_query_via_data_list.test_request
tags: worker-0
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jasomyer/work_code/ceilometer/.tox/gabbi/lib/python2.7/site-packages/gabbi/case.py", line 45, in wrapper
    func(self)
  File "/Users/jasomyer/work_code/ceilometer/.tox/gabbi/lib/python2.7/site-packages/gabbi/case.py", line 82, in test_request
    self._run_test()
  File "/Users/jasomyer/work_code/ceilometer/.tox/gabbi/lib/python2.7/site-packages/gabbi/case.py", line 282, in _run_test
    json_paths=test['response_json_paths'])
  File "/Users/jasomyer/work_code/ceilometer/.tox/gabbi/lib/python2.7/site-packages/gabbi/case.py", line 96, in _assert_response
    raise ServerError(content)
ServerError: {"error_message": {"faultstring": "unhashable type: 'dict'", "debuginfo": null, "faultcode": "Server"}}

Again the user sees this as a 500, when it should be 400 of sometime since the data failed to validate.

Revision history for this message
ZhiQiang Fan (aji-zqfan) wrote :

as you see, the stack trace shows that it is not releated to ceilometer project
I suggest report it to wsme project

Changed in ceilometer:
assignee: nobody → Mehdi Abaakouk (sileht)
status: Incomplete → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to wsme (master)

Reviewed: https://review.openstack.org/208866
Committed: https://git.openstack.org/cgit/stackforge/wsme/commit/?id=1dc4421b4faeae2474eb982b7603cb0999e5bae3
Submitter: Jenkins
Branch: master

commit 1dc4421b4faeae2474eb982b7603cb0999e5bae3
Author: Mehdi Abaakouk <email address hidden>
Date: Tue Aug 4 09:48:50 2015 +0200

    Return 400, if the query string is not a dict

    When we parse the json object that come in query string,
    we expect to find a dict, but not bail out if that not the case.
    So this will raise a 500.

    This changes this and return 400, because the input is invalid.

    Change-Id: I1a3b927cdfb3b554026306d65a46ed91635d073c
    Closes-bug: #1423634

Changed in wsme:
status: New → Fix Committed
Changed in wsme:
milestone: none → 0.8.0
status: Fix Committed → Fix Released
Changed in ceilometer:
assignee: Mehdi Abaakouk (sileht) → Chris Dent (chdent)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ceilometer (master)

Reviewed: https://review.openstack.org/208467
Committed: https://git.openstack.org/cgit/openstack/ceilometer/commit/?id=d7428b7c3873bb47683c4f4d547fce138b79a74b
Submitter: Jenkins
Branch: master

commit d7428b7c3873bb47683c4f4d547fce138b79a74b
Author: Mehdi Abaakouk <email address hidden>
Date: Mon Aug 3 14:41:42 2015 +0200

    Update tests to reflect WSME 0.8 fixes

    All these bugs are now fixed in wsme 0.8.0

    Closes-bug: #1424642
    Closes-bug: #1423634
    Closes-bug: #1419110
    Closes-bug: #1428185
    Closes-bug: #1428628
    Closes-bug: #1428658
    Closes-bug: #1428624

    Change-Id: Iea8507ebc54f42786a44bfcd96246b88dd998bf0

Changed in ceilometer:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in ceilometer:
milestone: none → liberty-3
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in ceilometer:
milestone: liberty-3 → 5.0.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.