mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
Test 404 and 403.
This commit is contained in:
parent
456bbfcde6
commit
946a910935
@ -19,6 +19,8 @@ if [ -e $DIR ]; then
|
|||||||
rm -rf $DIR || exit 1
|
rm -rf $DIR || exit 1
|
||||||
fi
|
fi
|
||||||
mkdir $DIR || exit 1
|
mkdir $DIR || exit 1
|
||||||
|
mkdir $DIR/forbidden || exit 1
|
||||||
|
chmod 0 $DIR/forbidden || exit 1
|
||||||
rm -f darkhttpd.gcda darkhttpd.log
|
rm -f darkhttpd.gcda darkhttpd.log
|
||||||
|
|
||||||
echo "===> test_make_safe_uri"
|
echo "===> test_make_safe_uri"
|
||||||
@ -32,7 +34,7 @@ echo "===> run usage statement"
|
|||||||
./a.out >/dev/null
|
./a.out >/dev/null
|
||||||
|
|
||||||
echo "===> run tests against a basic instance (generates darkhttpd.gcda)"
|
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=$!
|
PID=$!
|
||||||
kill -0 $PID || exit 1
|
kill -0 $PID || exit 1
|
||||||
python test.py
|
python test.py
|
||||||
@ -83,5 +85,5 @@ wait $PID
|
|||||||
echo "===> generating darkhttpd.c.gcov report"
|
echo "===> generating darkhttpd.c.gcov report"
|
||||||
gcov darkhttpd
|
gcov darkhttpd
|
||||||
rm -rf $DIR
|
rm -rf $DIR
|
||||||
rm -f darkhttpd.gcda darkhttpd.gcno darkhttpd.log a.out
|
rm -f darkhttpd.gcda darkhttpd.gcno a.out
|
||||||
echo done
|
echo done
|
||||||
|
@ -73,6 +73,20 @@ class TestHelper(unittest.TestCase):
|
|||||||
"You requested an invalid URL: %s\n"%path,
|
"You requested an invalid URL: %s\n"%path,
|
||||||
'Generated by darkhttpd')
|
'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,
|
def drive_range(self, range_in, range_out, len_out, data_out,
|
||||||
status_out = "206 Partial Content"):
|
status_out = "206 Partial Content"):
|
||||||
resp = Conn().get(self.url, req_hdrs = {"Range": "bytes="+range_in})
|
resp = Conn().get(self.url, req_hdrs = {"Range": "bytes="+range_in})
|
||||||
@ -159,6 +173,8 @@ def setUpModule():
|
|||||||
["no leading slash", "dir/../", "assertIsInvalid"],
|
["no leading slash", "dir/../", "assertIsInvalid"],
|
||||||
["invalid up dir", "/../", "assertIsInvalid"],
|
["invalid up dir", "/../", "assertIsInvalid"],
|
||||||
["fancy invalid up dir", "/./dir/./../../", "assertIsInvalid"],
|
["fancy invalid up dir", "/./dir/./../../", "assertIsInvalid"],
|
||||||
|
["not found", "/not_found.txt", "assertNotFound"],
|
||||||
|
["forbidden", "/forbidden/x", "assertForbidden"],
|
||||||
]:
|
]:
|
||||||
makeSimpleCases(*args)
|
makeSimpleCases(*args)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user