Commit 4a9100a TESTS: Add a test for the multiple files feature

1 file Authored and Committed by jhrozek 4 months ago
TESTS: Add a test for the multiple files feature

Adds an integration test for the new feature.

Reviewed-by: Pavel Březina <pbrezina@redhat.com>

    
  1 @@ -25,6 +25,7 @@
  2   import pwd
  3   import grp
  4   import pytest
  5 + import tempfile
  6   
  7   import ent
  8   import sssd_id
  9 @@ -33,7 +34,7 @@
 10                            call_sssd_enumeration,
 11                            call_sssd_getpwuid)
 12   from sssd_group import call_sssd_getgrnam, call_sssd_getgrgid
 13 - from files_ops import passwd_ops_setup, group_ops_setup
 14 + from files_ops import passwd_ops_setup, group_ops_setup, PasswdOps, GroupOps
 15   from util import unindent
 16   
 17   # Sync this with files_ops.c
 18 @@ -59,6 +60,11 @@
 19                   dir='/home/ov/user1',
 20                   shell='/bin/ov_user1_shell')
 21   
 22 + ALT_USER1 = dict(name='altuser1', passwd='x', uid=60001, gid=70001,
 23 +                  gecos='User for tests from alt files',
 24 +                  dir='/home/altuser1',
 25 +                  shell='/bin/bash')
 26 + 
 27   CANARY_GR = dict(name='canary',
 28                    gid=300001,
 29                    mem=[])
 30 @@ -79,6 +85,10 @@
 31                      gid=40000,
 32                      mem=[])
 33   
 34 + ALT_GROUP1 = dict(name='alt_group1',
 35 +                   gid=80001,
 36 +                   mem=['alt_user1'])
 37 + 
 38   
 39   def start_sssd():
 40       """Start sssd and add teardown for stopping it and removing state"""
 41 @@ -146,6 +156,38 @@
 42   
 43   
 44   @pytest.fixture
 45 + def files_multiple_sources(request):
 46 +     _, alt_passwd_path = tempfile.mkstemp(prefix='altpasswd')
 47 +     request.addfinalizer(lambda: os.unlink(alt_passwd_path))
 48 +     alt_pwops = PasswdOps(alt_passwd_path)
 49 + 
 50 +     _, alt_group_path = tempfile.mkstemp(prefix='altgroup')
 51 +     request.addfinalizer(lambda: os.unlink(alt_group_path))
 52 +     alt_grops = GroupOps(alt_group_path)
 53 + 
 54 +     passwd_list = ",".join([os.environ["NSS_WRAPPER_PASSWD"], alt_passwd_path])
 55 +     group_list = ",".join([os.environ["NSS_WRAPPER_GROUP"], alt_group_path])
 56 + 
 57 +     conf = unindent("""\
 58 +         [sssd]
 59 +         domains             = files
 60 +         services            = nss
 61 + 
 62 +         [nss]
 63 +         debug_level = 10
 64 + 
 65 +         [domain/files]
 66 +         id_provider = files
 67 +         passwd_files = {passwd_list}
 68 +         group_files = {group_list}
 69 +         debug_level = 10
 70 +     """).format(**locals())
 71 +     create_conf_fixture(request, conf)
 72 +     create_sssd_fixture(request)
 73 +     return alt_pwops, alt_grops
 74 + 
 75 + 
 76 + @pytest.fixture
 77   def proxy_to_files_domain_only(request):
 78       conf = unindent("""\
 79           [sssd]
 80 @@ -1054,3 +1096,20 @@
 81       res, user = sssd_getpwnam_sync(USER1["name"])
 82       assert res == NssReturnCode.SUCCESS
 83       assert user == USER1
 84 + 
 85 + 
 86 + def test_multiple_passwd_group_files(add_user_with_canary,
 87 +                                      add_group_with_canary,
 88 +                                      files_multiple_sources):
 89 +     """
 90 +     Test that users and groups can be mirrored from multiple files
 91 +     """
 92 +     alt_pwops, alt_grops = files_multiple_sources
 93 +     alt_pwops.useradd(**ALT_USER1)
 94 +     alt_grops.groupadd(**ALT_GROUP1)
 95 + 
 96 +     check_user(USER1)
 97 +     check_user(ALT_USER1)
 98 + 
 99 +     check_group(GROUP1)
100 +     check_group(ALT_GROUP1)