Blame SOURCES/tests-Don-t-override-the-specific-environment-by-the.patch

8f2224
From bd2f8d20c589feae7249ccca28199d826d007667 Mon Sep 17 00:00:00 2001
8f2224
From: Stanislav Levin <slev@altlinux.org>
8f2224
Date: Thu, 6 Aug 2020 13:55:45 +0300
8f2224
Subject: [PATCH] tests: Don't override the specific environment by the global
8f2224
 one
8f2224
8f2224
This changes the way in which a test environment is prepared.
8f2224
8f2224
Before:
8f2224
specific -> global
8f2224
8f2224
After:
8f2224
global -> specific
8f2224
8f2224
In particular, this allows setting PATH env variable differed from
8f2224
the global configuration.
8f2224
8f2224
Fixes: https://github.com/gssapi/mod_auth_gssapi/issues/226
8f2224
Signed-off-by: Stanislav Levin <slev@altlinux.org>
8f2224
(cherry picked from commit 731761e63d72bf5656f40340daafce4e2d34bd92)
8f2224
---
8f2224
 tests/magtests.py | 78 +++++++++++++++++++++++++++++------------------
8f2224
 1 file changed, 48 insertions(+), 30 deletions(-)
8f2224
8f2224
diff --git a/tests/magtests.py b/tests/magtests.py
8f2224
index 1c0b26a..e04fa65 100755
8f2224
--- a/tests/magtests.py
8f2224
+++ b/tests/magtests.py
8f2224
@@ -310,11 +310,13 @@ def setup_kdc(testdir, wrapenv):
8f2224
     with open(kdcconf, 'w+') as f:
8f2224
         f.write(text)
8f2224
 
8f2224
-    kdcenv = {'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
8f2224
-              'KRB5_CONFIG': krb5conf,
8f2224
-              'KRB5_KDC_PROFILE': kdcconf,
8f2224
-              'KRB5_TRACE': os.path.join(testdir, 'krbtrace.log')}
8f2224
-    kdcenv.update(wrapenv)
8f2224
+    kdcenv = wrapenv.copy()
8f2224
+    kdcenv.update({
8f2224
+        'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
8f2224
+        'KRB5_CONFIG': krb5conf,
8f2224
+        'KRB5_KDC_PROFILE': kdcconf,
8f2224
+        'KRB5_TRACE': os.path.join(testdir, 'krbtrace.log'),
8f2224
+    })
8f2224
 
8f2224
     logfile = open(testlog, 'a')
