Skip to content

Commit f206c24

Browse files
iboukrissimo5
authored andcommitted
More basic-auth tests
Add test for second user on the same connection with the password of the first user and without auth at all. Reviewed-by: Simo Sorce <[email protected]> Closes #48
1 parent 6dc1e9c commit f206c24

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/magtests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,16 @@ def test_basic_auth_krb5(testdir, testenv, testlog):
300300
else:
301301
sys.stderr.write('BASIC-AUTH Two Users: SUCCESS\n')
302302

303+
with (open(testlog, 'a')) as logfile:
304+
basick5 = subprocess.Popen(["tests/t_basic_k5_fail_second.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 Fail Second User: FAILED\n')
310+
else:
311+
sys.stderr.write('BASIC Fail Second User: SUCCESS\n')
312+
303313
with (open(testlog, 'a')) as logfile:
304314
basick5 = subprocess.Popen(["tests/t_basic_proxy.py"],
305315
stdout=logfile, stderr=logfile,

tests/t_basic_k5_fail_second.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
s = requests.Session()
11+
12+
url = 'http://%s:%s@%s/basic_auth_krb5/' % (os.environ['MAG_USER_NAME'],
13+
os.environ['MAG_USER_PASSWORD'],
14+
os.environ['NSS_WRAPPER_HOSTNAME'])
15+
r = s.get(url)
16+
if r.status_code != 200:
17+
raise ValueError('Basic Auth: Failed Authentication')
18+
19+
url = 'http://%s:%s@%s/basic_auth_krb5/' % (os.environ['MAG_USER_NAME_2'],
20+
os.environ['MAG_USER_PASSWORD'],
21+
os.environ['NSS_WRAPPER_HOSTNAME'])
22+
r = s.get(url)
23+
if r.status_code == 200:
24+
raise ValueError('Basic Auth: Got Success while expecting Error')
25+
26+
url = 'http://%s:%s@%s/basic_auth_krb5/' % (os.environ['MAG_USER_NAME_2'],
27+
os.environ['MAG_USER_PASSWORD_2'],
28+
os.environ['NSS_WRAPPER_HOSTNAME'])
29+
r = s.get(url)
30+
if r.status_code != 200:
31+
raise ValueError('Basic Auth: Failed Authentication')
32+
33+
url = 'http://%s/basic_auth_krb5/' % os.environ['NSS_WRAPPER_HOSTNAME']
34+
r = s.get(url)
35+
if r.status_code == 200:
36+
raise ValueError('Basic Auth: Got Success while expecting Error')

0 commit comments

Comments
 (0)