test_netgroup.py revision c0ee12832555b42c17e48cdf731731454a97972e
#
# Netgroup integration test
#
# Copyright (c) 2016 Red Hat, Inc.
# Author: Petr Cech <pcech@redhat.com>
#
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 only
#
# 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/>.
#
import os
import stat
import signal
import subprocess
import time
import ldap
import pytest
import config
import ds_openldap
import ldap_ent
import sssd_netgroup
LDAP_BASE_DN = "dc=example,dc=com"
"""LDAP server instance fixture"""
"cn=admin", "Secret123"
)
try:
except:
raise
return ds_inst
"""LDAP server connection fixture"""
return ldap_conn
"""Add LDAP entries from ent_list"""
if ent_list is not None:
"""Remove LDAP entries added by create_ldap_entries"""
if ent_list is None:
attrlist=[]):
else:
"""Add LDAP entries and add teardown for removing them"""
SCHEMA_RFC2307_BIS = "rfc2307bis"
"""Format a basic SSSD configuration"""
schema_conf += "ldap_group_object_class = groupOfNames\n"
return unindent("""\
[sssd]
domains = LDAP
services = nss
disable_netlink = true
{schema_conf}
id_provider = ldap
auth_provider = ldap
ldap_uri = {ldap_conn.ds_inst.ldap_url}
ldap_search_base = {ldap_conn.ds_inst.base_dn}
ldap_netgroup_search_base = ou=Netgroups,{ldap_conn.ds_inst.base_dn}
def create_conf_file(contents):
"""Create sssd.conf with specified contents"""
def cleanup_conf_file():
"""Remove sssd.conf, if it exists"""
def create_conf_cleanup(request):
"""Add teardown for removing sssd.conf"""
"""
Create sssd.conf with specified contents and add teardown for removing it
"""
def create_sssd_process():
"""Start the SSSD process"""
raise Exception("sssd start failed")
def get_sssd_pid():
return pid
def cleanup_sssd_process():
"""Stop the SSSD process and remove its state"""
try:
pid = get_sssd_pid()
while True:
try:
except:
break
except:
pass
def create_sssd_cleanup(request):
"""Add teardown for stopping SSSD and removing its state"""
def simulate_offline():
pid = get_sssd_pid()
def create_sssd_fixture(request):
"""Start SSSD and add teardown for stopping it and removing its state"""
return None
"""
Adding empty netgroup.
"""
assert netgroups == []
"(host2,user2,domain2)"])
return None
"""
Adding netgroup with triplet.
"""
("host2", "user2", "domain2")])
["(host2,user2,domain2)", "(host3,user3,domain3)"])
["(host4,user4,domain4)"],
["mixed_netgroup1"])
["(host5,user5,domain5)"],
["mixed_netgroup2"])
["(host6,user6,domain6)"],
["mixed_netgroup3", "mixed_netgroup4"])
return None
"""
Adding many netgroups of different type.
"""
assert netgroups == []
assert netgroups == []
("host3", "user3", "domain3")])
("host2", "user2", "domain2"),
("host3", "user3", "domain3")])
("host2", "user2", "domain2"),
("host3", "user3", "domain3"),
("host6", "user6", "domain6")])
["(host2,user2,domain2)"],
["rm_empty_netgroup1"])
return ent_list
"""
Removing netgroups step by step.
"""
('host2', 'user2', 'domain2')])
# removing of rm_empty_netgroup1
raise Exception("sssd_cache failed")
assert netgroups == []
# removing of rm_empty_netgroup2
raise Exception("sssd_cache failed")
assert netgroups == []
assert netgroups == []
return None
"""
Regression test for ticket 2841.
"""
('host2', 'user2', 'domain2')])
# removing of t2841_netgroup1 from t2841_netgroup3
raise Exception("sssd_cache failed")
# removing of t2841_netgroup2 from t2841_netgroup3
new = {'memberNisNetgroup': []}
raise Exception("sssd_cache failed")
assert netgroups == []