Test 404 and 403.

This commit is contained in:
Emil Mikulic 2015-01-01 20:32:52 +11:00
parent 456bbfcde6
commit 946a910935
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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)