Bug 50053 - fix simpleLdap.__setitem__() side effects
fix simpleLdap.__setitem__() side effects
Status: NEW
Product: UCS
Classification: Unclassified
Component: UDM (Generic)
UCS 4.4
Other Linux
: P5 normal (vote)
: ---
Assigned To: UMC maintainers
UMC maintainers
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2019-08-25 18:51 CEST by Florian Best
Modified: 2019-09-26 16:12 CEST (History)
0 users

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 Florian Best univentionstaff 2019-08-25 18:51:49 CEST
univention.admin.simeLdap.__setitem__() has some unwanted behavior:

1.
For properties which cannot be modified, it raises univention.admin.uexceptions.valueMayNotChange but even if the value is equal to the currently set value.
When fixing this, please note, that the comparision for equality needs to be done after syntax.parse() which may normalize the format!

>>> o['unlockTime'] = o['unlockTime']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 396, in __setitem__
    raise univention.admin.uexceptions.valueMayNotChange(_('key=%(key)s old=%(old)s new=%(new)s') % {'key': key, 'old': self[key], 'new': value})
univention.admin.uexceptions.valueMayNotChange: key=unlockTime old=None new=None

2. When setting a property to an equal value, it just doesn't replace it. This is evil for lists:

>>> obj['foo']
['bar']
>>> l = ['bar']
>>> obj['foo'] = l
>>> l.append('blub')
>>> obj['foo']
['bar']

3. If the property is required, setting a value to 0 or another false-ish value causes a univention.admin.uexceptions.valueRequired exception.

>>> o['username'] = 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 399, in __setitem__
    raise univention.admin.uexceptions.valueRequired, _('The property %s is required') % self.descriptions[key].short_description
univention.admin.uexceptions.valueRequired: The property User name is required

4. When checking for equality of a multivalue property it compares None == [] (because self.info.get(key) is None and not []).
Setting lists works:
>>> obj['some_multivalue_property'] = []
Setting None doesn't:
>>> o['groups'] = None
>>> o.info['groups']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'groups'

This influences also the handling of self.__no_default.

(5. Unsetting a value by setting it to None is not supported by all syntax classes, and therefore sometimes raises TypeError or univention.admin.uexceptions.valueInvalidSyntax).

>>> o['roomNumber'] = None
Traceback (most recent call last):                                           
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 414, in __setitem__
    raise univention.admin.uexceptions.valueInvalidSyntax(key)               
univention.admin.uexceptions.valueInvalidSyntax: roomNumber