Imported Upstream version 4.8.10

This commit is contained in:
Mario Fetka
2021-10-03 11:06:28 +02:00
parent 10dfc9587b
commit 03a8170b15
2361 changed files with 1883897 additions and 338759 deletions

View File

@@ -18,20 +18,22 @@
# 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/hbactest.py` module.
Test the `ipaserver/plugins/hbactest.py` module.
"""
from xmlrpc_test import XMLRPC_test, assert_attr_equal
from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test
from ipalib import api
from ipalib import errors
from types import NoneType
from nose.tools import raises
import pytest
# Test strategy:
# 1. Create few allow rules: with user categories, with explicit users, with user groups, with groups, with services
# 2. Create users for test
# 3. Run detailed and non-detailed tests for explicitly specified rules, check expected result
#
@pytest.mark.tier1
class test_hbactest(XMLRPC_test):
"""
Test the `hbactest` plugin.
@@ -88,20 +90,20 @@ class test_hbactest(XMLRPC_test):
self.rule_names[i], accessruletype=self.rule_type, description=self.rule_descs[i],
)
ret = api.Command['hbacrule_add_user'](
api.Command['hbacrule_add_user'](
self.rule_names[i], user=self.test_user, group=self.test_group
)
ret = api.Command['hbacrule_add_host'](
api.Command['hbacrule_add_host'](
self.rule_names[i], host=self.test_host, hostgroup=self.test_hostgroup
)
ret = api.Command['hbacrule_add_service'](
api.Command['hbacrule_add_service'](
self.rule_names[i], hbacsvc=self.test_service
)
if i & 1:
ret = api.Command['hbacrule_disable'](self.rule_names[i])
api.Command['hbacrule_disable'](self.rule_names[i])
def test_a_hbactest_check_rules_detail(self):
"""
@@ -113,8 +115,8 @@ class test_hbactest(XMLRPC_test):
service=self.test_service,
rules=self.rule_names
)
assert ret['value'] == True
assert type(ret['error']) == NoneType
assert ret['value']
assert ret['error'] is None
for i in [0,1,2,3]:
assert self.rule_names[i] in ret['matched']
@@ -129,10 +131,10 @@ class test_hbactest(XMLRPC_test):
rules=self.rule_names,
nodetail=True
)
assert ret['value'] == True
assert ret['error'] == None
assert ret['matched'] == None
assert ret['notmatched'] == None
assert ret['value']
assert ret['error'] is None
assert ret['matched'] is None
assert ret['notmatched'] is None
def test_c_hbactest_check_rules_enabled_detail(self):
"""
@@ -178,25 +180,25 @@ class test_hbactest(XMLRPC_test):
nodetail=True
)
assert ret['value'] == False
assert ret['matched'] == None
assert ret['notmatched'] == None
assert not ret['value']
assert ret['matched'] is None
assert ret['notmatched'] is None
for rule in self.rule_names:
assert u'%s_1x1' % (rule) in ret['error']
@raises(errors.ValidationError)
def test_f_hbactest_check_sourcehost_option_is_deprecated(self):
"""
Test running 'ipa hbactest' with --srchost option raises ValidationError
"""
api.Command['hbactest'](
user=self.test_user,
targethost=self.test_host,
sourcehost=self.test_sourcehost,
service=self.test_service,
rules=[u'%s_1x1' % rule for rule in self.rule_names],
nodetail=True
)
with pytest.raises(errors.ValidationError):
api.Command['hbactest'](
user=self.test_user,
targethost=self.test_host,
sourcehost=self.test_sourcehost,
service=self.test_service,
rules=[u'%s_1x1' % rule for rule in self.rule_names],
nodetail=True
)
def test_g_hbactest_clear_testing_data(self):
"""
@@ -214,4 +216,3 @@ class test_hbactest(XMLRPC_test):
api.Command['host_del'](self.test_sourcehost)
api.Command['hostgroup_del'](self.test_sourcehostgroup)
api.Command['hbacsvc_del'](self.test_service)