05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech#
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# Netgroup integration test
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech#
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# Copyright (c) 2016 Red Hat, Inc.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech# Author: Petr Cech <pcech@redhat.com>
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech#
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#
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#
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#
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport os
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport stat
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport signal
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport subprocess
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport time
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport ldap
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport ldap.modlist
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport pytest
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport config
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport ds_openldap
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport ldap_ent
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechfrom util import unindent
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechimport sssd_netgroup
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr CechLDAP_BASE_DN = "dc=example,dc=com"
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech@pytest.fixture(scope="module")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef ds_inst(request):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """LDAP server instance fixture"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ds_inst = ds_openldap.DSOpenLDAP(
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech config.PREFIX, 10389, LDAP_BASE_DN,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech "cn=admin", "Secret123"
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech )
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech try:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ds_inst.setup()
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech except:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ds_inst.teardown()
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech raise
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech request.addfinalizer(ds_inst.teardown)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech return ds_inst
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech@pytest.fixture(scope="module")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef ldap_conn(request, ds_inst):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """LDAP server connection fixture"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn = ds_inst.bind()
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn.ds_inst = ds_inst
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech request.addfinalizer(ldap_conn.unbind_s)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech return ldap_conn
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_ldap_entries(ldap_conn, ent_list=None):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Add LDAP entries from ent_list"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if ent_list is not None:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech for entry in ent_list:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn.add_s(entry[0], entry[1])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef cleanup_ldap_entries(ldap_conn, ent_list=None):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Remove LDAP entries added by create_ldap_entries"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if ent_list is None:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech for ou in ("Users", "Groups", "Netgroups", "Services", "Policies"):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech for entry in ldap_conn.search_s("ou=" + ou + "," +
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn.ds_inst.base_dn,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap.SCOPE_ONELEVEL,
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech attrlist=[]):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn.delete_s(entry[0])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech else:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech for entry in ent_list:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn.delete_s(entry[0])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
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 Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_ldap_fixture(request, ldap_conn, ent_list=None):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Add LDAP entries and add teardown for removing them"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_ldap_entries(ldap_conn, ent_list)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_ldap_cleanup(request, ldap_conn, ent_list)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr CechSCHEMA_RFC2307_BIS = "rfc2307bis"
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef format_basic_conf(ldap_conn, schema):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Format a basic SSSD configuration"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech schema_conf = "ldap_schema = " + schema + "\n"
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech schema_conf += "ldap_group_object_class = groupOfNames\n"
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech return unindent("""\
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech [sssd]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech domains = LDAP
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech services = nss
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek disable_netlink = true
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech [domain/LDAP]
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 """).format(**locals())
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_conf_file(contents):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Create sssd.conf with specified contents"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = open(config.CONF_PATH, "w")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf.write(contents)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf.close()
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech os.chmod(config.CONF_PATH, stat.S_IRUSR | stat.S_IWUSR)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef cleanup_conf_file():
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Remove sssd.conf, if it exists"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if os.path.lexists(config.CONF_PATH):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech os.unlink(config.CONF_PATH)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_conf_cleanup(request):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Add teardown for removing sssd.conf"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech request.addfinalizer(cleanup_conf_file)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_conf_fixture(request, contents):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Create sssd.conf with specified contents and add teardown for removing it
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_conf_file(contents)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_conf_cleanup(request)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_sssd_process():
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Start the SSSD process"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if subprocess.call(["sssd", "-D", "-f"]) != 0:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech raise Exception("sssd start failed")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozekdef get_sssd_pid():
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek pid_file = open(config.PIDFILE_PATH, "r")
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek pid = int(pid_file.read())
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek return pid
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef cleanup_sssd_process():
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Stop the SSSD process and remove its state"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech try:
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek pid = get_sssd_pid()
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech os.kill(pid, signal.SIGTERM)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech while True:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech try:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech os.kill(pid, signal.SIGCONT)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech except:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech break
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech time.sleep(1)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech except:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech pass
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech for path in os.listdir(config.DB_PATH):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech os.unlink(config.DB_PATH + "/" + path)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech for path in os.listdir(config.MCACHE_PATH):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech os.unlink(config.MCACHE_PATH + "/" + path)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_sssd_cleanup(request):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Add teardown for stopping SSSD and removing its state"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech request.addfinalizer(cleanup_sssd_process)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozekdef simulate_offline():
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek pid = get_sssd_pid()
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek os.kill(pid, signal.SIGUSR1)
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef create_sssd_fixture(request):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """Start SSSD and add teardown for stopping it and removing its state"""
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_sssd_process()
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_sssd_cleanup(request)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech@pytest.fixture
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef add_empty_netgroup(request, ldap_conn):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("empty_netgroup")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_ldap_fixture(request, ldap_conn, ent_list)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_conf_fixture(request, conf)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_sssd_fixture(request)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech return None
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef test_add_empty_netgroup(add_empty_netgroup):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Adding empty netgroup.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("empty_netgroup")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == []
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech@pytest.fixture
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef add_tripled_netgroup(request, ldap_conn):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("tripled_netgroup", ["(host,user,domain)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("adv_tripled_netgroup", ["(host1,user1,domain1)",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech "(host2,user2,domain2)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_ldap_fixture(request, ldap_conn, ent_list)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_conf_fixture(request, conf)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_sssd_fixture(request)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech return None
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef test_add_tripled_netgroup(add_tripled_netgroup):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Adding netgroup with triplet.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgrps = sssd_netgroup.get_sssd_netgroups("tripled_netgroup")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgrps == [("host", "user", "domain")]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgrps = sssd_netgroup.get_sssd_netgroups("adv_tripled_netgroup")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgrps) == sorted([("host1", "user1", "domain1"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ("host2", "user2", "domain2")])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech@pytest.fixture
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef add_mixed_netgroup(request, ldap_conn):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup2", members=["mixed_netgroup1"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup3", ["(host1,user1,domain1)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup4",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host2,user2,domain2)", "(host3,user3,domain3)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup5",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host4,user4,domain4)"],
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["mixed_netgroup1"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup6",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host5,user5,domain5)"],
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["mixed_netgroup2"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup7", members=["mixed_netgroup3"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup8",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech members=["mixed_netgroup3", "mixed_netgroup4"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("mixed_netgroup9",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host6,user6,domain6)"],
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["mixed_netgroup3", "mixed_netgroup4"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_ldap_fixture(request, ldap_conn, ent_list)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_conf_fixture(request, conf)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_sssd_fixture(request)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech return None
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef test_add_mixed_netgroup(add_mixed_netgroup):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Adding many netgroups of different type.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == []
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == []
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup3")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [("host1", "user1", "domain1")]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup4")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([("host2", "user2", "domain2"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ("host3", "user3", "domain3")])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup5")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [("host4", "user4", "domain4")]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup6")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [("host5", "user5", "domain5")]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup7")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [("host1", "user1", "domain1")]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup8")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([("host1", "user1", "domain1"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ("host2", "user2", "domain2"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ("host3", "user3", "domain3")])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("mixed_netgroup9")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([("host1", "user1", "domain1"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ("host2", "user2", "domain2"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ("host3", "user3", "domain3"),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ("host6", "user6", "domain6")])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech@pytest.fixture
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef remove_step_by_step(request, ldap_conn):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("rm_empty_netgroup1", ["(host1,user1,domain1)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("rm_empty_netgroup2",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["(host2,user2,domain2)"],
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ["rm_empty_netgroup1"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_ldap_fixture(request, ldap_conn, ent_list)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_conf_fixture(request, conf)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_sssd_fixture(request)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech return ent_list
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef test_remove_step_by_step(remove_step_by_step, ldap_conn):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Removing netgroups step by step.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = remove_step_by_step
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host1', 'user1', 'domain1')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([('host1', 'user1', 'domain1'),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ('host2', 'user2', 'domain2')])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech # removing of rm_empty_netgroup1
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn.delete_s(ent_list[0][0])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.remove(ent_list[0])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if subprocess.call(["sss_cache", "-N"]) != 0:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech raise Exception("sssd_cache failed")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.NOTFOUND
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == []
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech # removing of rm_empty_netgroup2
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn.delete_s(ent_list[0][0])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.remove(ent_list[0])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if subprocess.call(["sss_cache", "-N"]) != 0:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech raise Exception("sssd_cache failed")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.NOTFOUND
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == []
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.NOTFOUND
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == []
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech@pytest.fixture
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef removing_nested_netgroups(request, ldap_conn):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("t2841_netgroup1", ["(host1,user1,domain1)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("t2841_netgroup2", ["(host2,user2,domain2)"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ent_list.add_netgroup("t2841_netgroup3",
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech members=["t2841_netgroup1", "t2841_netgroup2"])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_ldap_fixture(request, ldap_conn, ent_list)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_conf_fixture(request, conf)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech create_sssd_fixture(request)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech return None
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cechdef test_removing_nested_netgroups(removing_nested_netgroups, ldap_conn):
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech Regression test for ticket 2841.
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech https://fedorahosted.org/sssd/ticket/2841
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech """
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech netgrp_dn = 'cn=t2841_netgroup3,ou=Netgroups,' + ldap_conn.ds_inst.base_dn
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host1', 'user1', 'domain1')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup3")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert sorted(netgroups) == sorted([('host1', 'user1', 'domain1'),
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ('host2', 'user2', 'domain2')])
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech # removing of t2841_netgroup1 from t2841_netgroup3
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech old = {'memberNisNetgroup': ["t2841_netgroup1", "t2841_netgroup2"]}
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech new = {'memberNisNetgroup': ["t2841_netgroup2"]}
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldif = ldap.modlist.modifyModlist(old, new)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn.modify_s(netgrp_dn, ldif)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if subprocess.call(["sss_cache", "-N"]) != 0:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech raise Exception("sssd_cache failed")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host1', 'user1', 'domain1')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup3")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech # removing of t2841_netgroup2 from t2841_netgroup3
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech old = {'memberNisNetgroup': ["t2841_netgroup2"]}
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech new = {'memberNisNetgroup': []}
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldif = ldap.modlist.modifyModlist(old, new)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech ldap_conn.modify_s(netgrp_dn, ldif)
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech if subprocess.call(["sss_cache", "-N"]) != 0:
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech raise Exception("sssd_cache failed")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup1")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host1', 'user1', 'domain1')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup2")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == [('host2', 'user2', 'domain2')]
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup3")
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert res == sssd_netgroup.NssReturnCode.SUCCESS
05457ed0e399aaacc919b7aacee5d8210e1c1072Petr Cech assert netgroups == []
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek
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 assert netgrps == [("host", "user", "domain")]
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek subprocess.check_call(["sss_cache", "-N"])
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek simulate_offline()
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek res, _, netgrps = sssd_netgroup.get_sssd_netgroups("tripled_netgroup")
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek assert res == sssd_netgroup.NssReturnCode.SUCCESS
c0ee12832555b42c17e48cdf731731454a97972eJakub Hrozek assert netgrps == [("host", "user", "domain")]