Skip to content

Commit c9e3ec5

Browse files
committed
Test that error env vars are properly exported.
Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Robbie Harwood <rharwood@redhat.com> Closes #130
1 parent b4f5124 commit c9e3ec5

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

src/mod_auth_gssapi.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,17 @@ char *mag_error(request_rec *req, const char *msg, uint32_t maj, uint32_t min)
6969
}
7070

7171
enum mag_err_code {
72-
MAG_GSS_ERR = 1,
72+
MAG_NO_AUTH = 1,
73+
MAG_GSS_ERR,
7374
MAG_INTERNAL,
7475
MAG_AUTH_NOT_ALLOWED
7576
};
7677

7778
static const char *mag_err_text(enum mag_err_code err)
7879
{
7980
switch (err) {
81+
case MAG_NO_AUTH:
82+
return "NO AUTH DATA";
8083
case MAG_GSS_ERR:
8184
return "GSS ERROR";
8285
case MAG_INTERNAL:
@@ -948,10 +951,18 @@ static int mag_auth(request_rec *req)
948951
}
949952

950953
/* We can proceed only if we do have an auth header */
951-
if (!auth_header) goto done;
954+
if (!auth_header) {
955+
mag_post_error(req, cfg, MAG_NO_AUTH, 0, 0,
956+
"Client did not send any authentication headers");
957+
goto done;
958+
}
952959

953960
auth_header_type = ap_getword_white(req->pool, &auth_header);
954-
if (!auth_header_type) goto done;
961+
if (!auth_header_type) {
962+
mag_post_error(req, cfg, MAG_NO_AUTH, 0, 0,
963+
"Client sent malformed authentication headers");
964+
goto done;
965+
}
955966

956967
/* We got auth header, sending auth header would mean re-auth */
957968
send_auth_header = !cfg->negotiate_once;
@@ -1028,6 +1039,8 @@ static int mag_auth(request_rec *req)
10281039
break;
10291040

10301041
default:
1042+
mag_post_error(req, cfg, MAG_NO_AUTH, 0, 0,
1043+
"Client sent unknown authentication headers");
10311044
goto done;
10321045
}
10331046

tests/401.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MAG_ERROR:[<!--#echo var="REDIRECT_MAG_ERROR" -->] MAG_ERROR_TEXT:[<!--#echo var="REDIRECT_MAG_ERROR_TEXT" -->] GSS_ERROR_MAJ:[<!--#echo var="REDIRECT_GSS_ERROR_MAJ" -->] GSS_ERROR_MIN:[<!--#echo var="REDIRECT_GSS_ERROR_MIN" -->]

tests/httpd.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ DocumentRoot "${HTTPROOT}/html"
9393
</Directory>
9494
<Directory "${HTTPROOT}/html">
9595
Options Indexes FollowSymLinks
96+
Options +Includes
97+
AddOutputFilter INCLUDES .html
9698
AllowOverride None
9799
Require all granted
98100
</Directory>
@@ -112,6 +114,7 @@ LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combine
112114
CustomLog "logs/access_log" combined
113115
</IfModule>
114116

117+
ErrorDocument 401 /401.html
115118
ErrorLog "logs/error_log"
116119
LogLevel debug
117120

@@ -193,6 +196,7 @@ CoreDumpDirectory "${HTTPROOT}"
193196
GssapiBasicAuth On
194197
GssapiBasicAuthMech krb5
195198
GssapiConnectionBound On
199+
GssapiPublishErrors On
196200
Require valid-user
197201
</Location>
198202

tests/magtests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ def setup_http(testdir, wrapenv):
239239
with open(config, 'w+') as f:
240240
f.write(text)
241241

242+
shutil.copy('tests/401.html', os.path.join(httpdir, 'html'))
243+
242244
httpenv = {'PATH': '/sbin:/bin:/usr/sbin:/usr/bin',
243245
'MALLOC_CHECK_': '3',
244246
'MALLOC_PERTURB_': str(random.randint(0, 32767) % 255 + 1)}

tests/t_basic_k5_fail_second.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import requests
6+
import sys
67
from requests.auth import HTTPBasicAuth
78

89

@@ -22,6 +23,8 @@
2223
r = s.get(url)
2324
if r.status_code == 200:
2425
raise ValueError('Basic Auth: Got Success while expecting Error')
26+
if not 'GSS ERROR' in r.text:
27+
raise ValueError('Basic Auth: Expected error variable is missing')
2528

2629
url = 'http://%s:%s@%s/basic_auth_krb5/' % (os.environ['MAG_USER_NAME_2'],
2730
os.environ['MAG_USER_PASSWORD_2'],

0 commit comments

Comments
 (0)