Skip to content

Commit 47de8ee

Browse files
committed
Add basic auth test
Signed-off-by: Simo Sorce <simo@redhat.com>
1 parent ecd5b7c commit 47de8ee

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

tests/httpd.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,15 @@ CoreDumpDirectory /tmp
132132
Require valid-user
133133
</Location>
134134

135+
<Location /basic_auth_krb5>
136+
AuthType GSSAPI
137+
AuthName "Password Login"
138+
GssapiSSLonly Off
139+
GssapiCredStore ccache:${HTTPROOT}/tmp/httpd_krb5_ccache
140+
GssapiCredStore client_keytab:${HTTPROOT}/http.keytab
141+
GssapiCredStore keytab:${HTTPROOT}/http.keytab
142+
GssapiBasicAuth On
143+
GssapiBasicAuthMech krb5
144+
Require valid-user
145+
</Location>
146+

tests/magtests.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ def setup_kdc(testdir, wrapenv):
135135

136136
kdcenv = {'PATH': '/sbin:/bin:/usr/sbin:/usr/bin',
137137
'KRB5_CONFIG': krb5conf,
138-
'KRB5_KDC_PROFILE': kdcconf}
138+
'KRB5_KDC_PROFILE': kdcconf,
139+
'KRB5_TRACE': os.path.join(testdir, 'krbtrace.log')}
139140
kdcenv.update(wrapenv)
140141

141142
with (open(testlog, 'a')) as logfile:
@@ -263,6 +264,23 @@ def test_spnego_auth(testdir, testenv, testlog):
263264
sys.stderr.write('SPNEGO: SUCCESS\n')
264265

265266

267+
def test_basic_auth_krb5(testdir, testenv, testlog):
268+
269+
basicdir = os.path.join(testdir, 'httpd', 'html', 'basic_auth_krb5')
270+
os.mkdir(basicdir)
271+
shutil.copy('tests/index.html', basicdir)
272+
273+
with (open(testlog, 'a')) as logfile:
274+
basick5 = subprocess.Popen(["tests/t_basic_k5.py"],
275+
stdout=logfile, stderr=logfile,
276+
env=testenv, preexec_fn=os.setsid)
277+
basick5.wait()
278+
if basick5.returncode != 0:
279+
sys.stderr.write('BASIC-AUTH: FAILED\n')
280+
else:
281+
sys.stderr.write('BASIC-AUTH: SUCCESS\n')
282+
283+
266284
if __name__ == '__main__':
267285

268286
args = parse_args()
@@ -282,14 +300,20 @@ def test_spnego_auth(testdir, testenv, testlog):
282300
kdcproc, kdcenv = setup_kdc(testdir, wrapenv)
283301
processes['KDC(%d)' % kdcproc.pid] = kdcproc
284302

285-
httpproc = setup_http(testdir, wrapenv)
303+
httpproc = setup_http(testdir, kdcenv)
286304
processes['HTTPD(%d)' % httpproc.pid] = httpproc
287305

288306
keysenv = setup_keys(testdir, kdcenv)
289307
testenv = kinit_user(testdir, kdcenv)
290308

291309
test_spnego_auth(testdir, testenv, testlog)
292310

311+
312+
testenv = {'MAG_USER_NAME': USR_NAME,
313+
'MAG_USER_PASSWORD': USR_PWD}
314+
testenv.update(kdcenv)
315+
test_basic_auth_krb5(testdir, testenv, testlog)
316+
293317
finally:
294318
with (open(testlog, 'a')) as logfile:
295319
for name in processes:

tests/t_basic_k5.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/python
2+
# Copyright (C) 2015 - mod_auth_gssapi contributors, see COPYING for license.
3+
4+
import os
5+
import requests
6+
from requests.auth import HTTPBasicAuth
7+
8+
9+
if __name__ == '__main__':
10+
url = 'http://%s/basic_auth_krb5/' % os.environ['NSS_WRAPPER_HOSTNAME']
11+
r = requests.get(url, auth=HTTPBasicAuth(os.environ['MAG_USER_NAME'],
12+
os.environ['MAG_USER_PASSWORD']))
13+
if r.status_code != 200:
14+
raise ValueError('Basic Auth Failed')

0 commit comments

Comments
 (0)