test_ldap.py revision 1097a61a8d4a892e126d14631c1b80fc1a5ce976
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# LDAP integration test
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# Copyright (c) 2015 Red Hat, Inc.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# Author: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# This is free software; you can redistribute it and/or modify it
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# under the terms of the GNU General Public License as published by
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# the Free Software Foundation; version 2 only
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# This program is distributed in the hope that it will be useful, but
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# WITHOUT ANY WARRANTY; without even the implied warranty of
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
04c3ac276103b56185119bcff9a66de7a8bb0e68Timo Sirainen# General Public License for more details.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# You should have received a copy of the GNU General Public License
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen# along with this program. If not, see <http://www.gnu.org/licenses/>.
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen """LDAP server instance fixture"""
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen """LDAP server connection fixture"""
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainendef create_ldap_entries(ldap_conn, ent_list=None):
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen """Add LDAP entries from ent_list"""
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if ent_list is not None:
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainendef cleanup_ldap_entries(ldap_conn, ent_list=None):
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen """Remove LDAP entries added by create_ldap_entries"""
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for ou in ("Users", "Groups", "Netgroups", "Services", "Policies"):
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen for entry in ldap_conn.search_s("ou=" + ou + "," +
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainendef create_ldap_cleanup(request, ldap_conn, ent_list=None):
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen """Add teardown for removing all user/group LDAP entries"""
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen request.addfinalizer(lambda: cleanup_ldap_entries(ldap_conn, ent_list))
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainendef create_ldap_fixture(request, ldap_conn, ent_list=None):
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen """Add LDAP entries and add teardown for removing them"""
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen create_ldap_cleanup(request, ldap_conn, ent_list)
"""Create sssd.conf with specified contents"""
def cleanup_conf_file():
"""Remove sssd.conf, if it exists"""
"""Add teardown for removing sssd.conf"""
Create sssd.conf with specified contents and add teardown for removing it
def create_sssd_process():
def cleanup_sssd_process():
while True:
conf = \
conf = \
conf = \
conf = \
conf = \
allowed_shells = /bin/not_installed
conf = \
allowed_shells = /bin/default, /bin/not_installed
conf = \
conf = \
user,