Skip to content

Commit a3009f0

Browse files
committed
Add test for Basic Proxy authentication
1 parent 1ce265f commit a3009f0

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

tests/httpd.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
ServerRoot "${HTTPROOT}"
22
ServerName "${HTTPNAME}"
33
Listen ${HTTPADDR}:${HTTPPORT}
4+
Listen ${HTTPADDR}:${PROXYPORT}
45

56
LoadModule access_compat_module modules/mod_access_compat.so
67
LoadModule actions_module modules/mod_actions.so
@@ -63,6 +64,8 @@ LoadModule userdir_module modules/mod_userdir.so
6364
LoadModule version_module modules/mod_version.so
6465
LoadModule vhost_alias_module modules/mod_vhost_alias.so
6566
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
67+
LoadModule proxy_module modules/mod_proxy.so
68+
LoadModule proxy_http_module modules/mod_proxy_http.so
6669

6770
LoadModule auth_gssapi_module mod_auth_gssapi.so
6871

@@ -149,3 +152,17 @@ CoreDumpDirectory /tmp
149152
Require valid-user
150153
</Location>
151154

155+
<VirtualHost *:${PROXYPORT}>
156+
ProxyRequests On
157+
ProxyVia On
158+
159+
<Proxy *>
160+
AuthType GSSAPI
161+
AuthName "Proxy Login"
162+
GssapiCredStore ccache:${HTTPROOT}/tmp/httpd_krb5_ccache
163+
GssapiCredStore client_keytab:${HTTPROOT}/http.keytab
164+
GssapiCredStore keytab:${HTTPROOT}/http.keytab
165+
GssapiBasicAuth On
166+
Require valid-user
167+
</Proxy>
168+
</VirtualHost>

tests/magtests.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def parse_args():
2323

2424
WRAP_HOSTNAME = "kdc.mag.dev"
2525
WRAP_IPADDR = '127.0.0.9'
26+
WRAP_HTTP_PORT = '80'
27+
WRAP_PROXY_PORT = '8080'
2628

2729
def setup_wrappers(base):
2830

@@ -47,6 +49,7 @@ def setup_wrappers(base):
4749
wenv = {'LD_PRELOAD': 'libsocket_wrapper.so libnss_wrapper.so',
4850
'SOCKET_WRAPPER_DIR': wrapdir,
4951
'SOCKET_WRAPPER_DEFAULT_IFACE': '9',
52+
'WRAP_PROXY_PORT': WRAP_PROXY_PORT,
5053
'NSS_WRAPPER_HOSTNAME': WRAP_HOSTNAME,
5154
'NSS_WRAPPER_HOSTS': hosts_file}
5255

@@ -218,7 +221,8 @@ def setup_http(testdir, wrapenv):
218221
text = t.substitute({'HTTPROOT': httpdir,
219222
'HTTPNAME': WRAP_HOSTNAME,
220223
'HTTPADDR': WRAP_IPADDR,
221-
'HTTPPORT': '80'})
224+
'PROXYPORT': WRAP_PROXY_PORT,
225+
'HTTPPORT': WRAP_HTTP_PORT})
222226
config = os.path.join(httpdir, 'httpd.conf')
223227
with open(config, 'w+') as f:
224228
f.write(text)
@@ -296,6 +300,16 @@ def test_basic_auth_krb5(testdir, testenv, testlog):
296300
else:
297301
sys.stderr.write('BASIC-AUTH Two Users: SUCCESS\n')
298302

303+
with (open(testlog, 'a')) as logfile:
304+
basick5 = subprocess.Popen(["tests/t_basic_proxy.py"],
305+
stdout=logfile, stderr=logfile,
306+
env=testenv, preexec_fn=os.setsid)
307+
basick5.wait()
308+
if basick5.returncode != 0:
309+
sys.stderr.write('BASIC Proxy Auth: FAILED\n')
310+
else:
311+
sys.stderr.write('BASIC Proxy Auth: SUCCESS\n')
312+
299313

300314
if __name__ == '__main__':
301315

tests/t_basic_proxy.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
proxy = 'http://%s:%s@%s:%s' % (os.environ['MAG_USER_NAME'],
11+
os.environ['MAG_USER_PASSWORD'],
12+
os.environ['NSS_WRAPPER_HOSTNAME'],
13+
os.environ['WRAP_PROXY_PORT'])
14+
proxies = { "http": proxy, }
15+
url = 'http://%s/basic_auth_krb5/' % os.environ['NSS_WRAPPER_HOSTNAME']
16+
r = requests.get(url, proxies=proxies,
17+
auth=HTTPBasicAuth(os.environ['MAG_USER_NAME_2'],
18+
os.environ['MAG_USER_PASSWORD_2']))
19+
if r.status_code != 200:
20+
raise ValueError('Basic Proxy Auth Failed')

0 commit comments

Comments
 (0)