From 09104abbab05f92bf1f489fb8e4ee5ab3c2bec1a Mon Sep 17 00:00:00 2001 From: Isaac Boukris Date: Mon, 27 Jul 2015 01:26:41 +0300 Subject: [PATCH] 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 --- tests/httpd.conf | 7 ++++++- tests/index.html | 2 +- tests/magtests.py | 24 +++++++++++++++++++++--- tests/t_basic_k5_two_users.py | 27 +++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100755 tests/t_basic_k5_two_users.py diff --git a/tests/httpd.conf b/tests/httpd.conf index 77701f9..18ba14b 100644 --- a/tests/httpd.conf +++ b/tests/httpd.conf @@ -62,13 +62,14 @@ LoadModule unixd_module modules/mod_unixd.so LoadModule userdir_module modules/mod_userdir.so LoadModule version_module modules/mod_version.so LoadModule vhost_alias_module modules/mod_vhost_alias.so - LoadModule mpm_prefork_module modules/mod_mpm_prefork.so LoadModule auth_gssapi_module mod_auth_gssapi.so + Options +Includes + AddOutputFilter INCLUDES .html AllowOverride none Require all denied @@ -117,6 +118,7 @@ IncludeOptional conf.d/*.conf CoreDumpDirectory /tmp + AuthType GSSAPI AuthName "Login" @@ -133,6 +135,8 @@ CoreDumpDirectory /tmp + Options +Includes + AddOutputFilter INCLUDES .html AuthType GSSAPI AuthName "Password Login" GssapiSSLonly Off @@ -141,6 +145,7 @@ CoreDumpDirectory /tmp GssapiCredStore keytab:${HTTPROOT}/http.keytab GssapiBasicAuth On GssapiBasicAuthMech krb5 + GssapiConnectionBound On Require valid-user diff --git a/tests/index.html b/tests/index.html index c5ad10e..9416405 100644 --- a/tests/index.html +++ b/tests/index.html @@ -1 +1 @@ -WORKS + diff --git a/tests/magtests.py b/tests/magtests.py index 27f55f2..e144e83 100755 --- a/tests/magtests.py +++ b/tests/magtests.py @@ -73,8 +73,8 @@ KRB5_CONF_TEMPLATE = ''' } [domain_realm] - .mag.dev = MAG.DEV - mag.dev = MAG.DEV + .mag.dev = ${TESTREALM} + mag.dev = ${TESTREALM} [dbmodules] ${TESTREALM} = { @@ -167,6 +167,8 @@ def kadmin_local(cmd, env, logfile): USR_NAME = "maguser" USR_PWD = "magpwd" +USR_NAME_2 = "maguser2" +USR_PWD_2 = "magpwd2" SVC_KTNAME = "httpd/http.keytab" KEY_TYPE = "aes256-cts-hmac-sha1-96:normal" @@ -188,6 +190,10 @@ def setup_keys(tesdir, env): with (open(testlog, 'a')) as logfile: kadmin_local(cmd, env, logfile) + cmd = "addprinc -pw %s -e %s %s" % (USR_PWD_2, KEY_TYPE, USR_NAME_2) + with (open(testlog, 'a')) as logfile: + kadmin_local(cmd, env, logfile) + keys_env = { "KRB5_KTNAME": svc_keytab } keys_env.update(env) @@ -280,6 +286,16 @@ def test_basic_auth_krb5(testdir, testenv, testlog): else: sys.stderr.write('BASIC-AUTH: SUCCESS\n') + with (open(testlog, 'a')) as logfile: + basick5 = subprocess.Popen(["tests/t_basic_k5_two_users.py"], + stdout=logfile, stderr=logfile, + env=testenv, preexec_fn=os.setsid) + basick5.wait() + if basick5.returncode != 0: + sys.stderr.write('BASIC-AUTH Two Users: FAILED\n') + else: + sys.stderr.write('BASIC-AUTH Two Users: SUCCESS\n') + if __name__ == '__main__': @@ -310,7 +326,9 @@ if __name__ == '__main__': testenv = {'MAG_USER_NAME': USR_NAME, - 'MAG_USER_PASSWORD': USR_PWD} + 'MAG_USER_PASSWORD': USR_PWD, + 'MAG_USER_NAME_2': USR_NAME_2, + 'MAG_USER_PASSWORD_2': USR_PWD_2} testenv.update(kdcenv) test_basic_auth_krb5(testdir, testenv, testlog) diff --git a/tests/t_basic_k5_two_users.py b/tests/t_basic_k5_two_users.py new file mode 100755 index 0000000..0d3d45b --- /dev/null +++ b/tests/t_basic_k5_two_users.py @@ -0,0 +1,27 @@ +#!/usr/bin/python +# Copyright (C) 2015 - mod_auth_gssapi contributors, see COPYING for license. + +import os +import requests +from requests.auth import HTTPBasicAuth + + +if __name__ == '__main__': + s = requests.Session() + + url = 'http://%s:%s@%s/basic_auth_krb5/' % (os.environ['MAG_USER_NAME'], + os.environ['MAG_USER_PASSWORD'], + os.environ['NSS_WRAPPER_HOSTNAME']) + r = s.get(url) + if r.status_code != 200: + raise ValueError('Basic Auth Failed') + + url = 'http://%s:%s@%s/basic_auth_krb5/' % (os.environ['MAG_USER_NAME_2'], + os.environ['MAG_USER_PASSWORD_2'], + os.environ['NSS_WRAPPER_HOSTNAME']) + r2 = s.get(url) + if r2.status_code != 200: + raise ValueError('Basic Auth failed') + + if r.text == r2.text: + raise ValueError('Basic Auth fatal error') -- 2.1.4