>From b31b156bedc677a58a7c4f2359c66655c547fbec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
Date: Sun, 8 Nov 2015 22:17:44 +0100
Subject: [PATCH 2/2] Fixup this to Nick's patch

---
 src/tests/intg/ldap_test.py | 220 +++++---------------------------------------
 1 file changed, 24 insertions(+), 196 deletions(-)

diff --git a/src/tests/intg/ldap_test.py b/src/tests/intg/ldap_test.py
index 40f9009..7b9cd35 100644
--- a/src/tests/intg/ldap_test.py
+++ b/src/tests/intg/ldap_test.py
@@ -33,6 +33,7 @@ import ldap_ent
 from util import *
 
 LDAP_BASE_DN = "dc=example,dc=com"
+INTERACTIVE_TIMEOUT = 4
 
 
 @pytest.fixture(scope="module")
@@ -133,14 +134,15 @@ def format_interactive_conf(ldap_conn, schema):
         format_basic_conf(ldap_conn, schema, enum=True) + \
         unindent("""
             [nss]
-            enum_cache_timeout                  = 4
-            entry_negative_timeout              = 4
+            memcache_timeout                    = 0
+            enum_cache_timeout                  = {0}
+            entry_negative_timeout              = 0
 
             [domain/LDAP]
-            ldap_enumeration_refresh_timeout    = 4
+            ldap_enumeration_refresh_timeout    = {0}
             ldap_purge_cache_timeout            = 1
-            entry_cache_timeout                 = 4
-        """)
+            entry_cache_timeout                 = {0}
+        """).format(INTERACTIVE_TIMEOUT)
 
 
 def create_conf_file(contents):
@@ -463,69 +465,61 @@ def user_and_groups_rfc2307_bis(request, ldap_conn):
 def test_add_remove_user(ldap_conn, blank_rfc2307):
     """Test user addition and removal are reflected by SSSD"""
     e = ldap_ent.user(ldap_conn.ds_inst.base_dn, "user", 1001, 2000)
-    time.sleep(2)
+    time.sleep(INTERACTIVE_TIMEOUT/2)
     # Add the user
     ent.assert_passwd(ent.contains_only())
     ldap_conn.add_s(*e)
-    ent.assert_passwd(ent.contains_only())
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_passwd(ent.contains_only(dict(name="user", uid=1001)))
     # Remove the user
     ldap_conn.delete_s(e[0])
-    ent.assert_passwd(ent.contains_only(dict(name="user", uid=1001)))
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_passwd(ent.contains_only())
 
 
 def test_add_remove_group_rfc2307(ldap_conn, blank_rfc2307):
     """Test RFC2307 group addition and removal are reflected by SSSD"""
     e = ldap_ent.group(ldap_conn.ds_inst.base_dn, "group", 2001)
-    time.sleep(2)
+    time.sleep(INTERACTIVE_TIMEOUT/2)
     # Add the group
     ent.assert_group(ent.contains_only())
     ldap_conn.add_s(*e)
-    ent.assert_group(ent.contains_only())
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group(ent.contains_only(dict(name="group", gid=2001)))
     # Remove the group
     ldap_conn.delete_s(e[0])
-    ent.assert_group(ent.contains_only(dict(name="group", gid=2001)))
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group(ent.contains_only())
 
 
 def test_add_remove_group_rfc2307_bis(ldap_conn, blank_rfc2307_bis):
     """Test RFC2307bis group addition and removal are reflected by SSSD"""
     e = ldap_ent.group_bis(ldap_conn.ds_inst.base_dn, "group", 2001)
-    time.sleep(2)
+    time.sleep(INTERACTIVE_TIMEOUT/2)
     # Add the group
     ent.assert_group(ent.contains_only())
     ldap_conn.add_s(*e)
-    ent.assert_group(ent.contains_only())
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group(ent.contains_only(dict(name="group", gid=2001)))
     # Remove the group
     ldap_conn.delete_s(e[0])
-    ent.assert_group(ent.contains_only(dict(name="group", gid=2001)))
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group(ent.contains_only())
 
 
 def test_add_remove_membership_rfc2307(ldap_conn, user_and_group_rfc2307):
     """Test user membership addition and removal are reflected by SSSD"""
-    time.sleep(2)
+    time.sleep(INTERACTIVE_TIMEOUT/2)
     # Add user to group
     ent.assert_group_by_name("group", dict(mem=ent.contains_only()))
     ldap_conn.modify_s("cn=group,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_REPLACE, "memberUid", "user")])
-    ent.assert_group_by_name("group", dict(mem=ent.contains_only()))
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group_by_name("group", dict(mem=ent.contains_only("user")))
     # Remove user from group
     ldap_conn.modify_s("cn=group,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_DELETE, "memberUid", None)])
-    ent.assert_group_by_name("group", dict(mem=ent.contains_only("user")))
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group_by_name("group", dict(mem=ent.contains_only()))
 
 
@@ -535,202 +529,36 @@ def test_add_remove_membership_rfc2307_bis(ldap_conn,
     Test user and group membership addition and removal are reflected by SSSD,
     with RFC2307bis schema
     """
