ldap_local_override_test.py revision 32dd0dd34193a7566d83adf6845f5194decc3304
#
# integration test for sss_override tool
#
# Copyright (c) 2015 Red Hat, Inc.
# Author: Pavel Reichl <preichl@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 ent
import grp
import pwd
import config
import signal
import subprocess
import time
import pytest
import ds_openldap
import ldap_ent
import sssd_id
try:
from subprocess import check_output
except ImportError:
# In python 2.6 , the module subprocess does not have the function
# check_output. This is a falback implementation
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be '
'overridden.')
**kwargs)
if retcode:
if cmd is None:
return output
"""LDAP server instance fixture"""
"cn=admin", "Secret123")
try:
except:
raise
return ds_inst
"""LDAP server connection fixture"""
return ldap_conn
"""Add LDAP entries and add teardown for removing them"""
def teardown():
"""Generate sssd.conf and add teardown for removing it"""
def stop_sssd():
while True:
try:
except:
break
def start_sssd():
"""Start sssd"""
raise Exception("sssd start failed")
def restart_sssd():
def create_sssd_fixture(request):
"""Start sssd and add teardown for stopping it and removing state"""
raise Exception("sssd start failed")
def teardown():
try:
except:
pass
OVERRIDE_FILENAME = "export_file"
"""Prepare SSSD with defaults"""
[sssd]
domains = LDAP
services = nss
[nss]
memcache_timeout = 1
ldap_auth_disable_tls_never_use_in_production = true
ldap_schema = rfc2307
id_provider = ldap
auth_provider = ldap
sudo_provider = ldap
ldap_uri = {ldap_conn.ds_inst.ldap_url}
ldap_search_base = {ldap_conn.ds_inst.base_dn}
use_fully_qualified_names = {use_fully_qualified_names}
case_sensitive = {case_sensitive}
def teardown():
# remove user export file
try:
except:
pass
#
# Common asserts for users
#
def assert_user_default():
# Assert entries are not overriden
gecos='User Number 1',
shell='/bin/user1_shell')
gecos='User Number 2',
shell='/bin/user2_shell')
def assert_user_overriden():
gecos='Overriden User 1',
shell='/bin/ov_user1_shell')
gecos='Overriden User 2',
shell='/bin/ov_user2_shell')
#
# Common fixtures for users
#
# Add entries
gecos='User Number 1',
loginShell='/bin/user1_shell',
homeDirectory='/home/user1')
gecos='User Number 2',
loginShell='/bin/user2_shell',
homeDirectory='/home/user2')
["user2", "user1"])
# Assert entries are not overriden
# Override
"-u", "10010",
"-g", "20010",
"-n", "ov_user1",
"-c", "Overriden User 1",
"-s", "/bin/ov_user1_shell"])
"-u", "10020",
"-g", "20020",
"-n", "ov_user2",
"-c", "Overriden User 2",
"-s", "/bin/ov_user2_shell"])
# Restart SSSD so the override might take effect
# Assert entries are overriden
#
# Simple user override
#
# Override
"-u", "10010",
"-g", "20010",
"-n", "ov_user1",
"-c", "Overriden User 1",
"-s", "/bin/ov_user1_shell"])
"-u", "10020",
"-g", "20020",
"-n", "ov_user2",
"-c", "Overriden User 2",
"-s", "/bin/ov_user2_shell"])
# Restart SSSD so the override might take effect
"""Test entries are overriden"""
#
# Root user override
#
# Assert entries are not overriden
'root',
# Override
"-u", "0",
"-g", "0",
"-n", "ov_user1",
"-c", "Overriden User 1",
"-s", "/bin/ov_user1_shell"])
"-u", "10020",
"-g", "20020",
"-n", "root",
"-c", "Overriden User 2",
"-s", "/bin/ov_user2_shell"])
# Restart SSSD so the override might take effect
"""Test entries are not overriden to root"""
# Override does not have to happen completly, trying to set uid or gid
# to 0 is simply ignored.
'ov_user1',
gecos='Overriden User 1',
shell='/bin/ov_user1_shell'))
# We can create override with name root. This test is just for tracking
# that this particular behavior won't change.
'user2',
gecos='Overriden User 2',
shell='/bin/ov_user2_shell'))
#
# Override replaces previous override
#
# Add entries
gecos='User Number 1',
loginShell='/bin/user1_shell',
homeDirectory='/home/user1')
# Assert entries are not overriden
'user1',
gecos='User Number 1',
shell='/bin/user1_shell'))
# Override
"-u", "10010",
"-g", "20010",
"-n", "ov_user1",
"-c", "Overriden User 1",
"-s", "/bin/ov_user1_shell"])
# Restart SSSD so the override might take effect
# Assert entries are overriden
'user1',
gecos='Overriden User 1',
shell='/bin/ov_user1_shell'))
# Override of override
"-u", "10100",
"-g", "20100",
"-n", "ov2_user1",
"-c", "Overriden2 User 1",
"-s", "/bin/ov2_user1_shell"])
# Restart SSSD so the override might take effect
gecos='Overriden2 User 1',
shell='/bin/ov2_user1_shell')
#
# Override removal
#
# Drop all overrides
# Avoid hitting memory cache
# Test entries are not overriden
#
#
# Export overrides
# Drop all overrides
# Avoid hitting memory cache
# Assert entries are not overridden
# Import overrides
#
# Override user-show
#
pass
assert out == "user1@LDAP:ov_user1:10010:20010:Overriden User 1:"\
"/home/ov/user1:/bin/ov_user1_shell\n"
assert out == "user2@LDAP:ov_user2:10020:20020:Overriden User 2:"\
"/home/ov/user2:/bin/ov_user2_shell\n"
# Return error on non-existing user
assert ret == 1
#
# Override user-find
#
pass
# Expected override of users
exp_usr_ovrd = ['user1@LDAP:ov_user1:10010:20010:Overriden User 1:'
'/home/ov/user1:/bin/ov_user1_shell',
'user2@LDAP:ov_user2:10020:20020:Overriden User 2:'
'/home/ov/user2:/bin/ov_user2_shell']
# Unexpected parameter is reported
assert ret == 1
#
# Group tests
#
#
# Common group asserts
#
def assert_group_overriden():
# Assert entries are overridden
def assert_group_default():
# Assert entries are not overridden
#
# Common fixtures for groups
#
# Add entries
gecos='User Number 1',
loginShell='/bin/user1_shell',
homeDirectory='/home/user1')
gecos='User Number 2',
loginShell='/bin/user2_shell',
homeDirectory='/home/user2')
["user2", "user1"])
# Assert entries are not overriden
# Override
"-n", "ov_group",
"-g", "3001"])
"--name", "ov_empty_group",
"--gid", "3002"])
# Restart SSSD so the override might take effect
# Assert entries are overridden
#
# Simple group override
#
# Override
"-n", "ov_group",
"-g", "3001"])
"--name", "ov_empty_group",
"--gid", "3002"])
# Restart SSSD so the override might take effect
"""Test entries are overriden"""
#
# Root group override
#
# Override
"-n", "ov_group",
"-g", "0"])
"--name", "ov_empty_group",
"--gid", "0"])
# Restart SSSD so the override might take effect
"""Test entries are overriden"""
#
# Replace group override
#
# Override of override
"-n", "ov2_group",
"-g", "4001"])
"--name", "ov2_empty_group",
"--gid", "4002"])
# Restart SSSD so the override might take effect
# Test overrides are overridden
#
# Remove group override
#
# Drop all overrides
# Avoid hitting memory cache
# Test overrides were dropped
#
#
# Export overrides
# Drop all overrides
# Avoid hitting memory cache
# Import overrides
# Regression test for bug #2802
# sss_override segfaults when accidentally adding --help flag to some commands
# Regression test for bug #2757
# sss_override does not work correctly when 'use_fully_qualified_names = True'
# Add entries
# Assert entries are not overridden
'user1@LDAP',
# Override
"-n", "alias1"])
# Assert entries are overridden
'user1@LDAP',
'alias1@LDAP',
# Regression test for bug #2790
# sss_override --name doesn't work with RFC2307 and ghost users
# Add entries
["user1", "user2"])
["user2"])
# Assert entries are not overridden
# Override
"-n", "alias1"])
"-n", "alias2"])
# Assert entries are overridden
"Could not find groups for user1 %d" % errno
assert grp_list == ["group1"]
"Could not find groups for user2 %d" % errno
# Test fully qualified and case-insensitive names
"""Setup test for mixed case names"""
# Add entries
# Override
"-u", "10010",
"-g", "20010",
"-n", "ov_user1",
"-c", "Overriden User 1",
"-s", "/bin/ov_user1_shell"])
"-u", "10020",
"-g", "20020",
"-n", "ov_user2",
"-c", "Overriden User 2",
"-s", "/bin/ov_user2_shell"])
"""Test if names with upper and lower case letter are overridden"""
# Assert entries are overridden
gecos='Overriden User 1',
shell='/bin/ov_user1_shell')
gecos='Overriden User 2',
shell='/bin/ov_user2_shell')