Skip to content

tests: Don't override the specific environment by the global one #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ elif [ -f /etc/fedora-release ]; then
dnf -y install $COMPILER python3-{gssapi,requests{,-gssapi},flake8} \
krb5-{server,workstation,pkinit} curl libfaketime \
{httpd,krb5,openssl,gssntlmssp}-devel {socket,nss}_wrapper \
autoconf automake libtool which bison make python3 \
autoconf automake libtool which bison make python3 python3-devel \
flex mod_session redhat-rpm-config /usr/bin/virtualenv
else
echo "Distro not found!"
Expand Down
78 changes: 48 additions & 30 deletions tests/magtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,13 @@ def setup_kdc(testdir, wrapenv):
with open(kdcconf, 'w+') as f:
f.write(text)

kdcenv = {'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
'KRB5_CONFIG': krb5conf,
'KRB5_KDC_PROFILE': kdcconf,
'KRB5_TRACE': os.path.join(testdir, 'krbtrace.log')}
kdcenv.update(wrapenv)
kdcenv = wrapenv.copy()
kdcenv.update({
'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
'KRB5_CONFIG': krb5conf,
'KRB5_KDC_PROFILE': kdcconf,
'KRB5_TRACE': os.path.join(testdir, 'krbtrace.log'),
})

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

keys_env = {"KRB5_KTNAME": svc_keytab, }
keys_env.update(env)
keys_env = env.copy()
keys_env.update({
"KRB5_KTNAME": svc_keytab,
})
return keys_env


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

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

httpenv = {'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
'MALLOC_CHECK_': '3',
'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1)}
httpenv.update(wrapenv)
httpenv = wrapenv.copy()
httpenv.update({
'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{wrapenv["PATH"]}',
'MALLOC_CHECK_': '3',
'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1),
})

httpd = "httpd" if distro == "Fedora" else "apache2"
httpproc = subprocess.Popen([httpd, '-DFOREGROUND', '-f', config],
Expand All @@ -445,8 +451,10 @@ def setup_http(testdir, so_dir, wrapenv):
def kinit_user(testdir, kdcenv):
testlog = os.path.join(testdir, 'kinit.log')
ccache = os.path.join(testdir, 'k5ccache')
testenv = {'KRB5CCNAME': ccache}
testenv.update(kdcenv)
testenv = kdcenv.copy()
testenv.update({
'KRB5CCNAME': ccache,
})

with (open(testlog, 'a')) as logfile:
kinit = subprocess.Popen(["kinit", USR_NAME],
Expand All @@ -467,8 +475,10 @@ def kinit_certuser(testdir, kdcenv):
pkinit_user_cert = os.path.join(testdir, PKINIT_USER_CERT)
pkinit_key = os.path.join(testdir, PKINIT_KEY)
ident = "X509_user_identity=FILE:" + pkinit_user_cert + "," + pkinit_key
testenv = {'KRB5CCNAME': ccache}
testenv.update(kdcenv)
testenv = kdcenv.copy()
testenv.update({
'KRB5CCNAME': ccache,
})
with (open(testlog, 'a')) as logfile:
logfile.write('PKINIT for maguser3\n')
kinit = subprocess.Popen(["kinit", USR_NAME_3, "-X", ident],
Expand Down Expand Up @@ -754,17 +764,21 @@ def faketime_setup(testenv):
raise NotImplementedError

# spedup x100
fakeenv = {'FAKETIME': '+0 x100'}
fakeenv.update(testenv)
fakeenv['LD_PRELOAD'] = ' '.join((testenv['LD_PRELOAD'], libfaketime))
fakeenv = testenv.copy()
fakeenv.update({
'FAKETIME': '+0 x100',
'LD_PRELOAD': ' '.join((testenv['LD_PRELOAD'], libfaketime)),
})
return fakeenv


def http_restart(testdir, so_dir, testenv):
httpenv = {'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{testenv["PATH"]}',
'MALLOC_CHECK_': '3',
'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1)}
httpenv.update(testenv)
httpenv = testenv.copy()
httpenv.update({
'PATH': f'/sbin:/bin:/usr/sbin:/usr/bin:{testenv["PATH"]}',
'MALLOC_CHECK_': '3',
'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1),
})

httpd = "httpd" if os.path.exists("/etc/httpd/modules") else "apache2"
config = os.path.join(testdir, 'httpd', 'httpd.conf')
Expand Down Expand Up @@ -838,11 +852,13 @@ def test_mech_name(testdir, testenv, logfile):
sys.stderr.write("krb5 PKINIT module not found, skipping name "
"attribute tests\n")

testenv = {'MAG_USER_NAME': USR_NAME,
'MAG_USER_PASSWORD': USR_PWD,
'MAG_USER_NAME_2': USR_NAME_2,
'MAG_USER_PASSWORD_2': USR_PWD_2}
testenv.update(kdcenv)
testenv = kdcenv.copy()
testenv.update({
'MAG_USER_NAME': USR_NAME,
'MAG_USER_PASSWORD': USR_PWD,
'MAG_USER_NAME_2': USR_NAME_2,
'MAG_USER_PASSWORD_2': USR_PWD_2,
})

errs += test_basic_auth_krb5(testdir, testenv, logfile)

Expand All @@ -853,9 +869,11 @@ def test_mech_name(testdir, testenv, logfile):
# After this point we need to speed up httpd to test creds timeout
try:
fakeenv = faketime_setup(kdcenv)
timeenv = {'TIMEOUT_USER': USR_NAME_4,
'MAG_USER_PASSWORD': USR_PWD}
timeenv.update(fakeenv)
timeenv = fakeenv.copy()
timeenv.update({
'TIMEOUT_USER': USR_NAME_4,
'MAG_USER_PASSWORD': USR_PWD,
})
curporc = httpproc
pid = processes['HTTPD(%d)' % httpproc.pid].pid
os.killpg(pid, signal.SIGTERM)
Expand Down