0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik#
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# Infopipe integration test
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik#
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# Copyright (c) 2017 Red Hat, Inc.
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# Author: Lukas Slebodnik <lslebodn@redhat.com>
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik#
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# This is free software; you can redistribute it and/or modify it
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# under the terms of the GNU General Public License as published by
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# the Free Software Foundation; version 2 only
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik#
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# This program is distributed in the hope that it will be useful, but
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# WITHOUT ANY WARRANTY; without even the implied warranty of
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# General Public License for more details.
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik#
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# You should have received a copy of the GNU General Public License
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik# along with this program. If not, see <http://www.gnu.org/licenses/>.
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik#
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikfrom __future__ import print_function
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport os
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport stat
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport pwd
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport signal
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport subprocess
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport errno
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport time
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport ldap
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport ldap.modlist
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport pytest
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport dbus
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport config
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport ds_openldap
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikimport ldap_ent
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidênciofrom util import unindent, get_call_output
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas SlebodnikLDAP_BASE_DN = "dc=example,dc=com"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas SlebodnikINTERACTIVE_TIMEOUT = 4
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikclass DbusDaemon(object):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik def __init__(self):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik self.pid = 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik def start(self):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Start the SSSD process"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert self.pid == 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik dbus_config_path = config.SYSCONFDIR + "/dbus-1/cwrap-dbus-system.conf"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik dbus_commands = [
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ["dbus-daemon", "--config-file", dbus_config_path,
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik "--nosyslog", "--fork"],
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ["dbus-daemon", "--config-file", dbus_config_path, "--fork"],
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ]
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik dbus_started = False
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for dbus_command in dbus_commands:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik try:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if subprocess.call(dbus_command) == 0:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik dbus_started = True
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik break
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik else:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik print("start failed for %s" % " ".join(dbus_command))
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik except OSError as ex:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if ex.errno == errno.ENOENT:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik print("%s does not exist" % (dbus_command[0]))
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik pass
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if not dbus_started:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik raise Exception("dbus-daemon start failed")
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik dbus_pid_path = config.RUNSTATEDIR + "/dbus/messagebus.pid"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # wait 10 seconds for pidfile
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik wait_time = 10
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for _ in range(wait_time * 10):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if os.path.isfile(dbus_pid_path):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik break
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik time.sleep(.1)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert os.path.isfile(dbus_pid_path)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with open(dbus_pid_path, "r") as pid_file:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik self.pid = int(pid_file.read())
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik def stop(self):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Stop the SSSD process and remove its state"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # stop process only if running
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if self.pid != 0:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik try:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik os.kill(self.pid, signal.SIGTERM)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik while True:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik try:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik os.kill(self.pid, signal.SIGCONT)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik except:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik break
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik time.sleep(.1)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik except:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik pass
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # clean pid so we can start service one more time
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik self.pid = 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # dbus-daemon 1.2.24 does not clean pid file after itself
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik try:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik os.unlink(config.RUNSTATEDIR + "/dbus/messagebus.pid")
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik except OSError as ex:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if ex.errno != errno.ENOENT:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik raise
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik@pytest.fixture(scope="module")
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef dbus_system_bus(request):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik dbus_daemon = DbusDaemon()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik dbus_daemon.start()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik def cleanup_dbus_process():
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik dbus_daemon.stop()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik request.addfinalizer(cleanup_dbus_process)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik return dbus.SystemBus()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik@pytest.fixture(scope="module")
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef ds_inst(request):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """LDAP server instance fixture"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ds_inst = ds_openldap.DSOpenLDAP(
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik config.PREFIX, 10389, LDAP_BASE_DN,
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik "cn=admin", "Secret123"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik )
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik try:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ds_inst.setup()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik except:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ds_inst.teardown()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik raise
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik request.addfinalizer(ds_inst.teardown)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik return ds_inst
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik@pytest.fixture(scope="module")
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef ldap_conn(request, ds_inst):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """LDAP server connection fixture"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap_conn = ds_inst.bind()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap_conn.ds_inst = ds_inst
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik request.addfinalizer(ldap_conn.unbind_s)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik return ldap_conn
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef create_ldap_entries(ldap_conn, ent_list=None):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Add LDAP entries from ent_list"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if ent_list is not None:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for entry in ent_list:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap_conn.add_s(entry[0], entry[1])
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef cleanup_ldap_entries(ldap_conn, ent_list=None):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Remove LDAP entries added by create_ldap_entries"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if ent_list is None:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for ou in ("Users", "Groups", "Netgroups", "Services", "Policies"):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for entry in ldap_conn.search_s("ou=" + ou + "," +
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap_conn.ds_inst.base_dn,
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap.SCOPE_ONELEVEL,
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik attrlist=[]):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap_conn.delete_s(entry[0])
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik else:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for entry in ent_list:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap_conn.delete_s(entry[0])
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef create_ldap_cleanup(request, ldap_conn, ent_list=None):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Add teardown for removing all user/group LDAP entries"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik request.addfinalizer(lambda: cleanup_ldap_entries(ldap_conn, ent_list))
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef create_ldap_fixture(request, ldap_conn, ent_list=None):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Add LDAP entries and add teardown for removing them"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_ldap_entries(ldap_conn, ent_list)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_ldap_cleanup(request, ldap_conn, ent_list)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas SlebodnikSCHEMA_RFC2307 = "rfc2307"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas SlebodnikSCHEMA_RFC2307_BIS = "rfc2307bis"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef format_basic_conf(ldap_conn, schema):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Format a basic SSSD configuration"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik schema_conf = "ldap_schema = " + schema + "\n"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if schema == SCHEMA_RFC2307_BIS:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik schema_conf += "ldap_group_object_class = groupOfNames\n"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik valgrind_cmd = "valgrind --log-file=%s/valgrind_ifp.log" % config.LOG_PATH
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ifp_command = "%s %s/sssd/sssd_ifp " % (valgrind_cmd, config.LIBEXEC_PATH)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik return unindent("""\
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik [sssd]
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik debug_level = 0xffff
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio domains = LDAP, app
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik services = nss, ifp
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik enable_files_domain = false
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik [nss]
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik memcache_timeout = 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik [ifp]
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # it need to be executed with valgrind because there is a problem
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # problem with "ifp" + client regristration in monitor
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # There is not such problem in 1st test. Just in following tests.
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik command = {ifp_command} --uid 0 --gid 0 --debug-to-files
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik [domain/LDAP]
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik {schema_conf}
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik id_provider = ldap
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap_uri = {ldap_conn.ds_inst.ldap_url}
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap_search_base = {ldap_conn.ds_inst.base_dn}
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio [application/app]
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio inherit_from = LDAP
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """).format(**locals())
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef format_interactive_conf(ldap_conn, schema):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Format an SSSD configuration with all caches refreshing in 4 seconds"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik return \
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik format_basic_conf(ldap_conn, schema) + \
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik unindent("""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik [nss]
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik memcache_timeout = 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik entry_negative_timeout = 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik [domain/LDAP]
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ldap_purge_cache_timeout = 1
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik entry_cache_timeout = {0}
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """).format(INTERACTIVE_TIMEOUT)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef create_conf_file(contents):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Create sssd.conf with specified contents"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with open(config.CONF_PATH, "w") as conf:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik conf.write(contents)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik os.chmod(config.CONF_PATH, stat.S_IRUSR | stat.S_IWUSR)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef cleanup_conf_file():
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Remove sssd.conf, if it exists"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if os.path.lexists(config.CONF_PATH):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik os.unlink(config.CONF_PATH)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef create_conf_cleanup(request):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Add teardown for removing sssd.conf"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik request.addfinalizer(cleanup_conf_file)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef create_conf_fixture(request, contents):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik Create sssd.conf with specified contents and add teardown for removing it
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_conf_file(contents)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_conf_cleanup(request)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef create_sssd_process():
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Start the SSSD process"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik if subprocess.call(["sssd", "-D", "-f"]) != 0:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik raise Exception("sssd start failed")
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef cleanup_sssd_process():
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Stop the SSSD process and remove its state"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik try:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with open(config.PIDFILE_PATH, "r") as pid_file:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik pid = int(pid_file.read())
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik os.kill(pid, signal.SIGTERM)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik while True:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik try:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik os.kill(pid, signal.SIGCONT)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik except:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik break
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik time.sleep(1)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik except:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik pass
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for path in os.listdir(config.DB_PATH):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik os.unlink(config.DB_PATH + "/" + path)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for path in os.listdir(config.MCACHE_PATH):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik os.unlink(config.MCACHE_PATH + "/" + path)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef create_sssd_cleanup(request):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Add teardown for stopping SSSD and removing its state"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik request.addfinalizer(cleanup_sssd_process)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef create_sssd_fixture(request):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik """Start SSSD and add teardown for stopping it and removing its state"""
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_sssd_process()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_sssd_cleanup(request)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik@pytest.fixture
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef sanity_rfc2307(request, ldap_conn):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_user("user1", 1001, 2001)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_user("user2", 1002, 2002)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_user("user3", 1003, 2003)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_group("group1", 2001)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_group("group2", 2002)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_group("group3", 2003)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_group("empty_group", 2010)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_group("single_user_group", 2011, ["user1"])
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_group("two_user_group", 2012, ["user1", "user2"])
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_ldap_fixture(request, ldap_conn, ent_list)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_conf_fixture(request, conf)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_sssd_fixture(request)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik return None
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik@pytest.fixture
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef simple_rfc2307(request, ldap_conn):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_user('usr\\\\001', 181818, 181818)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ent_list.add_group("group1", 181818)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_ldap_fixture(request, ldap_conn, ent_list)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_conf_fixture(request, conf)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik create_sssd_fixture(request)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik return None
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef test_ping_raw(dbus_system_bus, ldap_conn, simple_rfc2307):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test with disabled introspection
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_obj = dbus_system_bus.get_object('org.freedesktop.sssd.infopipe',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik '/org/freedesktop/sssd/infopipe',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik introspect=False)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface = dbus.Interface(sssd_obj, 'org.freedesktop.sssd.infopipe')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test missing parameter
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with pytest.raises(dbus.exceptions.DBusException) as exc_info:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface.Ping()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert exc_info.errisinstance(dbus.exceptions.DBusException)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ex = exc_info.value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_name() == 'org.freedesktop.DBus.Error.InvalidArgs'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_message() == 'Argument 0 is specified to be of type ' \
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik '"string", but is actually of type ' \
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik '"invalid"\n'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test wrong parameter type
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with pytest.raises(dbus.exceptions.DBusException) as exc_info:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface.Ping(1)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert exc_info.errisinstance(dbus.exceptions.DBusException)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ex = exc_info.value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_name() == 'org.freedesktop.DBus.Error.InvalidArgs'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_message() == 'Argument 0 is specified to be of type ' \
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik '"string", but is actually of type ' \
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik '"int32"\n'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test wrong parameter value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with pytest.raises(dbus.exceptions.DBusException) as exc_info:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface.Ping('test')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert exc_info.errisinstance(dbus.exceptions.DBusException)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ex = exc_info.value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_name() == 'org.freedesktop.DBus.Error.InvalidArgs'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_message() == 'Ping() only accepts "ping" as a param\n'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # positive test
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ret = sssd_interface.Ping('ping')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ret == "PONG"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test case insensitive input
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ret = sssd_interface.Ping('PinG')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ret == "PONG"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ret = sssd_interface.Ping('PING')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ret == "PONG"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef test_ping_introspection(dbus_system_bus, ldap_conn, simple_rfc2307):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_obj = dbus_system_bus.get_object('org.freedesktop.sssd.infopipe',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik '/org/freedesktop/sssd/infopipe')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface = dbus.Interface(sssd_obj, 'org.freedesktop.sssd.infopipe')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test missing parameter
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with pytest.raises(TypeError) as exc_info:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface.Ping()
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert exc_info.errisinstance(TypeError)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ex = exc_info.value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert str(ex) == 'More items found in D-Bus signature than in Python ' \
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik 'arguments'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test wrong parameter type
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with pytest.raises(TypeError) as exc_info:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface.Ping(1)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert exc_info.errisinstance(TypeError)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ex = exc_info.value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert str(ex) == 'Expected a string or unicode object'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test wrong parameter value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with pytest.raises(dbus.exceptions.DBusException) as exc_info:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface.Ping('test')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert exc_info.errisinstance(dbus.exceptions.DBusException)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ex = exc_info.value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_name() == 'org.freedesktop.DBus.Error.InvalidArgs'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_message() == 'Ping() only accepts "ping" as a param\n'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # positive test
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ret = sssd_interface.Ping('ping')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ret == "PONG"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test case insensitive input
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ret = sssd_interface.Ping('PinG')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ret == "PONG"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ret = sssd_interface.Ping('PING')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ret == "PONG"
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef test_special_characters(dbus_system_bus, ldap_conn, simple_rfc2307):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_obj = dbus_system_bus.get_object('org.freedesktop.sssd.infopipe',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik '/org/freedesktop/sssd/infopipe')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface = dbus.Interface(sssd_obj, 'org.freedesktop.sssd.infopipe')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik attributes = ['name', 'uidNumber', 'gidNumber', 'gecos', 'homeDirectory',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik 'loginShell']
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik expected = dict(name='usr\\001', uidNumber='181818', gidNumber='181818',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik gecos='181818', homeDirectory='/home/usr\\\\001',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik loginShell='/bin/bash')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik user_attrs = sssd_interface.GetUserAttr('usr\\001', attributes)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs.signature == 'sv'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs.variant_level == 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert len(attributes) == len(user_attrs)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert sorted(attributes) == sorted(user_attrs.keys())
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # check values of attributes
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for attr in user_attrs:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs[attr].signature == 's'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs[attr].variant_level == 1
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs[attr][0] == expected[attr]
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef test_get_user_attr(dbus_system_bus, ldap_conn, sanity_rfc2307):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_obj = dbus_system_bus.get_object('org.freedesktop.sssd.infopipe',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik '/org/freedesktop/sssd/infopipe')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface = dbus.Interface(sssd_obj, 'org.freedesktop.sssd.infopipe')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # negative test
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with pytest.raises(dbus.exceptions.DBusException) as exc_info:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface.GetUserAttr('non_existent_user', ['name'])
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert exc_info.errisinstance(dbus.exceptions.DBusException)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ex = exc_info.value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_name() == 'org.freedesktop.DBus.Error.Failed'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_message() == 'No such user\n'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # test 0 attributes
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik user_attrs = sssd_interface.GetUserAttr('user1', [])
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs.signature == 'sv'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs.variant_level == 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # expect empty sequence; len(user_attrs) == 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert not user_attrs
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # positive test
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik attributes = ['name', 'uidNumber', 'gidNumber', 'gecos', 'homeDirectory',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik 'loginShell']
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik expected = dict(name='user1', uidNumber='1001', gidNumber='2001',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik gecos='1001', homeDirectory='/home/user1',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik loginShell='/bin/bash')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik user_attrs = sssd_interface.GetUserAttr('user1', attributes)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs.signature == 'sv'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs.variant_level == 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert len(attributes) == len(user_attrs)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert sorted(attributes) == sorted(user_attrs.keys())
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # check values of attributes
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik for attr in user_attrs:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs[attr].signature == 's'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs[attr].variant_level == 1
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert user_attrs[attr][0] == expected[attr]
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnikdef test_get_user_groups(dbus_system_bus, ldap_conn, sanity_rfc2307):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_obj = dbus_system_bus.get_object('org.freedesktop.sssd.infopipe',
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik '/org/freedesktop/sssd/infopipe')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface = dbus.Interface(sssd_obj, 'org.freedesktop.sssd.infopipe')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # negative test
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with pytest.raises(dbus.exceptions.DBusException) as exc_info:
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik sssd_interface.GetUserGroups('non_existent_user')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert exc_info.errisinstance(dbus.exceptions.DBusException)
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik ex = exc_info.value
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_name() == 'org.freedesktop.DBus.Error.Failed'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert ex.get_dbus_message() == 'No such user\n'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # the same test via nss responder
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik with pytest.raises(KeyError):
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik pwd.getpwnam("non_existent_user")
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # 0 groups
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik res = sssd_interface.GetUserGroups('user3')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert res.signature == 's'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert res.variant_level == 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # expect empty sequence; len(res) == 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert not res
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # single group
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik res = sssd_interface.GetUserGroups('user2')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert res.signature == 's'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert res.variant_level == 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert len(res) == 1
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert res[0] == 'two_user_group'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik # more groups
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik res = sssd_interface.GetUserGroups('user1')
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert res.signature == 's'
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert res.variant_level == 0
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert len(res) == 2
0df79781d78973e5462dbef1e89d8fd6001da05cLukas Slebodnik assert sorted(res) == ['single_user_group', 'two_user_group']
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidênciodef test_sssctl_domain_list_app_domain(dbus_system_bus,
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio ldap_conn,
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio sanity_rfc2307):
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio output = get_call_output(["sssctl", "domain-list"], subprocess.STDOUT)
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio assert "Error" not in output
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio assert output.find("LDAP") != -1
14b485b11c31341c6874ac4183f757287fb30f64Fabiano Fidêncio assert output.find("app") != -1