05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# Netgroup integration test
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# Copyright (c) 2016 Red Hat, Inc.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# Author: Petr Cech <pcech@redhat.com>
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# This is free software; you can redistribute it and/or modify it
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# under the terms of the GNU General Public License as published by
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# the Free Software Foundation; version 2 only
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# This program is distributed in the hope that it will be useful, but
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# WITHOUT ANY WARRANTY; without even the implied warranty of
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# General Public License for more details.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# You should have received a copy of the GNU General Public License
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# along with this program. If not, see <http://www.gnu.org/licenses/>.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """LDAP server instance fixture"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """LDAP server connection fixture"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Add LDAP entries from ent_list"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if ent_list is not None:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef cleanup_ldap_entries(ldap_conn, ent_list=None):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Remove LDAP entries added by create_ldap_entries"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech for ou in ("Users", "Groups", "Netgroups", "Services", "Policies"):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech for entry in ldap_conn.search_s("ou=" + ou + "," +
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_ldap_cleanup(request, ldap_conn, ent_list=None):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Add teardown for removing all user/group LDAP entries"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech request.addfinalizer(lambda: cleanup_ldap_entries(ldap_conn, ent_list))
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_ldap_fixture(request, ldap_conn, ent_list=None):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Add LDAP entries and add teardown for removing them"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Format a basic SSSD configuration"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech schema_conf += "ldap_group_object_class = groupOfNames\n"
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech domains = LDAP
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech services = nss
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek disable_netlink = true
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech {schema_conf}
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech id_provider = ldap
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech auth_provider = ldap
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_uri = {ldap_conn.ds_inst.ldap_url}
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_search_base = {ldap_conn.ds_inst.base_dn}
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_netgroup_search_base = ou=Netgroups,{ldap_conn.ds_inst.base_dn}
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Create sssd.conf with specified contents"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech os.chmod(config.CONF_PATH, stat.S_IRUSR | stat.S_IWUSR)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Remove sssd.conf, if it exists"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Add teardown for removing sssd.conf"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Create sssd.conf with specified contents and add teardown for removing it
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Start the SSSD process"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Stop the SSSD process and remove its state"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Add teardown for stopping SSSD and removing its state"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Start SSSD and add teardown for stopping it and removing its state"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Adding empty netgroup.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("empty_netgroup")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("tripled_netgroup", ["(host,user,domain)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("adv_tripled_netgroup", ["(host1,user1,domain1)",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech "(host2,user2,domain2)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef test_add_tripled_netgroup(add_tripled_netgroup):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Adding netgroup with triplet.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgrps = sssd_netgroup.get_sssd_netgroups("tripled_netgroup")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgrps = sssd_netgroup.get_sssd_netgroups("adv_tripled_netgroup")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgrps) == sorted([("host1", "user1", "domain1"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup2", members=["mixed_netgroup1"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup3", ["(host1,user1,domain1)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host2,user2,domain2)", "(host3,user3,domain3)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host4,user4,domain4)"],
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["mixed_netgroup1"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host5,user5,domain5)"],
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["mixed_netgroup2"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup7", members=["mixed_netgroup3"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host6,user6,domain6)"],
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Adding many netgroups of different type.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup3")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [("host1", "user1", "domain1")]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup4")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([("host2", "user2", "domain2"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup5")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [("host4", "user4", "domain4")]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup6")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [("host5", "user5", "domain5")]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup7")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [("host1", "user1", "domain1")]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup8")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([("host1", "user1", "domain1"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup9")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([("host1", "user1", "domain1"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("rm_empty_netgroup1", ["(host1,user1,domain1)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host2,user2,domain2)"],
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["rm_empty_netgroup1"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef test_remove_step_by_step(remove_step_by_step, ldap_conn):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Removing netgroups step by step.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host1', 'user1', 'domain1')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([('host1', 'user1', 'domain1'),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech # removing of rm_empty_netgroup1
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.NOTFOUND
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech # removing of rm_empty_netgroup2
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.NOTFOUND
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.NOTFOUND
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("t2841_netgroup1", ["(host1,user1,domain1)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("t2841_netgroup2", ["(host2,user2,domain2)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef test_removing_nested_netgroups(removing_nested_netgroups, ldap_conn):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Regression test for ticket 2841.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech netgrp_dn = 'cn=t2841_netgroup3,ou=Netgroups,' + ldap_conn.ds_inst.base_dn
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host1', 'user1', 'domain1')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup3")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([('host1', 'user1', 'domain1'),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech # removing of t2841_netgroup1 from t2841_netgroup3
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech old = {'memberNisNetgroup': ["t2841_netgroup1", "t2841_netgroup2"]}
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host1', 'user1', 'domain1')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup3")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech # removing of t2841_netgroup2 from t2841_netgroup3
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host1', 'user1', 'domain1')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup3")
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozekdef test_offline_netgroups(add_tripled_netgroup):
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek res, _, netgrps = sssd_netgroup.get_sssd_netgroups("tripled_netgroup")
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek assert res == sssd_netgroup.NssReturnCode.SUCCESS
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek res, _, netgrps = sssd_netgroup.get_sssd_netgroups("tripled_netgroup")