Skip to content

Add test for Proxy SPNEGO auth #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/magtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ def test_spnego_auth(testdir, testenv, testlog):
else:
sys.stderr.write('SPNEGO: SUCCESS\n')

with (open(testlog, 'a')) as logfile:
spnego = subprocess.Popen(["tests/t_spnego_proxy.py"],
stdout=logfile, stderr=logfile,
env=testenv, preexec_fn=os.setsid)
spnego.wait()
if spnego.returncode != 0:
sys.stderr.write('SPNEGO Proxy Auth: FAILED\n')
else:
sys.stderr.write('SPNEGO Proxy Auth: SUCCESS\n')


def test_basic_auth_krb5(testdir, testenv, testlog):

Expand Down
35 changes: 35 additions & 0 deletions tests/t_spnego_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/python
# Copyright (C) 2015 - mod_auth_gssapi contributors, see COPYING for license.

import os
import requests
import gssapi
from base64 import b64encode

def getAuthToken(target):
spnego_mech = gssapi.raw.OID.from_int_seq('1.3.6.1.5.5.2')

name = gssapi.Name('HTTP@%s' % target,
gssapi.NameType.hostbased_service)

ctx = gssapi.SecurityContext(name=name, mech=spnego_mech)
token = ctx.step()

return 'Negotiate %s' % b64encode(token)


if __name__ == '__main__':
s = requests.Session()

target = os.environ['NSS_WRAPPER_HOSTNAME']
url = 'http://%s/spnego/' % target

proxy = 'http://%s:%s' % (target, os.environ['WRAP_PROXY_PORT'])
proxies = { "http" : proxy, }

s.headers.update({'Proxy-Authorization': getAuthToken(target)})
s.headers.update({'Authorization': getAuthToken(target)})

r = s.get(url, proxies=proxies)
if r.status_code != 200:
raise ValueError('Spnego Proxy Auth Failed')