Skip to content

Commit 5e72093

Browse files
iboukrissimo5
authored andcommitted
Add test for Proxy SPNEGO auth
Add appropairate authorization headers to test with SPNEGO too as discussed in #48 Requires recent version of python-gssapi module, see: pythongssapi/python-gssapi#74 Simo: Squashed original patches in one, removed trailing whitespaces and reworded the commit message. Reviewed-by: Simo Sorce <simo@redhat.com> Closes #49
1 parent 7aed3f2 commit 5e72093

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/magtests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ def test_spnego_auth(testdir, testenv, testlog):
273273
else:
274274
sys.stderr.write('SPNEGO: SUCCESS\n')
275275

276+
with (open(testlog, 'a')) as logfile:
277+
spnego = subprocess.Popen(["tests/t_spnego_proxy.py"],
278+
stdout=logfile, stderr=logfile,
279+
env=testenv, preexec_fn=os.setsid)
280+
spnego.wait()
281+
if spnego.returncode != 0:
282+
sys.stderr.write('SPNEGO Proxy Auth: FAILED\n')
283+
else:
284+
sys.stderr.write('SPNEGO Proxy Auth: SUCCESS\n')
285+
276286

277287
def test_basic_auth_krb5(testdir, testenv, testlog):
278288

tests/t_spnego_proxy.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/python
2+
# Copyright (C) 2015 - mod_auth_gssapi contributors, see COPYING for license.
3+
4+
import os
5+
import requests
6+
import gssapi
7+
from base64 import b64encode
8+
9+
def getAuthToken(target):
10+
spnego_mech = gssapi.raw.OID.from_int_seq('1.3.6.1.5.5.2')
11+
12+
name = gssapi.Name('HTTP@%s' % target,
13+
gssapi.NameType.hostbased_service)
14+
15+
ctx = gssapi.SecurityContext(name=name, mech=spnego_mech)
16+
token = ctx.step()
17+
18+
return 'Negotiate %s' % b64encode(token)
19+
20+
21+
if __name__ == '__main__':
22+
s = requests.Session()
23+
24+
target = os.environ['NSS_WRAPPER_HOSTNAME']
25+
url = 'http://%s/spnego/' % target
26+
27+
proxy = 'http://%s:%s' % (target, os.environ['WRAP_PROXY_PORT'])
28+
proxies = { "http" : proxy, }
29+
30+
s.headers.update({'Proxy-Authorization': getAuthToken(target)})
31+
s.headers.update({'Authorization': getAuthToken(target)})
32+
33+
r = s.get(url, proxies=proxies)
34+
if r.status_code != 200:
35+
raise ValueError('Spnego Proxy Auth Failed')

0 commit comments

Comments
 (0)