Add test for --no-listing.
authorEmil Mikulic <emikulic@gmail.com>
Tue, 19 May 2015 11:23:14 +0000 (21:23 +1000)
committerEmil Mikulic <emikulic@gmail.com>
Tue, 19 May 2015 11:30:59 +0000 (21:30 +1000)
darkhttpd.c
devel/cover
devel/test_no_listing.py [new file with mode: 0755]

index 86ec79f..a59a90c 100644 (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;
index 221a958..0551697 100755 (executable)
@@ -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
diff --git a/devel/test_no_listing.py b/devel/test_no_listing.py
new file mode 100755 (executable)
index 0000000..744378d
--- /dev/null
@@ -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: