>From f6e715061a044856a2e9f4d1e54b602fcc193c6e Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Tue, 6 Oct 2015 09:20:39 -0400
Subject: [PATCH 4/5] intg: local overrides regression tests

Regression tests for: #2757, #2802, #2790

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

diff --git a/src/tests/intg/ldap_local_override_test.py b/src/tests/intg/ldap_local_override_test.py
index 79112859f1c4639a0b024f213534d4d5c45b7ca0..a23e34a52c7583537f6ecba7f190badf242a9ba9 100644
--- a/src/tests/intg/ldap_local_override_test.py
+++ b/src/tests/intg/ldap_local_override_test.py
@@ -464,3 +464,128 @@ def test_local_override_group(ldap_conn, sanity_rfc2307):
 
     # clean up - remove override file
     subprocess.check_call(["rm", override_filename])
+
+
+def test_local_overrides_regr_2802():
+
+    # bug #2802 sss_override segfaults when accidentally adding --help flag to
+    # some commands
+    subprocess.call(["sss_override", "user-del", "--help"])
+
+
+@pytest.fixture
+def rfc2307_2757(request, ldap_conn):
+
+    # fill ldap
+    ent_list = ldap_ent.List(LDAP_BASE_DN)
+    ent_list.add_user("user1", 10001, 20001)
+
+    create_ldap_fixture(request, ldap_conn, ent_list)
+    #
+
+    conf = unindent("""\
+        [sssd]
+        domains             = LDAP
+        services            = nss
+
+        [nss]
+
+        [domain/LDAP]
+        ldap_auth_disable_tls_never_use_in_production = true
+        ldap_schema         = rfc2307
+        id_provider         = ldap
+        auth_provider       = ldap
+        sudo_provider       = ldap
+        ldap_uri            = {ldap_conn.ds_inst.ldap_url}
+        ldap_search_base    = {ldap_conn.ds_inst.base_dn}
+        use_fully_qualified_names = true
+    """).format(**locals())
+    create_conf_fixture(request, conf)
+    create_sssd_fixture(request)
+    return None
+
+
+def test_local_overrides_regr_2757(ldap_conn, rfc2307_2757):
+
+    # #2757 sss_override does not work correctly when
+    # 'use_fully_qualified_names = True'
+    ent.assert_passwd_by_name(
+        'user1@LDAP',
+        dict(name='user1@LDAP', passwd='*', uid=10001, gid=20001))
+
+    subprocess.check_call(["sss_override", "user-add", "user1@LDAP",
+                           "-n", "alias1"])
+    restart_sssd()
+
+    ent.assert_passwd_by_name(
+        'alias1@LDAP',
+        dict(name='alias1@LDAP', passwd='*', uid=10001, gid=20001))
+
+    subprocess.check_call(["sss_override", "user-add", "user1@LDAP",
+                           "-n", "alias2@LDAP"])
+    restart_sssd()
+
+    ent.assert_passwd_by_name(
+        'alias2@LDAP',
+        dict(name='alias2@LDAP', passwd='*', uid=10001, gid=20001))
+
+
+@pytest.fixture
+def rfc2307_2790(request, ldap_conn):
+
+    # fill ldap
+    ent_list = ldap_ent.List(LDAP_BASE_DN)
+    ent_list.add_user("user1", 10001, 20001)
+    ent_list.add_user("user2", 10002, 20002)
+
+    ent_list.add_group("group1", 2001,
+                       ["user1", "user2"])
+    ent_list.add_group("group2", 2002,
+                       ["user2"])
+
+    create_ldap_fixture(request, ldap_conn, ent_list)
+    #
+
+    conf = unindent("""\
+        [sssd]
+        domains             = LDAP
+        services            = nss
+
+        [nss]
+
+        [domain/LDAP]
+        ldap_auth_disable_tls_never_use_in_production = true
+        ldap_schema         = rfc2307
+        id_provider         = ldap
+        auth_provider       = ldap
+        sudo_provider       = ldap
+        ldap_uri            = {ldap_conn.ds_inst.ldap_url}
+        ldap_search_base    = {ldap_conn.ds_inst.base_dn}
+    """).format(**locals())
+    create_conf_fixture(request, conf)
+    create_sssd_fixture(request)
+    return None
+
+
+def test_local_overrides_regr_2790(ldap_conn, rfc2307_2790):
+
+    # #2790 sss_override --name doesn't work with RFC2307 and ghost users
+    ent.assert_passwd_by_name(
+        'user1',
+        dict(name='user1', passwd='*', uid=10001, gid=20001))
+
+    subprocess.check_call(["sss_override", "user-add", "user1",
+                           "-n", "alias1"])
+    subprocess.check_call(["sss_override", "user-add", "user2",
+                           "-n", "alias2"])
+    restart_sssd()
+
+    (res, errno, grp_list) = sssd_id.get_user_groups("alias1")
+    assert res == sssd_id.NssReturnCode.SUCCESS, \
+        "Could not find groups for user1 %d" % errno
+    assert grp_list == ["group1"]
+
+    (res, errno, grp_list) = sssd_id.get_user_groups("alias2")
+    assert res == sssd_id.NssReturnCode.SUCCESS, \
+        "Could not find groups for user2 %d" % errno
+    assert sorted(grp_list) == sorted(["group1", "group2"])
-- 
2.4.3

