Test 404 and 403.
authorEmil Mikulic <emikulic@gmail.com>
Thu, 1 Jan 2015 09:32:52 +0000 (20:32 +1100)
committerEmil Mikulic <emikulic@gmail.com>
Thu, 1 Jan 2015 09:32:52 +0000 (20:32 +1100)
devel/cover
devel/test.py

index 61a937a..d59d216 100755 (executable)
@@ -19,6 +19,8 @@ if [ -e $DIR ]; then
        rm -rf $DIR || exit 1
 fi
 mkdir $DIR || exit 1
+mkdir $DIR/forbidden || exit 1
+chmod 0 $DIR/forbidden || exit 1
 rm -f darkhttpd.gcda darkhttpd.log
 
 echo "===> test_make_safe_uri"
@@ -32,7 +34,7 @@ echo "===> run usage statement"
 ./a.out >/dev/null
 
 echo "===> run tests against a basic instance (generates darkhttpd.gcda)"
-./a.out $DIR --port $PORT --log darkhttpd.log >/dev/null &
+./a.out $DIR --port $PORT --log cover.out.log >cover.out.stdout 2>cover.out.stderr &
 PID=$!
 kill -0 $PID || exit 1
 python test.py
@@ -83,5 +85,5 @@ wait $PID
 echo "===> generating darkhttpd.c.gcov report"
 gcov darkhttpd
 rm -rf $DIR
-rm -f darkhttpd.gcda darkhttpd.gcno darkhttpd.log a.out
+rm -f darkhttpd.gcda darkhttpd.gcno a.out
 echo done
index 07b3501..cdb0cff 100755 (executable)
@@ -73,6 +73,20 @@ class TestHelper(unittest.TestCase):
             "You requested an invalid URL: %s\n"%path,
             'Generated by darkhttpd')
 
+    def assertNotFound(self, body, path):
+        self.assertContains(body,
+            "<title>404 Not Found</title>",
+            "<h1>Not Found</h1>\n",
+            "The URL you requested (%s) was not found.\n"%path,
+            'Generated by darkhttpd')
+
+    def assertForbidden(self, body, path):
+        self.assertContains(body,
+            "<title>403 Forbidden</title>",
+            "<h1>Forbidden</h1>\n",
+            "You don't have permission to access (%s).\n"%path,
+            'Generated by darkhttpd')
+
     def drive_range(self, range_in, range_out, len_out, data_out,
             status_out = "206 Partial Content"):
         resp = Conn().get(self.url, req_hdrs = {"Range": "bytes="+range_in})
@@ -159,6 +173,8 @@ def setUpModule():
         ["no leading slash",     "dir/../",         "assertIsInvalid"],
         ["invalid up dir",       "/../",            "assertIsInvalid"],
         ["fancy invalid up dir", "/./dir/./../../", "assertIsInvalid"],
+        ["not found",            "/not_found.txt",  "assertNotFound"],
+        ["forbidden",            "/forbidden/x",    "assertForbidden"],
         ]:
         makeSimpleCases(*args)