POST to containes resource gives http 400 when name is None

Bug #1354767 reported by Steve Heyman
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Barbican
Fix Released
Medium
Juan Antonio Osorio Robles

Bug Description

POST to containers resource to create a container fails with HTTP 400 when name is None.

API documentation says name is optional. Passing in a blank for name is acceptable and results in the expect HTTP 201. However, passing name as None causes the 400 error....the json schema validation fails.

Failing test is test_create_generic_container_w_empty_or_null_name_null (data driven).

Steve Heyman (sheyman)
Changed in barbican:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Adam Harwell (adam-harwell) wrote :

I can't seem to replicate this manually...

http://i.imgur.com/8avoQfH.png

In this example, I didn't pass a name, but the container was created successfully.

http://i.imgur.com/GlbhTCn.png

Revision history for this message
Steve Heyman (sheyman) wrote :

The parsed json looks like this:

{u'type': u'generic', u'name': None, u'secret_refs': []}

Its failing validation - and raising the error here: https://github.com/openstack/barbican/blob/master/barbican/api/__init__.py#L76

Revision history for this message
Steve Heyman (sheyman) wrote :

and the stack:

2014-08-10 09:12:28.691 87709 TRACE barbican.api Traceback (most recent call last):
2014-08-10 09:12:28.691 87709 TRACE barbican.api File "/Users/step6927/barbican/barbican/api/__init__.py", line 74, in load_body
2014-08-10 09:12:28.691 87709 TRACE barbican.api parsed_body = validator.validate(parsed_body)
2014-08-10 09:12:28.691 87709 TRACE barbican.api File "/Users/step6927/barbican/barbican/common/validators.py", line 366, in validate
2014-08-10 09:12:28.691 87709 TRACE barbican.api self._assert_schema_is_valid(json_data, schema_name)
2014-08-10 09:12:28.691 87709 TRACE barbican.api File "/Users/step6927/barbican/barbican/common/validators.py", line 92, in _assert_schema_is_valid
2014-08-10 09:12:28.691 87709 TRACE barbican.api property=get_invalid_property(e))
2014-08-10 09:12:28.691 87709 TRACE barbican.api InvalidObject: Provided object does not match schema 'Container': None is not of type 'string'

Revision history for this message
Venkat Sundaram (tsv) wrote :

I am able to reproduce it with the following request JSON body:

{ "name": null }

Please note that None is not a valid JSON type and so the equivalent of null has to be used. If instead None is passed as the value for "name" above, it will result in a "HTTP 400 Malformed JSON" error and that is the correct thing for the server to do.

I think Barbican fails the request with HTTP 400 because the corresponding schema expects the type of "name" to be a string. This could be fixed by changing the following schema (barbican/common/validators.py) from:

        self.schema = {
            "type": "object",
            "properties": {
                "name": {"type": "string"},

to:

        self.schema = {
            "type": "object",
            "properties": {
                "name": {"type": ["string","null"]},

Steve,
I see same behavior for secret creation as well.
If you agree I can fix these two and propose a CR.

Revision history for this message
Adam Harwell (adam-harwell) wrote :

Ah, yeah, I am able to replicate by explicitly passing: "name": null

This is a really weird case, but Venkat's change definitely works.

Revision history for this message
Steve Heyman (sheyman) wrote :

Ditto - I tested it too. If we think that its a valid (but weird) scenario then Venkat has it nailed with that update to the schema. My vote is to make the change.

Changed in barbican:
milestone: none → kilo-1
Changed in barbican:
milestone: kilo-1 → none
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/142181
Committed: https://git.openstack.org/cgit/openstack/barbican/commit/?id=f4b929e94db4179ca0feaf36f4debcecdc66f0f5
Submitter: Jenkins
Branch: master

commit f4b929e94db4179ca0feaf36f4debcecdc66f0f5
Author: Juan Antonio Osorio Robles <email address hidden>
Date: Tue Dec 16 20:38:00 2014 +0200

    Support containers without a name

    In the documentation we state that we actually support creating
    containers without specifying a name, but this was not the case in
    practice. This CR fixes that.

    Change-Id: Id420fd7d91bff518265da65b002d42f57c6f3914
    Closes-bug: #1354767

Changed in barbican:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in barbican:
milestone: none → kilo-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in barbican:
milestone: kilo-1 → 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.