Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Authors: # Jr Aquino <jr.aquino@citrixonline.com> # Pavel Zuna <pzuna@redhat.com> # # Copyright (C) 2010 Red Hat # see file 'COPYING' for use and warranty information # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. Test the `ipalib/plugins/sudorule.py` module. """
""" Test the `sudorule` plugin. """
""" Test adding a new Sudo rule using `xmlrpc.sudorule_add`. """ self.rule_name, description=self.rule_desc, )
""" Test adding an duplicate Sudo rule using `xmlrpc.sudorule_add'. """ self.rule_name ) else: assert False
""" Test displaying a Sudo rule using `xmlrpc.sudorule_show`. """
""" Test modifying a Sudo rule using `xmlrpc.sudorule_mod`. """ self.rule_name, description=self.rule_desc_mod )
""" Test searching for Sudo rules using `xmlrpc.sudorule_find`. """ name=self.rule_name, description=self.rule_desc_mod )
""" Initialize data for more Sudo rule plugin testing. """ self.test_user, givenname=u'first', sn=u'last' ) self.test_runasuser, givenname=u'first', sn=u'last' ) self.test_group, description=u'description' ) self.test_host, force=True ) self.failsafe_add(api.Object.hostgroup, self.test_hostgroup, description=u'description' ) self.failsafe_add(api.Object.sudocmdgroup, self.test_sudoallowcmdgroup, description=u'desc' ) self.failsafe_add(api.Object.sudocmdgroup, self.test_sudodenycmdgroup, description=u'desc' ) self.failsafe_add(api.Object.sudocmd, self.test_command, description=u'desc', force=True )
""" Test adding user and group to Sudo rule using `xmlrpc.sudorule_add_user`. """ self.rule_name, user=self.test_user, group=self.test_group )
""" Test showing a user to verify Sudo rule membership `xmlrpc.user_show`. """
""" Test showing a group to verify Sudo rule membership `xmlrpc.group_show`. """
""" Test removing user and group from Sudo rule using `xmlrpc.sudorule_remove_user'. """ self.rule_name, user=self.test_user, group=self.test_group )
""" Test adding run as user to Sudo rule using `xmlrpc.sudorule_add_runasuser`. """ self.rule_name, user=self.test_runasuser )
""" Test removing run as user to Sudo rule using `xmlrpc.sudorule_remove_runasuser'. """ self.rule_name, user=self.test_runasuser )
""" Test adding run as group to Sudo rule using `xmlrpc.sudorule_add_runasgroup`. """ self.rule_name, group=self.test_runasgroup ) self.test_runasgroup)
""" Test removing run as group to Sudo rule using `xmlrpc.sudorule_remove_runasgroup'. """ self.rule_name, group=self.test_runasgroup )
""" Test adding an external user to Sudo rule using `xmlrpc.sudorule_add_user`. """ self.rule_name, user=self.test_external_user )
""" Test removing an external user from Sudo rule using `xmlrpc.sudorule_remove_user'. """ self.rule_name, user=self.test_external_user )
""" Test adding an external runasuser to Sudo rule using `xmlrpc.sudorule_add_runasuser`. """ self.rule_name, user=self.test_external_user )
""" Test removing an external runasuser from Sudo rule using `xmlrpc.sudorule_remove_runasuser'. """ self.rule_name, user=self.test_external_user )
""" Test adding an external runasgroup to Sudo rule using `xmlrpc.sudorule_add_runasgroup`. """ self.rule_name, group=self.test_external_group )
""" Test removing an external runasgroup from Sudo rule using `xmlrpc.sudorule_remove_runasgroup'. """ self.rule_name, group=self.test_external_group )
""" Test adding an option to Sudo rule using `xmlrpc.sudorule_add_option`. """ self.rule_name, ipasudoopt=self.test_option )
""" Test removing an option from Sudo rule using `xmlrpc.sudorule_remove_option'. """ self.rule_name, ipasudoopt=self.test_option )
""" Test adding host and hostgroup to Sudo rule using `xmlrpc.sudorule_add_host`. """ self.rule_name, host=self.test_host, hostgroup=self.test_hostgroup ) failed = ret['failed'] assert 'memberhost' in failed assert 'host' in failed['memberhost'] assert not failed['memberhost']['host'] assert 'hostgroup' in failed['memberhost'] assert not failed['memberhost']['hostgroup'] entry = ret['result'] assert_attr_equal(entry, 'memberhost_host', self.test_host) assert_attr_equal(entry, 'memberhost_hostgroup', self.test_hostgroup)
""" Test showing host to verify Sudo rule membership `xmlrpc.host_show`. """ entry = ret['result'] assert_attr_equal(entry, 'memberof_sudorule', self.rule_name)
""" Test showing hostgroup to verify Sudo rule membership `xmlrpc.hostgroup_show`. """ entry = ret['result'] assert_attr_equal(entry, 'memberof_sudorule', self.rule_name)
""" Test removing host and hostgroup from Sudo rule using `xmlrpc.sudorule_remove_host`. """ self.rule_name, host=self.test_host, hostgroup=self.test_hostgroup ) failed = ret['failed'] assert 'memberhost' in failed assert 'host' in failed['memberhost'] assert not failed['memberhost']['host'] assert 'hostgroup' in failed['memberhost'] assert not failed['memberhost']['hostgroup'] entry = ret['result'] assert 'memberhost_host' not in entry assert 'memberhost_hostgroup' not in entry
""" Test adding an external host to Sudo rule using `xmlrpc.sudorule_add_host`. """ self.rule_name, host=self.test_external_host )
""" Test removing an external host from Sudo rule using `xmlrpc.sudorule_remove_host`. """ self.rule_name, host=self.test_external_host )
""" Test adding allow command and cmdgroup to Sudo rule using `xmlrpc.sudorule_add_allow_command`. """ self.rule_name, sudocmd=self.test_command, sudocmdgroup=self.test_sudoallowcmdgroup ) failed = ret['failed'] assert 'memberallowcmd' in failed assert 'sudocmd' in failed['memberallowcmd'] assert not failed['memberallowcmd']['sudocmd'] assert 'sudocmdgroup' in failed['memberallowcmd'] assert not failed['memberallowcmd']['sudocmdgroup'] entry = ret['result'] assert_attr_equal(entry, 'memberallowcmd_sudocmd', self.test_command) assert_attr_equal(entry, 'memberallowcmd_sudocmdgroup', self.test_sudoallowcmdgroup)
""" Test removing allow command and sudocmdgroup from Sudo rule using `xmlrpc.sudorule_remove_command`. """ self.rule_name, sudocmd=self.test_command, sudocmdgroup=self.test_sudoallowcmdgroup ) failed = ret['failed'] assert 'memberallowcmd' in failed assert 'sudocmd' in failed['memberallowcmd'] assert not failed['memberallowcmd']['sudocmd'] assert 'sudocmdgroup' in failed['memberallowcmd'] assert not failed['memberallowcmd']['sudocmdgroup'] entry = ret['result'] assert 'memberallowcmd_sudocmd' not in entry assert 'memberallowcmd_sudocmdgroup' not in entry
""" Test adding deny command and cmdgroup to Sudo rule using `xmlrpc.sudorule_add_deny_command`. """ self.rule_name, sudocmd=self.test_command, sudocmdgroup=self.test_sudodenycmdgroup ) failed = ret['failed'] assert 'memberdenycmd' in failed assert 'sudocmd' in failed['memberdenycmd'] assert not failed['memberdenycmd']['sudocmd'] assert 'sudocmdgroup' in failed['memberdenycmd'] assert not failed['memberdenycmd']['sudocmdgroup'] entry = ret['result'] assert_attr_equal(entry, 'memberdenycmd_sudocmd', self.test_command) assert_attr_equal(entry, 'memberdenycmd_sudocmdgroup', self.test_sudodenycmdgroup)
""" Test removing deny command and sudocmdgroup from Sudo rule using `xmlrpc.sudorule_remove_deny_command`. """ self.rule_name, sudocmd=self.test_command, sudocmdgroup=self.test_sudodenycmdgroup ) failed = ret['failed'] assert 'memberdenycmd' in failed assert 'sudocmd' in failed['memberdenycmd'] assert not failed['memberdenycmd']['sudocmd'] assert 'sudocmdgroup' in failed['memberdenycmd'] assert not failed['memberdenycmd']['sudocmdgroup'] entry = ret['result'] assert 'memberdenycmd_sudocmd' not in entry assert 'memberdenycmd_sudocmdgroup' not in entry
""" Test adding a user to an Sudo rule when usercat='all' """
""" Test setting usercat='all' in an Sudo rule when there are users """ except errors.MutuallyExclusiveError: pass finally:
""" Test adding a host to an Sudo rule when hostcat='all' """
""" Test setting hostcat='all' in an Sudo rule when there are hosts """ except errors.MutuallyExclusiveError: pass finally:
""" Test adding a command to an Sudo rule when cmdcategory='all' """
""" Test setting cmdcategory='all' in an Sudo rule when there are commands """ except errors.MutuallyExclusiveError: pass finally:
""" Test adding a runasuser to an Sudo rule when ipasudorunasusercategory='all' """
""" Test setting ipasudorunasusercategory='all' in an Sudo rule when there are runas users """ finally:
""" Clear data for Sudo rule plugin testing. """ api.Command['hostgroup_del'](self.test_hostgroup) api.Command['sudocmd_del'](self.test_command) api.Command['sudocmdgroup_del'](self.test_sudoallowcmdgroup) api.Command['sudocmdgroup_del'](self.test_sudodenycmdgroup)
""" Test deleting a Sudo rule using `xmlrpc.sudorule_del`. """ # verify that it's gone else: assert False |