dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0018-TESTS-Add-regression-test-for-looking-up-users-with-.patch

ca1eb8
From 0cbf6070bccb6c1f904cea596f00af0cc6328bae Mon Sep 17 00:00:00 2001
ca1eb8
From: Jakub Hrozek <jhrozek@redhat.com>
ca1eb8
Date: Thu, 21 Jun 2018 12:37:57 +0200
ca1eb8
Subject: [PATCH] TESTS: Add regression test for looking up users with
ca1eb8
 conflicting e-mail addresses
ca1eb8
MIME-Version: 1.0
ca1eb8
Content-Type: text/plain; charset=UTF-8
ca1eb8
Content-Transfer-Encoding: 8bit
ca1eb8
ca1eb8
Related:
ca1eb8
https://pagure.io/SSSD/sssd/issue/3607
ca1eb8
ca1eb8
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
ca1eb8
(cherry picked from commit 76ce965fc3abfdcf3a4a9518e57545ea060033d6)
ca1eb8
---
ca1eb8
 src/tests/intg/test_ldap.py | 64 +++++++++++++++++++++++++++++++++++++
ca1eb8
 1 file changed, 64 insertions(+)
ca1eb8
ca1eb8
diff --git a/src/tests/intg/test_ldap.py b/src/tests/intg/test_ldap.py
ca1eb8
index f71915a8086d395e9971a7c82e2744bdd7b931b6..d70ae39841f111fdf2d6c00c9acca8073725c5c5 100644
ca1eb8
--- a/src/tests/intg/test_ldap.py
ca1eb8
+++ b/src/tests/intg/test_ldap.py
ca1eb8
@@ -1736,3 +1736,67 @@ def test_local_negative_timeout_disabled(ldap_conn,
ca1eb8
     assert res == NssReturnCode.SUCCESS
ca1eb8
 
ca1eb8
     cleanup_ldap_entries(ldap_conn, ent_list)
ca1eb8
+
ca1eb8
+
ca1eb8
+@pytest.fixture
ca1eb8
+def users_with_email_setup(request, ldap_conn):
ca1eb8
+    ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
ca1eb8
+    ent_list.add_user("user1", 1001, 2001, mail="user1.email@LDAP")
ca1eb8
+
ca1eb8
+    ent_list.add_user("emailuser", 1002, 2002)
ca1eb8
+    ent_list.add_user("emailuser2", 1003, 2003, mail="emailuser@LDAP")
ca1eb8
+
ca1eb8
+    ent_list.add_user("userx", 1004, 2004, mail="userxy@LDAP")
ca1eb8
+    ent_list.add_user("usery", 1005, 2005, mail="userxy@LDAP")
ca1eb8
+
ca1eb8
+    create_ldap_fixture(request, ldap_conn, ent_list)
ca1eb8
+
ca1eb8
+    conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
ca1eb8
+    create_conf_fixture(request, conf)
ca1eb8
+    create_sssd_fixture(request)
ca1eb8
+    return None
ca1eb8
+
ca1eb8
+
ca1eb8
+def test_lookup_by_email(ldap_conn, users_with_email_setup):
ca1eb8
+    """
ca1eb8
+    Test the simple case of looking up a user by e-mail
ca1eb8
+    """
ca1eb8
+    ent.assert_passwd_by_name("user1.email@LDAP",
ca1eb8
+                              dict(name="user1", uid=1001, gid=2001))
ca1eb8
+
ca1eb8
+
ca1eb8
+def test_conflicting_mail_addresses_and_fqdn(ldap_conn,
ca1eb8
+                                             users_with_email_setup):
ca1eb8
+    """
ca1eb8
+    Test that we handle the case where one user's mail address is the
ca1eb8
+    same as another user's FQDN
ca1eb8
+
ca1eb8
+    This is a regression test for https://pagure.io/SSSD/sssd/issue/3607
ca1eb8
+    """
ca1eb8
+    # With #3607 unfixed, these two lookups would prime the cache with
ca1eb8
+    # nameAlias: emailuser@LDAP for both entries..
ca1eb8
+    ent.assert_passwd_by_name("emailuser@LDAP",
ca1eb8
+                              dict(name="emailuser", uid=1002, gid=2002))
ca1eb8
+    ent.assert_passwd_by_name("emailuser2@LDAP",
ca1eb8
+                              dict(name="emailuser2", uid=1003, gid=2003))
ca1eb8
+
ca1eb8
+    # ..and subsequently, emailuser would not be returned because the cache
ca1eb8
+    # lookup would have had returned two entries which is an error
ca1eb8
+    ent.assert_passwd_by_name("emailuser@LDAP",
ca1eb8
+                              dict(name="emailuser", uid=1002, gid=2002))
ca1eb8
+    ent.assert_passwd_by_name("emailuser2@LDAP",
ca1eb8
+                              dict(name="emailuser2", uid=1003, gid=2003))
ca1eb8
+
ca1eb8
+
ca1eb8
+def test_conflicting_mail_addresses(ldap_conn,
ca1eb8
+                                    users_with_email_setup):
ca1eb8
+    """
ca1eb8
+    Negative test: looking up a user by e-mail which belongs to more than
ca1eb8
+    one account fails in the back end.
ca1eb8
+    """
ca1eb8
+    with pytest.raises(KeyError):
ca1eb8
+        pwd.getpwnam("userxy@LDAP")
ca1eb8
+
ca1eb8
+    # However resolving the users on their own must work
ca1eb8
+    ent.assert_passwd_by_name("userx", dict(name="userx", uid=1004, gid=2004))
ca1eb8
+    ent.assert_passwd_by_name("usery", dict(name="usery", uid=1005, gid=2005))
ca1eb8
-- 
ca1eb8
2.17.1
ca1eb8