>From a3225029f25ac74aa418019efb503db6c3e71c31 Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Mon, 12 Oct 2015 16:42:47 -0400
Subject: [PATCH 2/3] intg: new test for group local overrides

Introduce a new integration test for local view overrides.

Resolves:
https://fedorahosted.org/sssd/ticket/2732
---
 src/tests/intg/ldap_local_override_test.py | 97 +++++++++++++++++++++++++++++-
 1 file changed, 95 insertions(+), 2 deletions(-)

diff --git a/src/tests/intg/ldap_local_override_test.py b/src/tests/intg/ldap_local_override_test.py
index 66bcb3c29b9e1ac861fb4c7a28d381a8302093f2..7c3a3d4254ed615f94412b5d1f1226ee40d8c681 100644
--- a/src/tests/intg/ldap_local_override_test.py
+++ b/src/tests/intg/ldap_local_override_test.py
@@ -132,13 +132,19 @@ def load_data_to_ldap(request, ldap_conn):
                       loginShell='/bin/user2_shell',
                       homeDirectory='/home/user2')
 
+    ent_list.add_user("weird()", 10005, 20001)
+
     ent_list.add_group("group", 2001,
                        ["user2", "user1"])
 
+    ent_list.add_group("empty_group", 2005, [])
+    ent_list.add_group("weird_gr()up", 2006, ["weird()"])
+
     create_ldap_fixture(request, ldap_conn, ent_list)
 
 
 override_user_filename = "user_export_file"
+override_group_filename = "group_export_file"
 
 
 @pytest.fixture
@@ -165,8 +171,17 @@ def sanity_rfc2307(request, ldap_conn):
     create_sssd_fixture(request)
 
     def teardown():
-        # remove user export file
-        os.unlink(override_user_filename)
+        # remove user and group export file
+        try:
+            os.unlink(override_user_filename)
+        except:
+            pass
+
+        try:
+            os.unlink(override_group_filename)
+        except:
+            pass
+
     request.addfinalizer(teardown)
 
     return None
@@ -337,3 +352,81 @@ def test_local_override_user_cached(ldap_conn, sanity_rfc2307):
     check_users_from_ldap()
 
     test_local_override_user(ldap_conn, sanity_rfc2307)
+
+
+def check_groups_from_ldap():
+    ent.assert_group_by_name(
+        "group", dict(gid=2001, mem=ent.contains_only("user1", "user2")))
+    ent.assert_group_by_name(
+        "empty_group", dict(gid=2005, mem=ent.contains_only()))
+    ent.assert_group_by_name(
+        "weird_gr()up", dict(gid=2006, mem=ent.contains_only("weird()")))
+
+
+def test_local_override_group(ldap_conn, sanity_rfc2307):
+    """ test commands: group-add, group-del, group-import, group-export """
+    def perform_override_1():
+        subprocess.check_call(["sss_override", "group-add", "group",
+                               "-n", "ov_group"])
+
+        subprocess.check_call(["sss_override", "group-add", "empty_group@LDAP",
+                               "--name", "void",
+                               "--gid", "3001"])
+
+    def check_groups_after_override_1():
+        ent.assert_group_by_name("ov_group@LDAP",
+                                 dict(gid=2001,
+                                      mem=ent.contains_only("user1", "user2")))
+        ent.assert_group_by_name("void",
+                                 dict(gid=3001,
+                                      mem=ent.contains_only()))
+
+    def check_groups_after_override_2():
+        ent.assert_group_by_gid(3000,
+                                dict(name="group", gid=3000,
+                                     mem=ent.contains_only("user1", "user2")))
+
+        ent.assert_group_by_gid(3001,
+                                dict(name="void",
+                                     mem=ent.contains_only()))
+
+        with pytest.raises(KeyError):
+            grp.getgrnam('ov_group')
+
+    def drop_all_overrides():
+        subprocess.check_call(["sss_override", "group-del", "group"])
+        subprocess.check_call(["sss_override", "group-del", "empty_group"])
+
+    # end of local functions
+
+    perform_override_1()
+    restart_sssd()
+
+    check_groups_after_override_1()
+
+    # drop prev. override and do override #2
+    subprocess.check_call(["sss_override", "group-add", "group", "-g", "3000"])
+    restart_sssd()
+
+    check_groups_after_override_2()
+
+    subprocess.call(["sss_override", "group-export", override_group_filename])
+    restart_sssd()
+
+    drop_all_overrides()
+    restart_sssd()
+
+    check_groups_from_ldap()
+
+    subprocess.call(["sss_override", "group-import", override_group_filename])
+    restart_sssd()
+
+    check_groups_after_override_2()
+
+
+def test_local_override_group_cached(ldap_conn, sanity_rfc2307):
+
+    # put object to sysdb cache before perfoming tests
+    check_groups_from_ldap()
+
+    test_local_override_group(ldap_conn, sanity_rfc2307)
-- 
2.4.3

