Skip to content

Commit 09104ab

Browse files
iboukrissimo5
authored andcommitted
Add test for basic auth with two different users over the same connection
Make sure each request is authenticated according to given credentials even when GssapiConnectionBound is set. Reviewed-by: Simo Sorce <simo@redhat.com>
1 parent c8ac2a4 commit 09104ab

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

tests/httpd.conf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ LoadModule unixd_module modules/mod_unixd.so
6262
LoadModule userdir_module modules/mod_userdir.so
6363
LoadModule version_module modules/mod_version.so
6464
LoadModule vhost_alias_module modules/mod_vhost_alias.so
65-
6665
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
6766

6867
LoadModule auth_gssapi_module mod_auth_gssapi.so
6968

7069

7170
<Directory />
71+
Options +Includes
72+
AddOutputFilter INCLUDES .html
7273
AllowOverride none
7374
Require all denied
7475
</Directory>
@@ -117,6 +118,7 @@ IncludeOptional conf.d/*.conf
117118

118119
CoreDumpDirectory /tmp
119120

121+
120122
<Location /spnego>
121123
AuthType GSSAPI
122124
AuthName "Login"
@@ -133,6 +135,8 @@ CoreDumpDirectory /tmp
133135
</Location>
134136

135137
<Location /basic_auth_krb5>
138+
Options +Includes
139+
AddOutputFilter INCLUDES .html
136140
AuthType GSSAPI
137141
AuthName "Password Login"
138142
GssapiSSLonly Off
@@ -141,6 +145,7 @@ CoreDumpDirectory /tmp
141145
GssapiCredStore keytab:${HTTPROOT}/http.keytab
142146
GssapiBasicAuth On
143147
GssapiBasicAuthMech krb5
148+
GssapiConnectionBound On
144149
Require valid-user
145150
</Location>
146151

tests/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
WORKS
1+
<!--#echo var="GSS_NAME" -->

tests/magtests.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def setup_wrappers(base):
7373
}
7474
7575
[domain_realm]
76-
.mag.dev = MAG.DEV
77-
mag.dev = MAG.DEV
76+
.mag.dev = ${TESTREALM}
77+
mag.dev = ${TESTREALM}
7878
7979
[dbmodules]
8080
${TESTREALM} = {
@@ -167,6 +167,8 @@ def kadmin_local(cmd, env, logfile):
167167

168168
USR_NAME = "maguser"
169169
USR_PWD = "magpwd"
170+
USR_NAME_2 = "maguser2"
171+
USR_PWD_2 = "magpwd2"
170172
SVC_KTNAME = "httpd/http.keytab"
171173
KEY_TYPE = "aes256-cts-hmac-sha1-96:normal"
172174

@@ -188,6 +190,10 @@ def setup_keys(tesdir, env):
188190
with (open(testlog, 'a')) as logfile:
189191
kadmin_local(cmd, env, logfile)
190192

193+
cmd = "addprinc -pw %s -e %s %s" % (USR_PWD_2, KEY_TYPE, USR_NAME_2)
194+
with (open(testlog, 'a')) as logfile:
195+
kadmin_local(cmd, env, logfile)
196+
191197
keys_env = { "KRB5_KTNAME": svc_keytab }
192198
keys_env.update(env)
193199

@@ -280,6 +286,16 @@ def test_basic_auth_krb5(testdir, testenv, testlog):
280286
else:
281287
sys.stderr.write('BASIC-AUTH: SUCCESS\n')
282288

289+
with (open(testlog, 'a')) as logfile:
290+
basick5 = subprocess.Popen(["tests/t_basic_k5_two_users.py"],
291+
stdout=logfile, stderr=logfile,
292+
env=testenv, preexec_fn=os.setsid)
293+
basick5.wait()
294+
if basick5.returncode != 0:
295+
sys.stderr.write('BASIC-AUTH Two Users: FAILED\n')
296+
else:
297+
sys.stderr.write('BASIC-AUTH Two Users: SUCCESS\n')
298+
283299

284300
if __name__ == '__main__':
285301

@@ -310,7 +326,9 @@ def test_basic_auth_krb5(testdir, testenv, testlog):
310326

311327

312328
testenv = {'MAG_USER_NAME': USR_NAME,
313-
'MAG_USER_PASSWORD': USR_PWD}
329+
'MAG_USER_PASSWORD': USR_PWD,
330+
'MAG_USER_NAME_2': USR_NAME_2,
331+
'MAG_USER_PASSWORD_2': USR_PWD_2}
314332
testenv.update(kdcenv)
315333
test_basic_auth_krb5(testdir, testenv, testlog)
316334

tests/t_basic_k5_two_users.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
s = requests.Session()
11+
12+
url = 'http://%s:%s@%s/basic_auth_krb5/' % (os.environ['MAG_USER_NAME'],
13+
os.environ['MAG_USER_PASSWORD'],
14+
os.environ['NSS_WRAPPER_HOSTNAME'])
15+
r = s.get(url)
16+
if r.status_code != 200:
17+
raise ValueError('Basic Auth Failed')
18+
19+
url = 'http://%s:%s@%s/basic_auth_krb5/' % (os.environ['MAG_USER_NAME_2'],
20+
os.environ['MAG_USER_PASSWORD_2'],
21+
os.environ['NSS_WRAPPER_HOSTNAME'])
22+
r2 = s.get(url)
23+
if r2.status_code != 200:
24+
raise ValueError('Basic Auth failed')
25+
26+
if r.text == r2.text:
27+
raise ValueError('Basic Auth fatal error')

0 commit comments

Comments
 (0)