>From 2c13856c9f650503b8eeb2d4446469548728804b Mon Sep 17 00:00:00 2001
From: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Date: Mon, 12 Oct 2015 16:17:46 +0300
Subject: [PATCH 3/3] intg: Add a memcache invalidation failure test

Add a memcache invalidation failure integration test. It fails as is,
and passes if ldap_enumeration_refresh_timeout in the first half is set
to e.g. 30. The sss_nss_check_header function was observed to always
return 0 for the second half of the test, when it was failing.
---
 src/tests/intg/ldap_test.py | 98 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)

diff --git a/src/tests/intg/ldap_test.py b/src/tests/intg/ldap_test.py
index cca9431..cdd8c8d 100644
--- a/src/tests/intg/ldap_test.py
+++ b/src/tests/intg/ldap_test.py
@@ -474,6 +474,99 @@ def test_add_remove_user(ldap_conn, blank_rfc2307):
     ent.assert_passwd(ent.contains_only())
 
 
+def test_add_remove_user_memcache_mix(ldap_conn,
+                                      void_conf,
+                                      void_sssd,
+                                      void_ldap):
+    # Setup
+    conf = unindent("""\
+            [sssd]
+            debug_level         = 0xffff
+            domains             = LDAP
+            services            = nss, pam
+
+            [nss]
+            memcache_timeout    = 0
+
+            [pam]
+
+            [domain/LDAP]
+            ldap_auth_disable_tls_never_use_in_production = true
+            debug_level         = 0xffff
+            ldap_schema         = rfc2307
+            enumerate           = true
+            id_provider         = ldap
+            auth_provider       = ldap
+            ldap_uri            = {ldap_conn.ds_inst.ldap_url}
+            ldap_search_base    = {ldap_conn.ds_inst.base_dn}
+
+            ldap_enumeration_refresh_timeout    = 4
+            ldap_purge_cache_timeout            = 1
+            entry_cache_timeout                 = 4
+    """).format(**locals())
+    create_conf_file(conf)
+    create_sssd_process()
+    e = ldap_ent.user(ldap_conn.ds_inst.base_dn, "user", 1001, 2001)
+    time.sleep(2)
+    # Add the user
+    ldap_conn.add_s(*e)
+    time.sleep(4)
+    pwd.getpwnam("user")
+    # Remove the user
+    ldap_conn.delete_s(e[0])
+    time.sleep(4)
+    # Teardown
+    cleanup_sssd_process()
+    cleanup_conf_file()
+    cleanup_ldap_entries(ldap_conn)
+
+    # Setup
+    e = ldap_ent.user(ldap_conn.ds_inst.base_dn, "user", 1001, 2001)
+    ldap_conn.add_s(*e)
+    conf = unindent("""\
+        [sssd]
+        domains             = LDAP
+        services            = nss
+
+        [nss]
+        debug_level         = 0xffff
+
+        [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_file(conf)
+    create_sssd_process()
+    # Check user presence
+    ent.assert_passwd_by_name(
+        'user',
+        dict(name='user', passwd='*', uid=1001, gid=2001,
+             gecos='1001', shell='/bin/bash'))
+    # Stop sssd
+    pid_file = open(config.PIDFILE_PATH, "r")
+    pid = int(pid_file.read())
+    os.kill(pid, signal.SIGTERM)
+    while True:
+        try:
+            os.kill(pid, signal.SIGCONT)
+        except:
+            break
+        time.sleep(1)
+    # Check user presence
+    ent.assert_passwd_by_name(
+        'user',
+        dict(name='user', passwd='*', uid=1001, gid=2001,
+             gecos='1001', shell='/bin/bash'))
+    # Teardown
+    cleanup_conf_file()
+    cleanup_ldap_entries(ldap_conn)
+
+
 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)
@@ -566,6 +659,11 @@ def test_add_remove_membership_rfc2307_bis(ldap_conn,
 
 
 @pytest.fixture
+def void_ldap(request, ldap_conn):
+    create_ldap_cleanup(request, ldap_conn)
+
+
+@pytest.fixture
 def void_conf(request):
     create_conf_cleanup(request)
 
-- 
2.6.1

