From a93fc02af6eb50ecb0cfc69174c9f385d60bbbb3 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 23 Sep 2013 10:46:01 +0200 Subject: Raise an error when updating CIDict with duplicate keys Updating a CIDict with data like {'A': 1, 'a': 2} would lead to data loss since only one of the items would get to the CIDict. This can result in non-obvious bugs similar to this one in python-ldap: https://bugzilla.redhat.com/show_bug.cgi?id=1007820 Raise an error in this case; any resolution must be done by the caller. --- ipatests/test_ipapython/test_ipautil.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ipatests/test_ipapython/test_ipautil.py') diff --git a/ipatests/test_ipapython/test_ipautil.py b/ipatests/test_ipapython/test_ipautil.py index a8a73edc..04a43990 100644 --- a/ipatests/test_ipapython/test_ipautil.py +++ b/ipatests/test_ipapython/test_ipautil.py @@ -243,6 +243,18 @@ class TestCIDict(object): 'a': 'va', 'b': 'vb', 'Key1': 'val1', 'key2': 'val2', 'KEY3': 'VAL3'} + def test_update_duplicate_values_dict(self): + with nose.tools.assert_raises(ValueError): + self.cidict.update({'a': 'va', 'A': None, 'b': 3}) + + def test_update_duplicate_values_list(self): + with nose.tools.assert_raises(ValueError): + self.cidict.update([('a', 'va'), ('A', None), ('b', 3)]) + + def test_update_duplicate_values_kwargs(self): + with nose.tools.assert_raises(ValueError): + self.cidict.update(a='va', A=None, b=3) + def test_update_kwargs(self): self.cidict.update(b='vb', key2='val2') assert dict(self.cidict.items()) == { -- cgit