From 1235dfa7bf4b249eb6da8eab8d8a2c7b0eef98db Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 17 Apr 2012 12:42:35 -0400 Subject: Fail on unknown Command options When unknown keyword arguments are passed to a Command, raise an error instead of ignoring them. Options used when IPA calls its commands internally are listed in a new Command attribute called internal_options, and allowed. Previous patches (0b01751c, c45174d6, c5689e7f) made IPA not use unknown keyword arguments in its own commands and tests, but since that some violations were reintroduced in permission_find and tests. Fix those. Tests included; both a frontend unittest and a XML-RPC test via the ping plugin (which was untested previously). https://fedorahosted.org/freeipa/ticket/2509 --- ipalib/frontend.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'ipalib/frontend.py') diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 10087ba24..c28fa54ae 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -29,7 +29,8 @@ from parameters import create_param, parse_param_spec, Param, Str, Flag, Passwor from output import Output, Entry, ListOfEntries from text import _, ngettext -from errors import ZeroArgumentError, MaxArgumentError, OverlapError, RequiresRoot, VersionError, RequirementError +from errors import (ZeroArgumentError, MaxArgumentError, OverlapError, + RequiresRoot, VersionError, RequirementError, OptionError) from errors import InvocationError from constants import TYPE_ERROR from ipapython.version import API_VERSION @@ -404,6 +405,8 @@ class Command(HasParam): output_params = Plugin.finalize_attr('output_params') has_output_params = tuple() + internal_options = tuple() + msg_summary = None msg_truncated = _('Results are truncated, try a more specific search') @@ -520,7 +523,13 @@ class Command(HasParam): def __options_2_params(self, options): for name in self.params: if name in options: - yield (name, options[name]) + yield (name, options.pop(name)) + # If any options remain, they are either internal or unknown + unused_keys = set(options).difference(self.internal_options) + unused_keys.discard('version') + if unused_keys: + raise OptionError(_('Unknown option: %(option)s'), + option=unused_keys.pop()) def args_options_2_entry(self, *args, **options): """ -- cgit