Bug 52949 - UDM REST API does not handle duplicate phone entries
UDM REST API does not handle duplicate phone entries
Status: RESOLVED MOVED
Product: UCS
Classification: Unclassified
Component: UDM - REST API
UCS 4.4
Other Linux
: P5 normal (vote)
: ---
Assigned To: Florian Best
UMC maintainers
https://git.knut.univention.de/univen...
:
: 52948 (view as bug list)
Depends on: 52948
Blocks:
  Show dependency treegraph
 
Reported: 2021-03-18 10:33 CET by Daniel Tröder
Modified: 2022-04-20 23:23 CEST (History)
1 user (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 3: Simply Wrong: The implementation doesn't match the docu
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 2: A Pain – users won’t like this once they notice it
User Pain: 0.069
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:
best: Patch_Available+


Attachments
patch (obsoleted by git:fbest/52949-uldap-modlist-remove-duplicates) (971 bytes, patch)
2021-03-18 11:17 CET, Florian Best
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2021-03-18 10:33:47 CET
+++ This bug was initially created as a clone of Bug #52948 +++

The UDM CLI handles it robustly:
-----------------------------------------------------------------------------
root@m20:~# udm users/user list --filter uid=Administrator | grep phone
root@m20:~# udm users/user modify --dn uid=Administrator,cn=users,dc=uni,dc=dtr --append phone=123 
Object modified: uid=Administrator,cn=users,dc=uni,dc=dtr
root@m20:~# udm users/user list --filter uid=Administrator | grep phone
  phone: 123
root@m20:~# udm users/user modify --dn uid=Administrator,cn=users,dc=uni,dc=dtr --append phone=123 
WARNING: cannot append 123 to phone, value exists
No modification: uid=Administrator,cn=users,dc=uni,dc=dtr
root@m20:~# udm users/user modify --dn uid=Administrator,cn=users,dc=uni,dc=dtr --append phone=456 --append phone=123 
WARNING: cannot append 123 to phone, value exists
Object modified: uid=Administrator,cn=users,dc=uni,dc=dtr
root@m20:~# udm users/user list --filter uid=Administrator | grep phone
  phone: 123
  phone: 456
-----------------------------------------------------------------------------

The UDM Python lib also:
-----------------------------------------------------------------------------
root@m20:~# python
>>> from univention.udm import UDM
>>> user_mod = UDM.admin().version(0).get('users/user')
>>> user = user_mod.get("uid=Administrator,cn=users,dc=uni,dc=dtr")
>>> user.props.phone
['123', '456']
>>> user.props.phone.append("123")
>>> user.save()
>>> user = user_mod.get("uid=Administrator,cn=users,dc=uni,dc=dtr")
>>> user.props.phone
['123', '456']
-----------------------------------------------------------------------------

But the UMC module shows an error popup when saving a duplicate phone entry:
-----------------------------------------------------------------------------
Das LDAP-Objekt konnte nicht gespeichert werden: LDAP-Fehler Type or value exists: telephoneNumber: value #0 provided more than once
-----------------------------------------------------------------------------

This behavior cannot be observed when saving duplicate "departmentNumber" entries.

The UMC should handle duplicate entries in the multi value field "email" robustly.

==========================================================================
==========================================================================

The UDM REST API returns HTTP 500 when a duplicate phone number is sent. From directory-manager-rest.log:

-----------------------------------------------------------------------------
16.03.21 14:08:39       ERROR      (    26160) : Uncaught exception PATCH /udm/users/user/uid=test.Katie62.Mo,cn=mitarbeiter,cn=users,ou=DEMOSCHOOL,dc=uni,dc=dtr (0.0.0
.0)
    HTTPServerRequest(protocol='http', host='m20.uni.dtr', method='PATCH', uri='/udm/users/user/uid=test.Katie62.Mo,cn=mitarbeiter,cn=users,ou=DEMOSCHOOL,dc=uni,dc=dtr'
, version='HTTP/1.1', remote_ip='0.0.0.0', headers={'X-Umc-Https': 'on', 'Content-Length': '505', 'Via': '1.1 m20.uni.dtr', 'Accept-Encoding': 'gzip, deflate', 'X-Forwa
rded-Host': 'm20.uni.dtr', 'X-Forwarded-For': '172.17.0.1', 'Host': 'm20.uni.dtr', 'Accept': 'application/json', 'User-Agent': 'OpenAPI-Generator/1.0.0/python', 'Connec
tion': 'close', 'X-Forwarded-Proto': 'https', 'X-Forwarded-Server': 'm20.uni.dtr', 'Content-Type': 'application/json', 'X-Forwarded-Ssl': 'on', 'Authorization': 'Basic 
Y249YWRtaW46dlFscmhyNkJleVlvNFo0dUo4MXc='})
    Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1469, in _execute
        result = yield result
      File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 1015, in run
        value = future.result()
      File "/usr/lib/python2.7/dist-packages/tornado/concurrent.py", line 237, in result
        raise_exc_info(self._exc_info)
      File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 1021, in run
        yielded = self.gen.throw(*exc_info)
      File "/usr/lib/python2.7/dist-packages/univention/admin/rest/module.py", line 2839, in patch
        obj = yield self.modify(module, obj)
      File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 1015, in run
        value = future.result()
      File "/usr/lib/python2.7/dist-packages/tornado/concurrent.py", line 237, in result
        raise_exc_info(self._exc_info)
      File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 1021, in run
        yielded = self.gen.throw(*exc_info)
      File "/usr/lib/python2.7/dist-packages/univention/admin/rest/module.py", line 2878, in modify
        yield self.pool.submit(self.handle_udm_errors, obj.modify)
      File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 1015, in run
        value = future.result()
      File "/usr/lib/python2.7/dist-packages/concurrent/futures/_base.py", line 398, in result
        return self.__get_result()
      File "/usr/lib/python2.7/dist-packages/concurrent/futures/thread.py", line 55, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/usr/lib/python2.7/dist-packages/univention/admin/rest/module.py", line 2930, in handle_udm_errors
        UDM_Error(exc).reraise()
      File "/usr/lib/python2.7/dist-packages/univention/admin/rest/module.py", line 2886, in handle_udm_errors
        return action()
      File "/usr/lib/python2.7/dist-packages/univention/admin/handlers/users/user.py", line 1410, in modify
        return super(object, self).modify(*args, **kwargs)
      File "/usr/lib/python2.7/dist-packages/univention/admin/handlers/__init__.py", line 650, in modify
        dn = self._modify(modify_childs, ignore_license=ignore_license, response=response)
      File "/usr/lib/python2.7/dist-packages/univention/admin/handlers/__init__.py", line 1330, in _modify
        self.dn = self.lo.modify(self.dn, ml, ignore_license=ignore_license, serverctrls=serverctrls, response=response)
      File "/usr/lib/python2.7/dist-packages/univention/admin/uldap.py", line 902, in modify
        raise univention.admin.uexceptions.ldapError(_err2str(msg), original_exception=msg)
    UDM_Error: LDAP Error Type or value exists: telephoneNumber: value #0 provided more than once
-----------------------------------------------------------------------------

The client had sent a PATCH request including {.., "phone": ["Jeffrey", "Jeffrey"]}.

The UDM REST API should handle duplicate entries in the multi value field "email" robustly.
Comment 1 Florian Best univentionstaff 2021-03-18 11:15:57 CET
*** Bug 52948 has been marked as a duplicate of this bug. ***
Comment 2 Florian Best univentionstaff 2021-03-18 11:17:07 CET
Created attachment 10652 [details]
patch (obsoleted by git:fbest/52949-uldap-modlist-remove-duplicates)

Attached is a patch which sorts out duplicated in univention.uldap directly.

Is this the wanted behavior? Or should we raise a exception if the user supplied duplicated values?
Comment 3 Florian Best univentionstaff 2021-03-25 18:08:45 CET
(In reply to Florian Best from comment #2)
> Created attachment 10652 [details]
> patch
> 
> Attached is a patch which sorts out duplicated in univention.uldap directly.
> 
> Is this the wanted behavior? Or should we raise a exception if the user
> supplied duplicated values?

Updated patch in git:fbest/52949-uldap-modlist-remove-duplicates.
The patch did not take into account that a modlist may contain None.