Add test for --forward
authorEmil Mikulic <emikulic@gmail.com>
Sun, 28 Apr 2013 14:31:54 +0000 (00:31 +1000)
committerEmil Mikulic <emikulic@gmail.com>
Sun, 28 Apr 2013 14:32:22 +0000 (00:32 +1000)
devel/cover
devel/test_forward.py [new file with mode: 0755]

index f9f89da..99d7a7c 100755 (executable)
@@ -21,12 +21,23 @@ mkdir $DIR || exit 1
 rm -f darkhttpd.gcda darkhttpd.log
 # display usage statement
 ./a.out >/dev/null
 rm -f darkhttpd.gcda darkhttpd.log
 # display usage statement
 ./a.out >/dev/null
-# run all tests against this instance (generates darkhttpd.gcda)
+
+# run tests against a basic instance (generates darkhttpd.gcda)
 ./a.out $DIR --port $PORT --log darkhttpd.log &
 PID=$!
 kill -0 $PID || exit 1
 python test.py
 kill $PID
 ./a.out $DIR --port $PORT --log darkhttpd.log &
 PID=$!
 kill -0 $PID || exit 1
 python test.py
 kill $PID
+
+# run forward tests
+./a.out $DIR --port $PORT \
+  --forward example.com http://www.example.com \
+  --forward secure.example.com https://www.example.com/secure &
+PID=$!
+kill -0 $PID || exit 1
+python test_forward.py
+kill $PID
+
 echo generating darkhttpd.c.gcov report
 gcov darkhttpd
 rm -rf $DIR
 echo generating darkhttpd.c.gcov report
 gcov darkhttpd
 rm -rf $DIR
diff --git a/devel/test_forward.py b/devel/test_forward.py
new file mode 100755 (executable)
index 0000000..103feef
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+import unittest
+from test import TestHelper, Conn, parse
+
+class TestForward(TestHelper):
+    def test_forward_root(self):
+        resp = Conn().get("/", req_hdrs = { "Host": "example.com" })
+        status, hdrs, body = parse(resp)
+        self.assertContains(status, "301 Moved Permanently")
+        expect = "http://www.example.com/"
+        self.assertEquals(hdrs["Location"], expect)
+        self.assertContains(body, expect)
+
+    def test_forward_relative(self):
+        resp = Conn().get("/foo/bar",
+                          req_hdrs = { "Host": "secure.example.com" })
+        status, hdrs, body = parse(resp)
+        self.assertContains(status, "301 Moved Permanently")
+        expect = "https://www.example.com/secure/foo/bar"
+        self.assertEquals(hdrs["Location"], expect)
+        self.assertContains(body, expect)
+
+if __name__ == '__main__':
+    unittest.main()
+
+# vim:set ts=4 sw=4 et: