dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0045-test_memory_cache-Add-test-for-initgroups-mc-with-fq.patch

6cf099
From b54fa4dacbb9cb225159d21976b637a78e461060 Mon Sep 17 00:00:00 2001
6cf099
From: Lukas Slebodnik <lslebodn@redhat.com>
6cf099
Date: Fri, 24 Jul 2015 15:13:01 +0200
6cf099
Subject: [PATCH 45/47] test_memory_cache: Add test for initgroups mc with fq
6cf099
 names
6cf099
MIME-Version: 1.0
6cf099
Content-Type: text/plain; charset=UTF-8
6cf099
Content-Transfer-Encoding: 8bit
6cf099
6cf099
Reviewed-by: Michal Židek <mzidek@redhat.com>
6cf099
(cherry picked from commit cb8c24707275c5bda7310d67e7f46c75d3ac36ea)
6cf099
---
6cf099
 src/tests/intg/test_memory_cache.py | 140 +++++++++++++++++++++++++++++++++++-
6cf099
 1 file changed, 138 insertions(+), 2 deletions(-)
6cf099
6cf099
diff --git a/src/tests/intg/test_memory_cache.py b/src/tests/intg/test_memory_cache.py
6cf099
index 5a1f07651b70a5bf1fbacceeae6825ea4341e3b5..12ce3c5054fe76560e31137d88043baf20641d3a 100644
6cf099
--- a/src/tests/intg/test_memory_cache.py
6cf099
+++ b/src/tests/intg/test_memory_cache.py
6cf099
@@ -106,8 +106,7 @@ def create_sssd_fixture(request):
6cf099
     request.addfinalizer(teardown)
6cf099
 
6cf099
 
6cf099
-@pytest.fixture
6cf099
-def sanity_rfc2307(request, ldap_conn):
6cf099
+def load_data_to_ldap(request, ldap_conn):
6cf099
     ent_list = ldap_ent.List(LDAP_BASE_DN)
6cf099
     ent_list.add_user("user1", 1001, 2001)
6cf099
     ent_list.add_user("user2", 1002, 2002)
6cf099
@@ -128,6 +127,64 @@ def sanity_rfc2307(request, ldap_conn):
6cf099
     ent_list.add_group("group2x", 2020, ["user21", "user22", "user23"])
6cf099
     create_ldap_fixture(request, ldap_conn, ent_list)
6cf099
 
6cf099
+
6cf099
+@pytest.fixture
6cf099
+def sanity_rfc2307(request, ldap_conn):
6cf099
+    load_data_to_ldap(request, ldap_conn)
6cf099
+
6cf099
+    conf = unindent("""\
6cf099
+        [sssd]
6cf099
+        config_file_version = 2
6cf099
+        domains             = LDAP
6cf099
+        services            = nss
6cf099
+
6cf099
+        [nss]
6cf099
+
6cf099
+        [domain/LDAP]
6cf099
+        ldap_auth_disable_tls_never_use_in_production = true
6cf099
+        ldap_schema         = rfc2307
6cf099
+        id_provider         = ldap
6cf099
+        auth_provider       = ldap
6cf099
+        sudo_provider       = ldap
6cf099
+        ldap_uri            = {ldap_conn.ds_inst.ldap_url}
6cf099
+        ldap_search_base    = {ldap_conn.ds_inst.base_dn}
6cf099
+    """).format(**locals())
6cf099
+    create_conf_fixture(request, conf)
6cf099
+    create_sssd_fixture(request)
6cf099
+    return None
6cf099
+
6cf099
+
6cf099
+@pytest.fixture
6cf099
+def fqname_rfc2307(request, ldap_conn):
6cf099
+    load_data_to_ldap(request, ldap_conn)
6cf099
+
6cf099
+    conf = unindent("""\
6cf099
+        [sssd]
6cf099
+        config_file_version = 2
6cf099
+        domains             = LDAP
6cf099
+        services            = nss
6cf099
+
6cf099
+        [nss]
6cf099
+
6cf099
+        [domain/LDAP]
6cf099
+        ldap_auth_disable_tls_never_use_in_production = true
6cf099
+        ldap_schema         = rfc2307
6cf099
+        id_provider         = ldap
6cf099
+        auth_provider       = ldap
6cf099
+        sudo_provider       = ldap
6cf099
+        ldap_uri            = {ldap_conn.ds_inst.ldap_url}
6cf099
+        ldap_search_base    = {ldap_conn.ds_inst.base_dn}
6cf099
+        use_fully_qualified_names = true
6cf099
+    """).format(**locals())
6cf099
+    create_conf_fixture(request, conf)
6cf099
+    create_sssd_fixture(request)
6cf099
+    return None
6cf099
+
6cf099
+
6cf099
+@pytest.fixture
6cf099
+def fqname_case_insensitive_rfc2307(request, ldap_conn):
6cf099
+    load_data_to_ldap(request, ldap_conn)
6cf099
+
6cf099
     conf = unindent("""\
6cf099
         [sssd]
6cf099
         config_file_version = 2
6cf099
@@ -144,6 +201,8 @@ def sanity_rfc2307(request, ldap_conn):
6cf099
         sudo_provider       = ldap
6cf099
         ldap_uri            = {ldap_conn.ds_inst.ldap_url}
6cf099
         ldap_search_base    = {ldap_conn.ds_inst.base_dn}
6cf099
+        use_fully_qualified_names = true
6cf099
+        case_sensitive = false
6cf099
     """).format(**locals())
