Bug 50046 - [UDM HTTP API] HTTP 500 on POST to groups/group without "superordinate"
[UDM HTTP API] HTTP 500 on POST to groups/group without "superordinate"
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM - REST API
UCS 4.4
Other Linux
: P5 normal (vote)
: ---
Assigned To: Florian Best
Daniel Tröder
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2019-08-23 11:45 CEST by Daniel Tröder
Modified: 2019-10-02 16:06 CEST (History)
2 users (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2019-08-23 11:45:09 CEST
{
    "error": {
        "message": "u'superordinate'",
        "code": 500,
        "traceback": "Traceback (most recent call last):\n  File \"/usr/lib/python2.7/dist-packages/tornado/web.py\", line 1469, in _execute\n    result = yield result\n  File \"/usr/lib/python2.7/dist-packages/tornado/gen.py\", line 1015, in run\n    value = future.result()\n  File \"/usr/lib/python2.7/dist-packages/tornado/concurrent.py\", line 237, in result\n    raise_exc_info(self._exc_info)\n  File \"/usr/lib/python2.7/dist-packages/tornado/gen.py\", line 1021, in run\n    yielded = self.gen.throw(*exc_info)\n  File \"/usr/lib/pymodules/python2.7/univention/management/modules/udm/module.py\", line 2097, in post\n    obj = yield obj.create(object_type)\n  File \"/usr/lib/python2.7/dist-packages/tornado/gen.py\", line 1015, in run\n    value = future.result()\n  File \"/usr/lib/python2.7/dist-packages/tornado/concurrent.py\", line 237, in result\n    raise_exc_info(self._exc_info)\n  File \"/usr/lib/python2.7/dist-packages/tornado/gen.py\", line 285, in wrapper\n    yielded = next(result)\n  File \"/usr/lib/pymodules/python2.7/univention/management/modules/udm/module.py\", line 2405, in create\n    superordinate = self.request.body_arguments['superordinate']\nKeyError: u'superordinate'\n",
        "error": {
        },
        "title": ""
    }
}
Comment 1 Daniel Tröder univentionstaff 2019-08-23 11:48:19 CEST
Same HTTP500 for "options" and "policies". Minimum fro a group is:

{
  "properties": {
          "name": "grp01"
	},
  "position": "cn=klassen,cn=schueler,cn=groups,ou=DEMOSCHOOL,dc=uni,dc=dtr",
  "superordinate": null,
  "options": {},
  "policies": {}
}
Comment 2 Florian Best univentionstaff 2019-09-01 22:26:48 CEST
univention-management-console-module-udm (9.0.12-26)
4564641c221b | Bug #50046: Bug #27816: fix sanitizing of arguments when creating objects via POST
Comment 3 Daniel Tröder univentionstaff 2019-09-12 10:41:03 CEST
Still all three (position, options, policies) are required:

univention-management-console-mod 9.0.14-1


curl -s -X POST -H "Accept:application/json" -H "Content-Type:application/json" -d '{
  "properties": {
    "name": "testgrp01",
    "description": "Text 01", 
    "users": [
            "uid=demo_student,cn=schueler,cn=users,ou=DEMOSCHOOL,dc=uni,dc=dtr", 
            "uid=demo_teacher,cn=lehrer,cn=users,ou=DEMOSCHOOL,dc=uni,dc=dtr"
        ]
}
}'  -u Administrator:univention 'http://m66.uni.dtr/univention/udm/groups/group/' | python -m json.tool
{
    "_links": {
        "curies": [
            {
                "href": "http://m66.uni.dtr/univention/udm/relation/{rel}",
                "name": "udm",
                "templated": true
            }
        ]
    },
    "error": {
        "code": 422,
        "error": {
            "body_arguments": {
                "options": "Argument required",
                "policies": "Argument required",
                "position": "Argument required"
            }
        },
        "message": "3 error(s) occurred:\nRequest argument \"position\" Argument required\nRequest argument \"options\" Argument required\nRequest argument \"policies\" Argument required\n",
        "title": "Unprocessable Entity",
        "traceback": null
    }
}
Comment 4 Florian Best univentionstaff 2019-09-12 11:35:56 CEST
This is on purpose, the request must include all necessary parameters. Use /univention/udm/group/group/add to get a template containing all necessary values, which can be used for a POST request.
Comment 5 Daniel Tröder univentionstaff 2019-09-12 12:30:34 CEST
(In reply to Florian Best from comment #4)
> This is on purpose, the request must include all necessary parameters. Use
> /univention/udm/group/group/add to get a template containing all necessary
> values, which can be used for a POST request.
That is a unnecessary restriction.
Requiring a GET on the template incurs a unnecessary performance penalty.

To create a group nothing more than the "name" property is required:

--------------------------------------------
$ udm groups/group create --set name=testgroup001
WARNING: The object is not going to be created underneath of its default containers.
Object created: cn=testgroup001,dc=uni,dc=dtr
--------------------------------------------

Why would the REST API require options, policies and position, if the cli doesn't?
Comment 6 Ingo Steuwer univentionstaff 2019-09-13 09:37:03 CEST
(In reply to Daniel Tröder from comment #5)

> Why would the REST API require options, policies and position, if the cli
> doesn't?

I think it is reasonable to make paramters which have well defined defaults optional. I expect that far most users will never define options or policies for a group and many of them even don't know what those are good for.
Comment 7 Florian Best univentionstaff 2019-09-22 15:12:01 CEST
I still don't fully agree but I made the changes as you wished.

univention-directory-manager-rest (9.0.16-1)
8016c4d43f0e | Bug #27816: Bug #50046: make position, options, policies in POST create request optional
Comment 8 Florian Best univentionstaff 2019-10-02 16:06:32 CEST
UCS 4.4-2 has been released:
 https://docs.software-univention.de/release-notes-4.4-2-en.html
 https://docs.software-univention.de/release-notes-4.4-2-de.html

If this error occurs again, please use "Clone This Bug".