Imported Upstream version 4.0.5
This commit is contained in:
@@ -17,11 +17,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
|
||||
from ipatests.test_integration.base import IntegrationTest
|
||||
from ipatests.pytest_plugins.integration.tasks import (
|
||||
clear_sssd_cache, get_host_ip_with_hostmask, modify_sssd_conf)
|
||||
from ipatests.test_integration.tasks import clear_sssd_cache
|
||||
|
||||
|
||||
class TestSudo(IntegrationTest):
|
||||
@@ -33,12 +30,10 @@ class TestSudo(IntegrationTest):
|
||||
topology = 'line'
|
||||
|
||||
@classmethod
|
||||
def install(cls, mh):
|
||||
super(TestSudo, cls).install(mh)
|
||||
def setup_class(cls):
|
||||
super(TestSudo, cls).setup_class()
|
||||
|
||||
cls.client = cls.clients[0]
|
||||
cls.clientname = cls.client.run_command(
|
||||
['hostname', '-s']).stdout_text.strip()
|
||||
|
||||
for i in range(1, 3):
|
||||
# Add 1. and 2. testing user
|
||||
@@ -74,25 +69,17 @@ class TestSudo(IntegrationTest):
|
||||
'-G', 'localgroup',
|
||||
'localuser'])
|
||||
|
||||
# Create sudorule 'defaults' for not requiring authentication
|
||||
cls.master.run_command(['ipa', 'sudorule-add', 'defaults'])
|
||||
cls.master.run_command(['ipa', 'sudorule-add-option',
|
||||
'defaults',
|
||||
'--sudooption', "!authenticate"])
|
||||
|
||||
|
||||
@classmethod
|
||||
def uninstall(cls, mh):
|
||||
def teardown_class(cls):
|
||||
cls.client.run_command(['groupdel', 'localgroup'], raiseonerr=False)
|
||||
cls.client.run_command(['userdel', 'localuser'], raiseonerr=False)
|
||||
super(TestSudo, cls).uninstall(mh)
|
||||
super(TestSudo, cls).teardown_class()
|
||||
|
||||
def list_sudo_commands(self, user, raiseonerr=False, verbose=False):
|
||||
clear_sssd_cache(self.client)
|
||||
list_flag = '-ll' if verbose else '-l'
|
||||
return self.client.run_command(
|
||||
'su -c "sudo %s -n" %s' % (list_flag, user),
|
||||
raiseonerr=raiseonerr)
|
||||
return self.client.run_command('su -c "sudo %s" %s' % (list_flag, user),
|
||||
raiseonerr=raiseonerr)
|
||||
|
||||
def reset_rule_categories(self, safe_delete=True):
|
||||
if safe_delete:
|
||||
@@ -178,16 +165,6 @@ class TestSudo(IntegrationTest):
|
||||
|
||||
result2 = self.list_sudo_commands("testuser2", raiseonerr=False)
|
||||
assert result2.returncode != 0
|
||||
assert "Sorry, user testuser2 may not run sudo on {}.".format(
|
||||
self.clientname) in result2.stderr_text
|
||||
|
||||
def test_sudo_rule_restricted_to_one_user_without_defaults_rule(self):
|
||||
# Verify password is requested with the 'defaults' sudorule disabled
|
||||
self.master.run_command(['ipa', 'sudorule-disable', 'defaults'])
|
||||
|
||||
result3 = self.list_sudo_commands("testuser2", raiseonerr=False)
|
||||
assert result3.returncode != 0
|
||||
assert "sudo: a password is required" in result3.stderr_text
|
||||
|
||||
def test_setting_category_to_all_with_valid_entries_user(self):
|
||||
result = self.reset_rule_categories(safe_delete=False)
|
||||
@@ -198,7 +175,6 @@ class TestSudo(IntegrationTest):
|
||||
self.master.run_command(['ipa', 'sudorule-remove-user',
|
||||
'testrule',
|
||||
'--users', 'testuser1'])
|
||||
self.master.run_command(['ipa', 'sudorule-enable', 'defaults'])
|
||||
|
||||
def test_sudo_rule_restricted_to_one_group_setup(self):
|
||||
# Add the testgroup2 to the rule
|
||||
@@ -209,8 +185,6 @@ class TestSudo(IntegrationTest):
|
||||
def test_sudo_rule_restricted_to_one_group(self):
|
||||
result1 = self.list_sudo_commands("testuser1", raiseonerr=False)
|
||||
assert result1.returncode != 0
|
||||
assert "Sorry, user testuser1 may not run sudo on {}.".format(
|
||||
self.clientname) in result1.stderr_text
|
||||
|
||||
result2 = self.list_sudo_commands("testuser2")
|
||||
assert "(ALL : ALL) NOPASSWD: ALL" in result2.stdout_text
|
||||
@@ -242,8 +216,6 @@ class TestSudo(IntegrationTest):
|
||||
def test_sudo_rule_restricted_to_one_host_negative(self):
|
||||
result1 = self.list_sudo_commands("testuser1", raiseonerr=False)
|
||||
assert result1.returncode != 0
|
||||
assert "Sorry, user testuser1 may not run sudo on {}.".format(
|
||||
self.clientname) in result1.stderr_text
|
||||
|
||||
def test_sudo_rule_restricted_to_one_host_negative_teardown(self):
|
||||
# Remove the master from the rule
|
||||
@@ -297,38 +269,13 @@ class TestSudo(IntegrationTest):
|
||||
'--hostgroups', 'testhostgroup'])
|
||||
|
||||
def test_sudo_rule_restricted_to_one_hostmask_setup(self):
|
||||
# We need to detect the hostmask first
|
||||
full_ip = get_host_ip_with_hostmask(self.client)
|
||||
|
||||
# Make a note for the next test, which needs to be skipped
|
||||
# if hostmask detection failed
|
||||
self.__class__.skip_hostmask_based = False
|
||||
|
||||
if not full_ip:
|
||||
self.__class__.skip_hostmask_based = True
|
||||
raise pytest.skip("Hostmask could not be detected")
|
||||
|
||||
# Add the client's /24 hostmask to the rule
|
||||
ip = self.client.ip
|
||||
self.master.run_command(['ipa', '-n', 'sudorule-add-host',
|
||||
'testrule',
|
||||
'--hostmask', full_ip])
|
||||
|
||||
# SSSD >= 1.13.3-3 uses native IPA schema instead of compat entries to
|
||||
# pull in sudoers. Since native schema does not (yet) support
|
||||
# hostmasks, we need to point ldap_sudo_search_base to the old schema
|
||||
domain = self.client.domain
|
||||
modify_sssd_conf(
|
||||
self.client,
|
||||
domain.name,
|
||||
{
|
||||
'ldap_sudo_search_base': 'ou=sudoers,{}'.format(domain.basedn)
|
||||
},
|
||||
provider_subtype='sudo'
|
||||
)
|
||||
'--hostmask', '%s/24' % ip])
|
||||
|
||||
def test_sudo_rule_restricted_to_one_hostmask(self):
|
||||
if self.__class__.skip_hostmask_based:
|
||||
raise pytest.skip("Hostmask could not be detected")
|
||||
|
||||
result1 = self.list_sudo_commands("testuser1")
|
||||
assert "(ALL : ALL) NOPASSWD: ALL" in result1.stdout_text
|
||||
|
||||
@@ -337,16 +284,11 @@ class TestSudo(IntegrationTest):
|
||||
assert result.returncode != 0
|
||||
|
||||
def test_sudo_rule_restricted_to_one_hostmask_teardown(self):
|
||||
if self.__class__.skip_hostmask_based:
|
||||
raise pytest.skip("Hostmask could not be detected")
|
||||
|
||||
# Detect the hostmask first to delete the hostmask based rule
|
||||
full_ip = get_host_ip_with_hostmask(self.client)
|
||||
|
||||
# Remove the client's hostmask from the rule
|
||||
# Remove the client's /24 hostmask from the rule
|
||||
ip = self.client.ip
|
||||
self.master.run_command(['ipa', '-n', 'sudorule-remove-host',
|
||||
'testrule',
|
||||
'--hostmask', full_ip])
|
||||
'--hostmask', '%s/24' % ip])
|
||||
|
||||
def test_sudo_rule_restricted_to_one_hostmask_negative_setup(self):
|
||||
# Add the master's hostmask to the rule
|
||||
@@ -358,8 +300,6 @@ class TestSudo(IntegrationTest):
|
||||
def test_sudo_rule_restricted_to_one_hostmask_negative(self):
|
||||
result1 = self.list_sudo_commands("testuser1")
|
||||
assert result1.returncode != 0
|
||||
assert "Sorry, user testuser1 may not run sudo on {}.".format(
|
||||
self.clientname) in result1.stderr_text
|
||||
|
||||
def test_sudo_rule_restricted_to_one_hostmask_negative_teardown(self):
|
||||
# Remove the master's hostmask from the rule
|
||||
@@ -368,18 +308,6 @@ class TestSudo(IntegrationTest):
|
||||
'testrule',
|
||||
'--hostmask', '%s/32' % ip])
|
||||
|
||||
# reset ldap_sudo_search_base back to the default value, the old
|
||||
# schema is not needed for the upcoming tests
|
||||
domain = self.client.domain
|
||||
modify_sssd_conf(
|
||||
self.client,
|
||||
domain.name,
|
||||
{
|
||||
'ldap_sudo_search_base': None
|
||||
},
|
||||
provider_subtype='sudo'
|
||||
)
|
||||
|
||||
def test_sudo_rule_restricted_to_one_command_setup(self):
|
||||
# Reset testrule configuration
|
||||
self.reset_rule_categories()
|
||||
@@ -530,7 +458,7 @@ class TestSudo(IntegrationTest):
|
||||
|
||||
def test_sudo_rule_restricted_to_running_as_single_group(self):
|
||||
result1 = self.list_sudo_commands("testuser1", verbose=True)
|
||||
assert "RunAsUsers: testuser1" in result1.stdout_text
|
||||
assert "RunAsUsers: root" in result1.stdout_text
|
||||
assert "RunAsGroups: testgroup2" in result1.stdout_text
|
||||
|
||||
def test_setting_category_to_all_with_valid_entries_runasgroup(self):
|
||||
@@ -551,7 +479,7 @@ class TestSudo(IntegrationTest):
|
||||
|
||||
def test_sudo_rule_restricted_to_running_as_single_local_group(self):
|
||||
result1 = self.list_sudo_commands("testuser1", verbose=True)
|
||||
assert "RunAsUsers: testuser1" in result1.stdout_text
|
||||
assert "RunAsUsers: root" in result1.stdout_text
|
||||
assert "RunAsGroups: localgroup" in result1.stdout_text
|
||||
|
||||
def test_setting_category_to_all_with_valid_entries_runasgroup_local(self):
|
||||
|
||||
Reference in New Issue
Block a user