def test_disabled_passwd_mc(ldap_conn, disable_pwd_mc_rfc2307): ent.assert_passwd_by_name( 'user1', dict(name='user1', passwd='*', uid=1001, gid=2001, gecos='1001', shell='/bin/bash')) ent.assert_passwd_by_uid( 1001, dict(name='user1', passwd='*', uid=1001, gid=2001, gecos='1001', shell='/bin/bash')) assert_user_gids_equal('user1', [2000, 2001]) stop_sssd() # passwd cache is disabled with pytest.raises(KeyError): pwd.getpwnam('user1') with pytest.raises(KeyError): pwd.getpwuid(1001) # Initgroups looks up the user first, hence KeyError from the # passwd database even if the initgroups cache is active. with pytest.raises(KeyError): (res, errno, gids) = sssd_id.get_user_gids('user1')
def test_disabled_mc(ldap_conn, disable_memcache_rfc2307): ent.assert_passwd_by_name( 'user1', dict(name='user1', passwd='*', uid=1001, gid=2001, gecos='1001', shell='/bin/bash')) ent.assert_passwd_by_uid( 1001, dict(name='user1', passwd='*', uid=1001, gid=2001, gecos='1001', shell='/bin/bash')) ent.assert_group_by_name("group1", dict(name="group1", gid=2001)) ent.assert_group_by_gid(2001, dict(name="group1", gid=2001)) assert_user_gids_equal('user1', [2000, 2001]) stop_sssd() # sssd is stopped and the memory cache is disabled; # so pytest should not be able to find anything with pytest.raises(KeyError): pwd.getpwnam('user1') with pytest.raises(KeyError): pwd.getpwuid(1001) with pytest.raises(KeyError): grp.getgrnam('group1') with pytest.raises(KeyError): grp.getgrgid(2001) with pytest.raises(KeyError): (res, errno, gids) = sssd_id.get_user_gids('user1')
def assert_user_gids_equal(user, expected_gids): (res, errno, gids) = sssd_id.get_user_gids(user) assert res == sssd_id.NssReturnCode.SUCCESS, \ "Could not find groups for user %s, %d" % (user, errno) assert sorted(gids) == sorted(expected_gids), \ "result: %s\n expected %s" % ( ", ".join(["%s" % s for s in sorted(gids)]), ", ".join(["%s" % s for s in sorted(expected_gids)]) )
def assert_unsuccessful_initgr(user): with pytest.raises(KeyError): (res, errno, gids) = sssd_id.get_user_gids(user)