8f2224
     ksetup = subprocess.Popen(["kdb5_util", "create", "-W", "-s",
8f2224
@@ -383,8 +385,10 @@ def setup_keys(tesdir, env):
8f2224
     cmd = "addprinc -nokey -e %s %s" % (KEY_TYPE, USR_NAME_3)
8f2224
     kadmin_local(cmd, env, logfile)
8f2224
 
8f2224
-    keys_env = {"KRB5_KTNAME": svc_keytab, }
8f2224
-    keys_env.update(env)
8f2224
+    keys_env = env.copy()
8f2224
+    keys_env.update({
8f2224
+        "KRB5_KTNAME": svc_keytab,
8f2224
+    })
8f2224
     return keys_env
8f2224
 
8f2224
 
8f2224
@@ -421,10 +425,12 @@ def setup_http(testdir, so_dir, wrapenv):
8f2224
 
8f2224
     shutil.copy('tests/401.html', os.path.join(httpdir, 'html'))
8f2224
 
8f2224
-    httpenv = {'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
8f2224
-               'MALLOC_CHECK_': '3',
8f2224
-               'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1)}
8f2224
-    httpenv.update(wrapenv)
8f2224
+    httpenv = wrapenv.copy()
8f2224
+    httpenv.update({
8f2224
+        'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
8f2224
+        'MALLOC_CHECK_': '3',
8f2224
+        'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1),
8f2224
+    })
8f2224
 
8f2224
     httpd = "httpd" if distro == "Fedora" else "apache2"
8f2224
     httpproc = subprocess.Popen([httpd, '-DFOREGROUND', '-f', config],
8f2224
@@ -435,8 +441,10 @@ def setup_http(testdir, so_dir, wrapenv):
8f2224
 def kinit_user(testdir, kdcenv):
8f2224
     testlog = os.path.join(testdir, 'kinit.log')
8f2224
     ccache = os.path.join(testdir, 'k5ccache')
8f2224
-    testenv = {'KRB5CCNAME': ccache}
8f2224
-    testenv.update(kdcenv)
8f2224
+    testenv = kdcenv.copy()
8f2224
+    testenv.update({
8f2224
+        'KRB5CCNAME': ccache,
8f2224
+    })
8f2224
 
8f2224
     with (open(testlog, 'a')) as logfile:
8f2224
         kinit = subprocess.Popen(["kinit", USR_NAME],
8f2224
@@ -457,8 +465,10 @@ def kinit_certuser(testdir, kdcenv):
8f2224
     pkinit_user_cert = os.path.join(testdir, PKINIT_USER_CERT)
8f2224
     pkinit_key = os.path.join(testdir, PKINIT_KEY)
8f2224
     ident = "X509_user_identity=FILE:" + pkinit_user_cert + "," + pkinit_key
8f2224
-    testenv = {'KRB5CCNAME': ccache}
8f2224
-    testenv.update(kdcenv)
8f2224
+    testenv = kdcenv.copy()
8f2224
+    testenv.update({
8f2224
+        'KRB5CCNAME': ccache,
8f2224
+    })
8f2224
     with (open(testlog, 'a')) as logfile:
8f2224
         logfile.write('PKINIT for maguser3\n')
8f2224
         kinit = subprocess.Popen(["kinit", USR_NAME_3, "-X", ident],
8f2224
@@ -711,17 +721,21 @@ def faketime_setup(testenv):
8f2224
         raise NotImplementedError
8f2224
 
8f2224
     # spedup x100
8f2224
-    fakeenv = {'FAKETIME': '+0 x100'}
8f2224
-    fakeenv.update(testenv)
8f2224
-    fakeenv['LD_PRELOAD'] = ' '.join((testenv['LD_PRELOAD'], libfaketime))
8f2224
+    fakeenv = testenv.copy()
8f2224
+    fakeenv.update({
8f2224
+        'FAKETIME': '+0 x100',
8f2224
+        'LD_PRELOAD': ' '.join((testenv['LD_PRELOAD'], libfaketime)),
8f2224
+    })
8f2224
     return fakeenv
8f2224
 
8f2224
 
8f2224
 def http_restart(testdir, so_dir, testenv):
8f2224
-    httpenv = {'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{testenv["PATH"]}',
8f2224
-               'MALLOC_CHECK_': '3',
8f2224
-               'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1)}
8f2224
-    httpenv.update(testenv)
8f2224
+    httpenv = testenv.copy()
8f2224
+    httpenv.update({
8f2224
+        'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{testenv["PATH"]}',
8f2224
+        'MALLOC_CHECK_': '3',
8f2224
+        'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1),
8f2224
+    })
8f2224
 
8f2224
     httpd = "httpd" if os.path.exists("/etc/httpd/modules") else "apache2"
8f2224
     config = os.path.join(testdir, 'httpd', 'httpd.conf')
8f2224
@@ -776,11 +790,13 @@ if __name__ == '__main__':
8f2224
             sys.stderr.write("krb5 PKINIT module not found, skipping name "
8f2224
                              "attribute tests\n")
8f2224
 
8f2224
-        testenv = {'MAG_USER_NAME': USR_NAME,
8f2224
-                   'MAG_USER_PASSWORD': USR_PWD,
8f2224
-                   'MAG_USER_NAME_2': USR_NAME_2,
8f2224
-                   'MAG_USER_PASSWORD_2': USR_PWD_2}
8f2224
-        testenv.update(kdcenv)
8f2224
+        testenv = kdcenv.copy()
8f2224
+        testenv.update({
8f2224
+            'MAG_USER_NAME': USR_NAME,
8f2224
+            'MAG_USER_PASSWORD': USR_PWD,
8f2224
+            'MAG_USER_NAME_2': USR_NAME_2,
8f2224
+            'MAG_USER_PASSWORD_2': USR_PWD_2,
8f2224
+        })
8f2224
 
8f2224
         errs += test_basic_auth_krb5(testdir, testenv, logfile)
8f2224
 
8f2224
@@ -789,9 +805,11 @@ if __name__ == '__main__':
8f2224
         # After this point we need to speed up httpd to test creds timeout
8f2224
         try:
8f2224
             fakeenv = faketime_setup(kdcenv)
8f2224
-            timeenv = {'TIMEOUT_USER': USR_NAME_4,
8f2224
-                       'MAG_USER_PASSWORD': USR_PWD}
8f2224
-            timeenv.update(fakeenv)
8f2224
+            timeenv = fakeenv.copy()
8f2224
+            timeenv.update({
8f2224
+                'TIMEOUT_USER': USR_NAME_4,
8f2224
+                'MAG_USER_PASSWORD': USR_PWD,
8f2224
+            })
8f2224
             curporc = httpproc
8f2224
             pid = processes['HTTPD(%d)' % httpproc.pid].pid
8f2224
             os.killpg(pid, signal.SIGTERM)