Include RPM spec file in dist package.
[mod_auth_gssapi.git] / tests / t_spnego_negotiate_once.py
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_kerberos import HTTPKerberosAuth, OPTIONAL
7
8
9 if __name__ == '__main__':
10     sess = requests.Session()
11     url = 'http://%s/spnego_negotiate_once/' % (
12         os.environ['NSS_WRAPPER_HOSTNAME'])
13
14     # ensure a 401 with the appropriate WWW-Authenticate header is returned
15     # when no auth is provided
16     r = sess.get(url)
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')
23
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 '
31                          'enabled')
32
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')
37