Add test for --no-listing.

This commit is contained in:
Emil Mikulic 2015-05-19 21:23:14 +10:00
parent fc8e127bb7
commit e9aeaba7fe
3 changed files with 27 additions and 0 deletions

View File

@ -1838,6 +1838,10 @@ static void process_get(struct connection *conn) {
free(target);
if (no_listing) {
free(decoded_url);
/* Return 404 instead of 403 to make --no-listing
* indistinguishable from the directory not existing.
* i.e.: Don't leak information.
*/
default_reply(conn, 404, "Not Found",
"The URL you requested (%s) was not found.", conn->url);
return;

View File

@ -84,6 +84,14 @@ python test_mimemap.py
kill $PID
wait $PID
echo "===> run --no-listing tests"
./a.out $DIR --port $PORT --no-listing >/dev/null &
PID=$!
kill -0 $PID || exit 1
python test_no_listing.py
kill $PID
wait $PID
echo "===> generating darkhttpd.c.gcov report"
gcov darkhttpd
rm -rf $DIR

15
devel/test_no_listing.py Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python
# This is run by the "cover" script.
import unittest
from test import TestHelper, Conn, parse
class TestNoListing(TestHelper):
def test_no_listing(self):
resp = self.get("/")
status, hdrs, body = parse(resp)
self.assertContains(status, "404 Not Found")
if __name__ == '__main__':
unittest.main()
# vim:set ts=4 sw=4 et: