Skip to content

Commit 731761e

Browse files
stanislavlevinsimo5
authored andcommitted
tests: Don't override the specific environment by the global one
This changes the way in which a test environment is prepared. Before: specific -> global After: global -> specific In particular, this allows setting PATH env variable differed from the global configuration. Fixes: #226 Signed-off-by: Stanislav Levin <slev@altlinux.org>
1 parent 70c90bf commit 731761e

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

tests/magtests.py

+48-30
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,13 @@ def setup_kdc(testdir, wrapenv):
320320
with open(kdcconf, 'w+') as f:
321321
f.write(text)
322322

323-
kdcenv = {'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
324-
'KRB5_CONFIG': krb5conf,
325-
'KRB5_KDC_PROFILE': kdcconf,
326-
'KRB5_TRACE': os.path.join(testdir, 'krbtrace.log')}
327-
kdcenv.update(wrapenv)
323+
kdcenv = wrapenv.copy()
324+
kdcenv.update({
325+
'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
326+
'KRB5_CONFIG': krb5conf,
327+
'KRB5_KDC_PROFILE': kdcconf,
328+
'KRB5_TRACE': os.path.join(testdir, 'krbtrace.log'),
329+
})
328330

329331
logfile = open(testlog, 'a')
330332
ksetup = subprocess.Popen(["kdb5_util", "create", "-W", "-s",
@@ -393,8 +395,10 @@ def setup_keys(tesdir, env):
393395
cmd = "addprinc -nokey -e %s %s" % (KEY_TYPE, USR_NAME_3)
394396
kadmin_local(cmd, env, logfile)
395397

396-
keys_env = {"KRB5_KTNAME": svc_keytab, }
397-
keys_env.update(env)
398+
keys_env = env.copy()
399+
keys_env.update({
400+
"KRB5_KTNAME": svc_keytab,
401+
})
398402
return keys_env
399403

400404

@@ -431,10 +435,12 @@ def setup_http(testdir, so_dir, wrapenv):
431435

432436
shutil.copy('tests/401.html', os.path.join(httpdir, 'html'))
433437

434-
httpenv = {'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
435-
'MALLOC_CHECK_': '3',
436-
'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1)}
437-
httpenv.update(wrapenv)
438+
httpenv = wrapenv.copy()
439+
httpenv.update({
440+
'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
441+
'MALLOC_CHECK_': '3',
442+
'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1),
443+
})
438444

439445
httpd = "httpd" if distro == "Fedora" else "apache2"
440446
httpproc = subprocess.Popen([httpd, '-DFOREGROUND', '-f', config],
@@ -445,8 +451,10 @@ def setup_http(testdir, so_dir, wrapenv):
445451
def kinit_user(testdir, kdcenv):
446452
testlog = os.path.join(testdir, 'kinit.log')
447453
ccache = os.path.join(testdir, 'k5ccache')
448-
testenv = {'KRB5CCNAME': ccache}
449-
testenv.update(kdcenv)
454+
testenv = kdcenv.copy()
455+
testenv.update({
456+
'KRB5CCNAME': ccache,
457+
})
450458

451459
with (open(testlog, 'a')) as logfile:
452460
kinit = subprocess.Popen(["kinit", USR_NAME],
@@ -467,8 +475,10 @@ def kinit_certuser(testdir, kdcenv):
467475
pkinit_user_cert = os.path.join(testdir, PKINIT_USER_CERT)
468476
pkinit_key = os.path.join(testdir, PKINIT_KEY)
469477
ident = "X509_user_identity=FILE:" + pkinit_user_cert + "," + pkinit_key
470-
testenv = {'KRB5CCNAME': ccache}
471-
testenv.update(kdcenv)
478+
testenv = kdcenv.copy()
479+
testenv.update({
480+
'KRB5CCNAME': ccache,
481+
})
472482
with (open(testlog, 'a')) as logfile:
473483
logfile.write('PKINIT for maguser3\n')
474484
kinit = subprocess.Popen(["kinit", USR_NAME_3, "-X", ident],
@@ -754,17 +764,21 @@ def faketime_setup(testenv):
754764
raise NotImplementedError
755765

756766
# spedup x100
757-
fakeenv = {'FAKETIME': '+0 x100'}
758-
fakeenv.update(testenv)
759-
fakeenv['LD_PRELOAD'] = ' '.join((testenv['LD_PRELOAD'], libfaketime))
767+
fakeenv = testenv.copy()
768+
fakeenv.update({
769+
'FAKETIME': '+0 x100',
770+
'LD_PRELOAD': ' '.join((testenv['LD_PRELOAD'], libfaketime)),
771+
})
760772
return fakeenv
761773

762774

763775
def http_restart(testdir, so_dir, testenv):
764-
httpenv = {'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{testenv["PATH"]}',
765-
'MALLOC_CHECK_': '3',
766-
'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1)}
767-
httpenv.update(testenv)
776+
httpenv = testenv.copy()
777+
httpenv.update({
778+
'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{testenv["PATH"]}',
779+
'MALLOC_CHECK_': '3',
780+
'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1),
781+
})
768782

769783
httpd = "httpd" if os.path.exists("/etc/httpd/modules") else "apache2"
770784
config = os.path.join(testdir, 'httpd', 'httpd.conf')
@@ -844,11 +858,13 @@ def test_mech_name(testdir, testenv, logfile):
844858
sys.stderr.write("krb5 PKINIT module not found, skipping name "
845859
"attribute tests\n")
846860

847-
testenv = {'MAG_USER_NAME': USR_NAME,
848-
'MAG_USER_PASSWORD': USR_PWD,
849-
'MAG_USER_NAME_2': USR_NAME_2,
850-
'MAG_USER_PASSWORD_2': USR_PWD_2}
851-
testenv.update(kdcenv)
861+
testenv = kdcenv.copy()
862+
testenv.update({
863+
'MAG_USER_NAME': USR_NAME,
864+
'MAG_USER_PASSWORD': USR_PWD,
865+
'MAG_USER_NAME_2': USR_NAME_2,
866+
'MAG_USER_PASSWORD_2': USR_PWD_2,
867+
})
852868

853869
errs += test_basic_auth_krb5(testdir, testenv, logfile)
854870

@@ -859,9 +875,11 @@ def test_mech_name(testdir, testenv, logfile):
859875
# After this point we need to speed up httpd to test creds timeout
860876
try:
861877
fakeenv = faketime_setup(kdcenv)
862-
timeenv = {'TIMEOUT_USER': USR_NAME_4,
863-
'MAG_USER_PASSWORD': USR_PWD}
864-
timeenv.update(fakeenv)
878+
timeenv = fakeenv.copy()
879+
timeenv.update({
880+
'TIMEOUT_USER': USR_NAME_4,
881+
'MAG_USER_PASSWORD': USR_PWD,
882+
})
865883
curporc = httpproc
866884
pid = processes['HTTPD(%d)' % httpproc.pid].pid
867885
os.killpg(pid, signal.SIGTERM)

0 commit comments

Comments
 (0)