summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2012-06-15 09:08:55 -0400
committerRob Crittenden <rcritten@redhat.com>2012-06-25 22:04:14 -0400
commit3021b3e9d5f69a2a604921a6203962ffc57b9d79 (patch)
treee40d7fbd8770b5a7ed6d4251d99eefd0a860fdf1 /ipalib
parentec5115a15513b40f7ef5d2bcf4f5e66c139f5d87 (diff)
downloadfreeipa-3021b3e9d5f69a2a604921a6203962ffc57b9d79.tar.gz
freeipa-3021b3e9d5f69a2a604921a6203962ffc57b9d79.tar.xz
freeipa-3021b3e9d5f69a2a604921a6203962ffc57b9d79.zip
Improve output validation
We only checked the length of Command output dictionaries. A misspelled key in would not be caught. Fix the problem by checking if the sets of keys are equal. Add a test. Split the test methods into more manageable pieces. https://fedorahosted.org/freeipa/ticket/2860
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/frontend.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index c28fa54ae..fadcb8632 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -913,16 +913,19 @@ class Command(HasParam):
raise TypeError('%s: need a %r; got a %r: %r' % (
nice, dict, type(output), output)
)
- if len(output) < len(self.output):
- missing = sorted(set(self.output).difference(output))
- raise ValueError('%s: missing keys %r in %r' % (
- nice, missing, output)
- )
- if len(output) > len(self.output):
- extra = sorted(set(output).difference(self.output))
- raise ValueError('%s: unexpected keys %r in %r' % (
- nice, extra, output)
- )
+ expected_set = set(self.output)
+ actual_set = set(output)
+ if expected_set != actual_set:
+ missing = expected_set - actual_set
+ if missing:
+ raise ValueError('%s: missing keys %r in %r' % (
+ nice, sorted(missing), output)
+ )
+ extra = actual_set - expected_set
+ if extra:
+ raise ValueError('%s: unexpected keys %r in %r' % (
+ nice, sorted(extra), output)
+ )
for o in self.output():
value = output[o.name]
if not (o.type is None or isinstance(value, o.type)):