test case "test_should_raise_container_no_content_type_header" is failing with py34 due to content-type header

Bug #1485452 reported by Pradeep Kumar Singh
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Barbican
Fix Released
Medium
Dave McCowan

Bug Description

ERROR: barbican.tests.api.controllers.test_containers.WhenCreatingContainersUsingContainersResource.test_should_raise_container_no_content_type_header
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pradeep/commit/barbican/barbican/tests/api/controllers/test_containers.py", line 115, in test_should_raise_container_no_content_type_header
    headers={'Content-Type': ''}
  File "/home/pradeep/commit/barbican/barbican/tests/api/controllers/test_containers.py", line 334, in create_container
    headers=headers
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/webtest/utils.py", line 37, in wrapper
    return self._gen_request(method, url, **kw)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/webtest/app.py", line 735, in _gen_request
    expect_errors=expect_errors)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/webtest/app.py", line 605, in do_request
    res = req.get_response(app, catch_exc_info=True)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/webob/request.py", line 1313, in send
    application, catch_exc_info=True)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/webob/request.py", line 1281, in call_application
    app_iter = application(self.environ, start_response)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/webtest/lint.py", line 198, in lint_app
    iterator = application(environ, start_response_wrapper)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/pecan/core.py", line 829, in __call__
    return super(Pecan, self).__call__(environ, start_response)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/pecan/core.py", line 677, in __call__
    controller, args, kwargs = self.find_controller(state)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/pecan/core.py", line 847, in find_controller
    controller, args, kw = super(Pecan, self).find_controller(_state)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/pecan/core.py", line 535, in find_controller
    params = req.params
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/pecan/core.py", line 55, in __getattribute__
    return WebObRequest.__getattribute__(self, name)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/webob/request.py", line 853, in params
    params = NestedMultiDict(self.GET, self.POST)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/pecan/core.py", line 55, in __getattribute__
    return WebObRequest.__getattribute__(self, name)
  File "/home/pradeep/commit/barbican/.tox/py34/lib/python3.4/site-packages/webob/request.py", line 802, in POST
    encoding='utf8')
  File "/usr/lib/python3.4/cgi.py", line 561, in __init__
    self.read_single()
  File "/usr/lib/python3.4/cgi.py", line 724, in read_single
    self.read_binary()
  File "/usr/lib/python3.4/cgi.py", line 747, in read_binary
    self.file.write(data)
TypeError: must be str, not bytes

May be its due to https://bugs.python.org/issue24764.
When i removed the content-type header exception is not thrown.

Revision history for this message
Dave McCowan (dave-mccowan) wrote :

I don't think we need this bug. The failure is PY34 only, and can be fixed under the PY34 blueprint.

The issue is here:
In barbican/api/controllers/containers.py, line 171:
    @controllers.enforce_content_types(['application/json'])

This is a string passed in through the decorator which needs to be bytes later.

Revision history for this message
Pradeep Kumar Singh (pradeep-singh-u) wrote :

Hi Dave,

Thanks for your input.
I tried to comment out the line you mentioned and i also converted the input str to bytes but issue still persists.

Changed in barbican:
assignee: nobody → Dave McCowan (dave-mccowan)
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/219774

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to barbican (master)

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

commit c4d662c4077479e22ca7e40d658eecb499f4d718
Author: Dave McCowan <email address hidden>
Date: Wed Sep 2 12:05:20 2015 -0400

    Change test_containers unit test to work around webtest issue

    The test_should_raise_container_no_content_type_header() is
    misnamed. In this test, the Content-type: header is sent, but
    there is no value sent with it.

    When webtest processed this request with Python3, it hit an infamous
    sting/bytes issue while sending the POST. The issue was hit in webtest
    and cgi code, not in Barbican code.

    From a Barbican point of view, testing
       Content-type: \r\n
    and
       Content-type: bad_content_type\r\n
    runs through the same code, fails the same test, and throws the
    same exception.

    Therefore, I propose we rename and change the test case to the second
    case. Webtest does not have a problem handling this test in Python3.
    The same conditions are tested and verified for Python2 and 3.

    Change-Id: I22d597e61fc37d24526e4dac554983108ceaa507
    Related-blueprint: blueprint barbican-py3
    Closes-bug: #1485452

Changed in barbican:
status: In Progress → Fix Committed
Changed in barbican:
status: Fix Committed → Fix Released
Changed in barbican:
milestone: none → mitaka-1
importance: Undecided → Medium
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.