URL: https://github.com/freeipa/freeipa/pull/4050
Author: flo-renaud
 Title: #4050: [Backport][ipa-4-8] ipatests: filter_users should be applied 
correctly if SSSD starts offline
Action: opened

PR body:
"""
This PR was opened automatically because PR #3349 was pushed to master and 
backport to ipa-4-8 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/4050/head:pr4050
git checkout pr4050
From 136069d6ccdff0d944ce1fccb4099e4e20047ffd Mon Sep 17 00:00:00 2001
From: Anuja More <am...@redhat.com>
Date: Wed, 16 Oct 2019 17:15:20 +0530
Subject: [PATCH] ipatests: filter_users should be applied correctly.

Added test which checks that no look up should
be added in data provider when users are added in
filter_users for doamin provider.

Related Ticket:
https://pagure.io/SSSD/sssd/issue/3978

Signed-off-by: Anuja More <am...@redhat.com>
---
 ipatests/pytest_ipa/integration/tasks.py |  6 +++
 ipatests/test_integration/test_sssd.py   | 52 +++++++++++++++++++++---
 2 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py
index 24b7933fb9..b30c710166 100644
--- a/ipatests/pytest_ipa/integration/tasks.py
+++ b/ipatests/pytest_ipa/integration/tasks.py
@@ -1951,3 +1951,9 @@ def remote_ini_file(host, filename):
 def is_selinux_enabled(host):
     res = host.run_command('selinuxenabled', ok_returncode=(0, 1))
     return res.returncode == 0
+
+
+def get_logsize(host, logfile):
+    """ get current logsize"""
+    logsize = len(host.get_file_contents(logfile))
+    return logsize
diff --git a/ipatests/test_integration/test_sssd.py b/ipatests/test_integration/test_sssd.py
index ac31d42104..5d7420ef8f 100644
--- a/ipatests/test_integration/test_sssd.py
+++ b/ipatests/test_integration/test_sssd.py
@@ -13,14 +13,11 @@
 
 from ipatests.test_integration.base import IntegrationTest
 from ipatests.pytest_ipa.integration import tasks
+from ipaplatform.osinfo import osinfo
 from ipaplatform.paths import paths
 
 
-class TestSSSDAuthCache(IntegrationTest):
-    """Regression tests for cached_auth_timeout option
-
-       https://bugzilla.redhat.com/show_bug.cgi?id=1685581
-   """
+class TestSSSDWithAdTrust(IntegrationTest):
 
     topology = 'star'
     num_ad_domains = 1
@@ -34,6 +31,9 @@ class TestSSSDAuthCache(IntegrationTest):
             'name_tmpl': 'testuser@{domain}',
             'password': 'Secret123'
         },
+        'fakeuser': {
+            'name': 'some_user@some.domain'
+        },
     }
     ipa_user = 'user1'
     ipa_user_password = 'SecretUser1'
@@ -43,7 +43,7 @@ class TestSSSDAuthCache(IntegrationTest):
 
     @classmethod
     def install(cls, mh):
-        super(TestSSSDAuthCache, cls).install(mh)
+        super(TestSSSDWithAdTrust, cls).install(mh)
 
         cls.ad = cls.ads[0]  # pylint: disable=no-member
 
@@ -53,6 +53,9 @@ def install(cls, mh):
 
         cls.users['ad']['name'] = cls.users['ad']['name_tmpl'].format(
             domain=cls.ad.domain.name)
+
+        # Regression tests for cached_auth_timeout option
+        # https://bugzilla.redhat.com/show_bug.cgi?id=1685581
         tasks.user_add(cls.master, cls.intermed_user)
         tasks.create_active_user(cls.master, cls.ipa_user,
                                  cls.ipa_user_password)
@@ -108,3 +111,40 @@ def test_auth_cache_enabled_when_configured(self, user):
             assert self.is_auth_cached(self.users[user])
             time.sleep(10)
             assert not self.is_auth_cached(self.users[user])
+
+    @contextmanager
+    def filter_user_setup(self, user):
+        sssd_conf_backup = tasks.FileBackup(self.master, paths.SSSD_CONF)
+        filter_user = {'filter_users': self.users[user]['name']}
+        try:
+            tasks.modify_sssd_conf(self.master, self.master.domain.name,
+                                   filter_user)
+            tasks.clear_sssd_cache(self.master)
+            yield
+        finally:
+            sssd_conf_backup.restore()
+            tasks.clear_sssd_cache(self.master)
+
+    @pytest.mark.xfail(
+        osinfo.id == 'fedora' and osinfo.version_number <= (28,),
+        reason='https://pagure.io/SSSD/sssd/issue/3978')
+    @pytest.mark.parametrize('user', ['ad', 'fakeuser'])
+    def test_is_user_filtered(self, user):
+        """No lookup in data provider from 'filter_users' config option.
+
+        Test for https://bugzilla.redhat.com/show_bug.cgi?id=1685472
+        https://bugzilla.redhat.com/show_bug.cgi?id=1724088
+
+        When there are users in filter_users in domain section then no look
+        up should be in data provider.
+        """
+        with self.filter_user_setup(user=user):
+            log_file = '{0}/sssd_nss.log'.format(paths.VAR_LOG_SSSD_DIR)
+            logsize = tasks.get_logsize(self.master, log_file)
+            self.master.run_command(
+                ['getent', 'passwd', self.users[user]['name']],
+                ok_returncode=2)
+            sssd_log = self.master.get_file_contents(log_file)[logsize:]
+            dp_req = ("Looking up [{0}] in data provider".format(
+                self.users[user]['name']))
+            assert not dp_req.encode() in sssd_log
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org

Reply via email to