6cf099
     create_conf_fixture(request, conf)
6cf099
     create_sssd_fixture(request)
6cf099
@@ -345,3 +404,80 @@ def test_initgroups_with_mc(ldap_conn, sanity_rfc2307):
6cf099
     test_initgroups(ldap_conn, sanity_rfc2307)
6cf099
     stop_sssd()
6cf099
     test_initgroups(ldap_conn, sanity_rfc2307)
6cf099
+
6cf099
+
6cf099
+def test_initgroups_fqname_with_mc(ldap_conn, fqname_rfc2307):
6cf099
+    assert_user_gids_equal('user1@LDAP', [2000, 2001])
6cf099
+    stop_sssd()
6cf099
+    assert_user_gids_equal('user1@LDAP', [2000, 2001])
6cf099
+
6cf099
+
6cf099
+def assert_initgroups_equal(user, primary_gid, expected_gids):
6cf099
+    (res, errno, gids) = sssd_id.call_sssd_initgroups(user, primary_gid)
6cf099
+    assert res == sssd_id.NssReturnCode.SUCCESS, \
6cf099
+        "Could not find groups for user %s, %d" % (user, errno)
6cf099
+
6cf099
+    assert sorted(gids) == sorted(expected_gids), \
6cf099
+        "result: %s\n expected %s" % (
6cf099
+            ", ".join(["%s" % s for s in sorted(gids)]),
6cf099
+            ", ".join(["%s" % s for s in sorted(expected_gids)])
6cf099
+        )
6cf099
+
6cf099
+
6cf099
+def assert_stored_last_initgroups(user1_case1, user1_case2, user1_case_last,
6cf099
+                                  primary_gid, expected_gids):
6cf099
+
6cf099
+    assert_initgroups_equal(user1_case1, primary_gid, expected_gids)
6cf099
+    assert_initgroups_equal(user1_case2, primary_gid, expected_gids)
6cf099
+    assert_initgroups_equal(user1_case_last, primary_gid, expected_gids)
6cf099
+    stop_sssd()
6cf099
+
6cf099
+    user = user1_case1
6cf099
+    (res, errno, gids) = sssd_id.call_sssd_initgroups(user, primary_gid)
6cf099
+    assert res == sssd_id.NssReturnCode.UNAVAIL, \
6cf099
+        "Initgroups for user shoudl fail user %s, %d" % (user, res)
6cf099
+
6cf099
+    user = user1_case2
6cf099
+    (res, errno, gids) = sssd_id.call_sssd_initgroups(user, primary_gid)
6cf099
+    assert res == sssd_id.NssReturnCode.UNAVAIL, \
6cf099
+        "Initgroups for user shoudl fail user %s, %d" % (user, res)
6cf099
+
6cf099
+    # Just last invocation of initgroups shoudl PASS
6cf099
+    # Otherwise, we would not be able to invalidate it
6cf099
+    assert_initgroups_equal(user1_case_last, primary_gid, expected_gids)
6cf099
+
6cf099
+
6cf099
+def test_initgroups_case_insensitive_with_mc1(ldap_conn,
6cf099
+                                              fqname_case_insensitive_rfc2307):
6cf099
+    user1_case1 = 'User1@LDAP'
6cf099
+    user1_case2 = 'uSer1@LDAP'
6cf099
+    user1_case_last = 'usEr1@LDAP'
6cf099
+    primary_gid = 2001
6cf099
+    expected_gids = [2000, 2001]
6cf099
+
6cf099
+    assert_stored_last_initgroups(user1_case1, user1_case2, user1_case_last,
6cf099
+                                  primary_gid, expected_gids)
6cf099
+
6cf099
+
6cf099
+def test_initgroups_case_insensitive_with_mc2(ldap_conn,
6cf099
+                                              fqname_case_insensitive_rfc2307):
6cf099
+    user1_case1 = 'usEr1@LDAP'
6cf099
+    user1_case2 = 'User1@LDAP'
6cf099
+    user1_case_last = 'uSer1@LDAP'
6cf099
+    primary_gid = 2001
6cf099
+    expected_gids = [2000, 2001]
6cf099
+
6cf099
+    assert_stored_last_initgroups(user1_case1, user1_case2, user1_case_last,
6cf099
+                                  primary_gid, expected_gids)
6cf099
+
6cf099
+
6cf099
+def test_initgroups_case_insensitive_with_mc3(ldap_conn,
6cf099
+                                              fqname_case_insensitive_rfc2307):
6cf099
+    user1_case1 = 'uSer1@LDAP'
6cf099
+    user1_case2 = 'usEr1@LDAP'
6cf099
+    user1_case_last = 'User1@LDAP'
6cf099
+    primary_gid = 2001
6cf099
+    expected_gids = [2000, 2001]
6cf099
+
6cf099
+    assert_stored_last_initgroups(user1_case1, user1_case2, user1_case_last,
6cf099
+                                  primary_gid, expected_gids)
6cf099
-- 
6cf099
2.4.3
6cf099