2 # Copyright (C) 2015 - mod_auth_gssapi contributors, see COPYING for license.
6 from requests_kerberos import HTTPKerberosAuth, OPTIONAL
9 if __name__ == '__main__':
10 sess = requests.Session()
11 url = 'http://%s/spnego_negotiate_once/' % (
12 os.environ['NSS_WRAPPER_HOSTNAME'])
14 # ensure a 401 with the appropriate WWW-Authenticate header is returned
15 # when no auth is provided
17 if r.status_code != 401:
18 raise ValueError('Spnego Negotiate Once failed - 401 expected')
19 if not (r.headers.get("WWW-Authenticate") and
20 r.headers.get("WWW-Authenticate").startswith("Negotiate")):
21 raise ValueError('Spnego Negotiate Once failed - WWW-Authenticate '
22 'Negotiate header missing')
24 # test sending a bad Authorization header with GssapiNegotiateOnce enabled
25 r = sess.get(url, headers={"Authorization": "Negotiate badvalue"})
26 if r.status_code != 401:
27 raise ValueError('Spnego Negotiate Once failed - 401 expected')
28 if r.headers.get("WWW-Authenticate"):
29 raise ValueError('Spnego Negotiate Once failed - WWW-Authenticate '
30 'Negotiate present but GssapiNegotiateOnce is '
33 # ensure a 200 is returned when valid auth is provided
34 r = sess.get(url, auth=HTTPKerberosAuth())
35 if r.status_code != 200:
36 raise ValueError('Spnego Negotiate Once failed')