diff options
author | Petr Viktorin <pviktori@redhat.com> | 2012-04-27 06:07:16 -0400 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2012-05-07 17:23:08 +0200 |
commit | abef5e8c027bf37d9522f4d30e8e43c408251893 (patch) | |
tree | 8aa414f6cf7746f947b0509144bd70d25489c4e6 | |
parent | 0206dbe79502dd06b9c44622ead4635e430e3620 (diff) | |
download | freeipa-abef5e8c027bf37d9522f4d30e8e43c408251893.tar.gz freeipa-abef5e8c027bf37d9522f4d30e8e43c408251893.tar.xz freeipa-abef5e8c027bf37d9522f4d30e8e43c408251893.zip |
Do not crash on empty --setattr, --getattr, --addattr
Also the unused `append` argument from _convert_2_dict.
https://fedorahosted.org/freeipa/ticket/2680
-rw-r--r-- | ipalib/plugins/baseldap.py | 16 | ||||
-rw-r--r-- | tests/test_xmlrpc/test_attr.py | 3 |
2 files changed, 10 insertions, 9 deletions
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py index 5a8013efc..e4f8cdc69 100644 --- a/ipalib/plugins/baseldap.py +++ b/ipalib/plugins/baseldap.py @@ -791,18 +791,18 @@ last, after all sets and adds."""), exclude='webui', ) - def _convert_2_dict(self, attrs, append=True): + def _convert_2_dict(self, attrs): """ Convert a string in the form of name/value pairs into a dictionary. - The incoming attribute may be a string or a list. - :param attrs: A list of name/value pairs - - :param append: controls whether this returns a list of values or a single - value. + :param attrs: A list of name/value pair strings, in the "name=value" + format. May also be a single string, or None. """ + newdict = {} - if not type(attrs) in (list, tuple): + if attrs is None: + attrs = [] + elif not type(attrs) in (list, tuple): attrs = [attrs] for a in attrs: m = re.match("\s*(.*?)\s*=\s*(.*?)\s*$", a) @@ -811,7 +811,7 @@ last, after all sets and adds."""), if len(value) == 0: # None means "delete this attribute" value = None - if append and attr in newdict: + if attr in newdict: if type(value) in (tuple,): newdict[attr] += list(value) else: diff --git a/tests/test_xmlrpc/test_attr.py b/tests/test_xmlrpc/test_attr.py index 6877a6306..5916ebd2d 100644 --- a/tests/test_xmlrpc/test_attr.py +++ b/tests/test_xmlrpc/test_attr.py @@ -39,7 +39,8 @@ class test_attr(Declarative): dict( desc='Create %r' % user1, command=( - 'user_add', [user1], dict(givenname=u'Test', sn=u'User1') + 'user_add', [user1], dict(givenname=u'Test', sn=u'User1', + setattr=None) ), expected=dict( value=user1, |