Blame SOURCES/0117-TESTS-Add-a-regression-test-for-SIGHUP-handling-in-s.patch

96eb28
From 103a22b85df5c371aefb08e476a3ab950e6882a3 Mon Sep 17 00:00:00 2001
96eb28
From: Jakub Hrozek <jhrozek@redhat.com>
96eb28
Date: Tue, 19 Jun 2018 11:39:02 +0200
96eb28
Subject: [PATCH] TESTS: Add a regression test for SIGHUP handling in
96eb28
 sss_ssh_authorizedkeys
96eb28
MIME-Version: 1.0
96eb28
Content-Type: text/plain; charset=UTF-8
96eb28
Content-Transfer-Encoding: 8bit
96eb28
96eb28
A regression test for:
96eb28
https://pagure.io/SSSD/sssd/issue/3747
96eb28
96eb28
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
96eb28
(cherry picked from commit 4cc3c1a1b1070c12bcc4351880d8207e47b37496)
96eb28
---
96eb28
 src/tests/intg/test_ssh_pubkey.py | 58 +++++++++++++++++++++++++++++++++++++++
96eb28
 1 file changed, 58 insertions(+)
96eb28
96eb28
diff --git a/src/tests/intg/test_ssh_pubkey.py b/src/tests/intg/test_ssh_pubkey.py
96eb28
index fbf55566e341373873057ec4e3af1d7f83202aa7..8fb41c62d87ec210c9aad8582023fe1cb00f2b4e 100644
96eb28
--- a/src/tests/intg/test_ssh_pubkey.py
96eb28
+++ b/src/tests/intg/test_ssh_pubkey.py
96eb28
@@ -24,6 +24,8 @@ import time
96eb28
 import ldap
96eb28
 import ldap.modlist
96eb28
 import pytest
96eb28
+import string
96eb28
+import random
96eb28
 
96eb28
 import config
96eb28
 import ds_openldap
96eb28
@@ -230,3 +232,59 @@ def test_ssh_pubkey_retrieve(add_user_with_ssh_key):
96eb28
 
96eb28
     sshpubkey = get_call_output(["sss_ssh_authorizedkeys", "user2"])
96eb28
     assert len(sshpubkey) == 0
96eb28
+
96eb28
+
96eb28
+@pytest.fixture()
96eb28
+def sighup_client(request):
96eb28
+    test_ssh_cli_path = os.path.join(config.ABS_BUILDDIR,
96eb28
+                                     "..", "..", "..", "test_ssh_client")
96eb28
+    assert os.access(test_ssh_cli_path, os.X_OK)
96eb28
+    return test_ssh_cli_path
96eb28
+
96eb28
+
96eb28
+@pytest.fixture
96eb28
+def add_user_with_many_keys(request, ldap_conn):
96eb28
+    # Generate a large list of unique ssh pubkeys
96eb28
+    pubkey_list = []
96eb28
+    while len(pubkey_list) < 50:
96eb28
+        new_pubkey = list(USER1_PUBKEY1)
96eb28
+        new_pubkey[10] = random.choice(string.ascii_uppercase)
96eb28
+        new_pubkey[11] = random.choice(string.ascii_uppercase)
96eb28
+        new_pubkey[12] = random.choice(string.ascii_uppercase)
96eb28
+        str_new_pubkey = ''.join(c for c in new_pubkey)
96eb28
+        if str_new_pubkey in pubkey_list:
96eb28
+            continue
96eb28
+        pubkey_list.append(str_new_pubkey)
96eb28
+
96eb28
+    ent_list = ldap_ent.List(ldap_conn.ds_inst.base_dn)
96eb28
+    ent_list.add_user("user1", 1001, 2001, sshPubKey=pubkey_list)
96eb28
+    create_ldap_fixture(request, ldap_conn, ent_list)
96eb28
+
96eb28
+    conf = format_basic_conf(ldap_conn, SCHEMA_RFC2307_BIS)
96eb28
+    create_conf_fixture(request, conf)
96eb28
+    create_sssd_fixture(request)
96eb28
+    return None
96eb28
+
96eb28
+
96eb28
+def test_ssh_sighup(add_user_with_many_keys, sighup_client):
96eb28
+    """
96eb28
+    A regression test for https://pagure.io/SSSD/sssd/issue/3747
96eb28
+
96eb28
+    OpenSSH can close its end of the pipe towards sss_ssh_authorizedkeys
96eb28
+    before all of the output is read. In that case, older versions
96eb28
+    of sss_ssh_authorizedkeys were receiving a SIGPIPE
96eb28
+    """
96eb28
+    cli_path = sighup_client
96eb28
+
96eb28
+    # python actually does the sensible, but unexpected (for a C programmer)
96eb28
+    # thing and handles SIGPIPE. In order to reproduce the bug, we need
96eb28
+    # to unset the SIGPIPE handler
96eb28
+    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
96eb28
+
96eb28
+    process = subprocess.Popen([cli_path, "user1"],
96eb28
+                               stdout=subprocess.PIPE,
96eb28
+                               stderr=subprocess.PIPE)
96eb28
+    _, _ = process.communicate()
96eb28
+    # If the test tool detects that sss_ssh_authorizedkeys was killed with a
96eb28
+    # signal, it would have returned 1
96eb28
+    assert process.returncode == 0
96eb28
-- 
96eb28
2.14.4
96eb28