-    time.sleep(2)
+    time.sleep(INTERACTIVE_TIMEOUT/2)
     # Add user to group1
     ent.assert_group_by_name("group1", dict(mem=ent.contains_only()))
     ldap_conn.modify_s("cn=group1,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_REPLACE, "member",
                          "uid=user,ou=Users," + ldap_conn.ds_inst.base_dn)])
-    ent.assert_group_by_name("group1", dict(mem=ent.contains_only()))
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group_by_name("group1", dict(mem=ent.contains_only("user")))
 
     # Add group1 to group2
     ldap_conn.modify_s("cn=group2,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_REPLACE, "member",
                          "cn=group1,ou=Groups," + ldap_conn.ds_inst.base_dn)])
-    ent.assert_group_by_name("group2", dict(mem=ent.contains_only()))
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group_by_name("group2", dict(mem=ent.contains_only("user")))
 
     # Remove group1 from group2
     ldap_conn.modify_s("cn=group2,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_DELETE, "member", None)])
-    ent.assert_group_by_name("group2", dict(mem=ent.contains_only("user")))
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group_by_name("group2", dict(mem=ent.contains_only()))
 
     # Remove user from group1
     ldap_conn.modify_s("cn=group1,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_DELETE, "member", None)])
-    ent.assert_group_by_name("group1", dict(mem=ent.contains_only("user")))
-    time.sleep(4)
+    time.sleep(INTERACTIVE_TIMEOUT)
     ent.assert_group_by_name("group1", dict(mem=ent.contains_only()))
 
 
 @pytest.fixture
-def void_conf(request):
-    create_conf_cleanup(request)
-
-
-@pytest.fixture
-def void_sssd(request):
-    create_sssd_cleanup(request)
-
-
-@pytest.fixture
-def three_users_three_groups_rfc2307(request, ldap_conn):
-    ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
-    ent_list.add_user("user1", 1001, 2001)
-    ent_list.add_user("user2", 1002, 2002)
-    ent_list.add_user("user3", 1003, 2003)
-    ent_list.add_group("group1", 2001, ["user1"])
-    ent_list.add_group("group2", 2002, ["user2"])
-    ent_list.add_group("group3", 2003, ["user3"])
-    create_ldap_fixture(request, ldap_conn, ent_list)
-
-
-def test_filter_users(request, ldap_conn, three_users_three_groups_rfc2307,
-                      void_conf, void_sssd):
-    """Test the effect of the "filter_users" option"""
-    all_users = frozenset([1, 2, 3])
-    for filter_users_in_groups in [False, True]:
-        for filter_users in [frozenset([]),
-                             frozenset([1]),
-                             frozenset([1, 2]),
-                             frozenset([1, 2, 3])]:
-            unfiltered_users = all_users - filter_users
-            filter_users_str = ",".join(map(lambda i: "user" + str(i),
-                                            filter_users))
-
-            conf = \
-                format_basic_conf(ldap_conn, SCHEMA_RFC2307, enum=True) + \
-                unindent("""
-                    [nss]
-                    filter_users            = {filter_users_str}
-                    filter_users_in_groups  = {filter_users_in_groups}
-                """).format(**locals())
-            create_conf_file(conf)
-            create_sssd_process()
-            ent.assert_passwd(
-                ent.contains_only(
-                    *map(
-                        lambda i:
-                            dict(name="user" + str(i), uid=1000 + i),
-                        unfiltered_users
-                    )
-                )
-            )
-            ent.assert_group(
-                ent.contains_only(
-                    *map(
-                        lambda i:
-                            dict(
-                                name="group" + str(i),
-                                gid=2000 + i,
-                                mem=ent.contains_only()
-                                if filter_users_in_groups and i in filter_users
-                                else ent.contains_only("user" + str(i))
-                            ),
-                        all_users
-                    )
-                )
-            )
-            cleanup_sssd_process()
-            cleanup_conf_file()
-
-
-def test_filter_groups_rfc2307(request, ldap_conn,
-                               three_users_three_groups_rfc2307,
-                               void_conf, void_sssd):
-    """Test the effect of the "filter_groups" option with RFC2307 groups"""
-    all_groups = frozenset([1, 2, 3])
-    for filter_groups in [frozenset([]),
-                          frozenset([1]),
-                          frozenset([1, 2]),
-                          frozenset([1, 2, 3])]:
-        unfiltered_groups = all_groups - filter_groups
-        filter_groups_str = ",".join(map(lambda i: "group" + str(i),
-                                         filter_groups))
-
-        conf = \
-            format_basic_conf(ldap_conn, SCHEMA_RFC2307, enum=True) + \
-            unindent("""
-                [nss]
-                filter_groups   = {filter_groups_str}
-            """).format(**locals())
-        create_conf_file(conf)
-        create_sssd_process()
-        ent.assert_group(
-            ent.contains_only(
-                *map(
-                    lambda i:
-                        dict(
-                            name="group" + str(i),
-                            gid=2000 + i,
-                            mem=ent.contains_only("user" + str(i))
-                        ),
-                    unfiltered_groups
-                )
-            )
-        )
-        cleanup_sssd_process()
-        cleanup_conf_file()
-
-
-@pytest.fixture
-def three_users_three_groups_rfc2307_bis(request, ldap_conn):
-    ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
-    ent_list.add_user("user1", 1001, 2001)
-    ent_list.add_user("user2", 1002, 2002)
-    ent_list.add_user("user3", 1003, 2003)
-    ent_list.add_group_bis("group1", 2001, ["user1"])
-    ent_list.add_group_bis("group2", 2002, ["user2"], ["group1"])
-    ent_list.add_group_bis("group3", 2003, ["user3"], ["group2"])
-    create_ldap_fixture(request, ldap_conn, ent_list)
-
-
-def test_filter_groups_rfc2307_bis(request, ldap_conn,
-                                   three_users_three_groups_rfc2307_bis,
-                                   void_conf, void_sssd):
-    """Test the effect of the "filter_groups" option with RFC2307bis groups"""
-    all_groups = frozenset([1, 2, 3])
-    for filter_groups in [frozenset([]),
-                          frozenset([1]),
-                          frozenset([1, 2]),
-                          frozenset([1, 2, 3])]:
-        unfiltered_groups = all_groups - filter_groups
-        filter_groups_str = ",".join(map(lambda i: "group" + str(i),
-                                         filter_groups))
-
-        conf = \
-            format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS, enum=True) + \
-            unindent("""
-                [nss]
-                filter_groups   = {filter_groups_str}
-            """).format(**locals())
-        create_conf_file(conf)
-        create_sssd_process()
-        ent.assert_group(
-            ent.contains_only(
-                *map(
-                    lambda i:
-                        dict(
-                            name="group" + str(i),
-                            gid=2000 + i,
-                            mem=ent.contains_only(
-                                    *map(lambda j: "user" + str(j),
-                                         range(1, i + 1)))
-                        ),
-                    unfiltered_groups
-                )
-            )
-        )
-        cleanup_sssd_process()
-        cleanup_conf_file()
-
-
-@pytest.fixture
 def override_homedir(request, ldap_conn):
     ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
     ent_list.add_user("user_with_homedir_A", 1001, 2001,
-- 
2.1.0

