sssd/0024-TESTS-Add-a-test-for-t...

124 lines
3.9 KiB
Diff

From bb1455ce8d45d026f173f402bce29bf97af8c44d Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Mon, 26 Mar 2018 17:30:14 +0200
Subject: [PATCH] TESTS: Add a test for the multiple files feature
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Adds an integration test for the new feature.
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
(cherry picked from commit 4a9100a588ade253cecb2224b95bd8caa8136109)
---
src/tests/intg/test_files_provider.py | 61 ++++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/src/tests/intg/test_files_provider.py b/src/tests/intg/test_files_provider.py
index 41bfd8844..ce5c7b774 100644
--- a/src/tests/intg/test_files_provider.py
+++ b/src/tests/intg/test_files_provider.py
@@ -25,6 +25,7 @@ import subprocess
import pwd
import grp
import pytest
+import tempfile
import ent
import sssd_id
@@ -33,7 +34,7 @@ from sssd_passwd import (call_sssd_getpwnam,
call_sssd_enumeration,
call_sssd_getpwuid)
from sssd_group import call_sssd_getgrnam, call_sssd_getgrgid
-from files_ops import passwd_ops_setup, group_ops_setup
+from files_ops import passwd_ops_setup, group_ops_setup, PasswdOps, GroupOps
from util import unindent
# Sync this with files_ops.c
@@ -59,6 +60,11 @@ OV_USER1 = dict(name='ov_user1', passwd='x', uid=10010, gid=20010,
dir='/home/ov/user1',
shell='/bin/ov_user1_shell')
+ALT_USER1 = dict(name='altuser1', passwd='x', uid=60001, gid=70001,
+ gecos='User for tests from alt files',
+ dir='/home/altuser1',
+ shell='/bin/bash')
+
CANARY_GR = dict(name='canary',
gid=300001,
mem=[])
@@ -79,6 +85,10 @@ GROUP_NOMEM = dict(name='group_nomem',
gid=40000,
mem=[])
+ALT_GROUP1 = dict(name='alt_group1',
+ gid=80001,
+ mem=['alt_user1'])
+
def start_sssd():
"""Start sssd and add teardown for stopping it and removing state"""
@@ -145,6 +155,38 @@ def files_domain_only(request):
return None
+@pytest.fixture
+def files_multiple_sources(request):
+ _, alt_passwd_path = tempfile.mkstemp(prefix='altpasswd')
+ request.addfinalizer(lambda: os.unlink(alt_passwd_path))
+ alt_pwops = PasswdOps(alt_passwd_path)
+
+ _, alt_group_path = tempfile.mkstemp(prefix='altgroup')
+ request.addfinalizer(lambda: os.unlink(alt_group_path))
+ alt_grops = GroupOps(alt_group_path)
+
+ passwd_list = ",".join([os.environ["NSS_WRAPPER_PASSWD"], alt_passwd_path])
+ group_list = ",".join([os.environ["NSS_WRAPPER_GROUP"], alt_group_path])
+
+ conf = unindent("""\
+ [sssd]
+ domains = files
+ services = nss
+
+ [nss]
+ debug_level = 10
+
+ [domain/files]
+ id_provider = files
+ passwd_files = {passwd_list}
+ group_files = {group_list}
+ debug_level = 10
+ """).format(**locals())
+ create_conf_fixture(request, conf)
+ create_sssd_fixture(request)
+ return alt_pwops, alt_grops
+
+
@pytest.fixture
def proxy_to_files_domain_only(request):
conf = unindent("""\
@@ -1054,3 +1096,20 @@ def test_no_sssd_conf(add_user_with_canary, no_sssd_conf):
res, user = sssd_getpwnam_sync(USER1["name"])
assert res == NssReturnCode.SUCCESS
assert user == USER1
+
+
+def test_multiple_passwd_group_files(add_user_with_canary,
+ add_group_with_canary,
+ files_multiple_sources):
+ """
+ Test that users and groups can be mirrored from multiple files
+ """
+ alt_pwops, alt_grops = files_multiple_sources
+ alt_pwops.useradd(**ALT_USER1)
+ alt_grops.groupadd(**ALT_GROUP1)
+
+ check_user(USER1)
+ check_user(ALT_USER1)
+
+ check_group(GROUP1)
+ check_group(ALT_GROUP1)
--
2.14.3