diff --git a/CHANGES b/CHANGES index 0fa41aa..5e091fd 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,11 @@ +2.0: + Major modifications + Replace libowfat with libc + Replace buffer_1 and buffer_2 with stdio + Fix directory listing of / SEGV + Replace compile-time options with command-line ones + Add regression test suite + 1.11: Fix if-modified-since date parsing Make text content-types use charset=UTF-8 diff --git a/Makefile b/Makefile index fb809c0..126306c 100644 --- a/Makefile +++ b/Makefile @@ -4,5 +4,8 @@ CFLAGS = -DFNORD='"fnord/$(VERSION)"' -Wall -Werror all: fnord +test: fnord + cd tests && python3 ./test.py + clean: rm -f *.[oa] fnord diff --git a/fnord.c b/fnord.c index 2723442..0cf8fff 100644 --- a/fnord.c +++ b/fnord.c @@ -1093,7 +1093,7 @@ handledirlist(const char *origurl) size = 32 + nl; fputs("HTTP/1.0 200 OK\r\nServer: " FNORD "\r\nConnection: close\r\n", stdout); - fputs("Content-Type: text/html\r\n", stdout); + fputs("Content-Type: text/html; charset=utf-8\r\n", stdout); fputs("\r\n

Directory Listing: /", stdout); hdl_encode_html(nurl, nl); fputs("

\n
\n", stdout);
@@ -1425,7 +1425,7 @@ main(int argc, char *argv[], const char *const *envp)
                 redirect = 1;
                 break;
             default:
-                fprintf(stderr, "%d Usage: %s [-d] [-r]\n", opt, argv[0]);
+                fprintf(stderr, "Usage: %s [-c] [-d] [-r]\n", argv[0]);
                 return 69;
             }
         }
diff --git a/tests/default/index.html b/tests/default/index.html
new file mode 100644
index 0000000..dc065e0
--- /dev/null
+++ b/tests/default/index.html
@@ -0,0 +1 @@
+james
diff --git a/tests/moo:80/.empty b/tests/moo:80/.empty
new file mode 100644
index 0000000..e69de29
diff --git a/tests/test.py b/tests/test.py
new file mode 100755
index 0000000..0a6c836
--- /dev/null
+++ b/tests/test.py
@@ -0,0 +1,59 @@
+#! /usr/bin/python3
+
+import unittest
+from subprocess import *
+import os
+
+def fnord(*args):
+    return Popen(('../fnord',) + args, 
+                 stdin=PIPE, stdout=PIPE, stderr=PIPE,
+                 env={'PROTO': 'TCP',
+                      'TCPREMOTEPORT': '5858',
+                      'TCPREMOTEIP': '10.1.2.3'})
+
+class ArgTests(unittest.TestCase):
+    def check_index(self, *args):
+        p = fnord(*args)
+        so, se = p.communicate(b'GET / HTTP/1.0\r\n\r\n')
+        self.assertEqual(so, b'HTTP/1.0 200 OK\r\nServer: fnord/2.0\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 6\r\nLast-Modified: Thu, 16 Feb 2012 04:08:57 GMT\r\n\r\njames\n')
+        self.assertEqual(se, b'10.1.2.3 200 6 127.0.0.1:80 (null) (null) /index.html\n')
+
+    def testArgs(self):
+        "Make sure index.html is the same for all arguments"
+
+        self.check_index()
+        self.check_index('-d')
+        self.check_index('-r')
+        self.check_index('-c')
+
+    def testBadArgs(self):
+        "Make sure bad arguments actually fail"
+
+        self.assertRaises(AssertionError, self.check_index, '-Z')
+
+
+class BasicTests(unittest.TestCase):
+    args = []
+
+    def setUp(self):
+        self.p = fnord(*self.args)
+        
+    def tearDown(self):
+        del self.p
+
+    def get(self, path, host):
+        h = 'GET %s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host)
+        so, se = self.p.communicate(h.encode('utf-8'))
+        return (so, se)
+
+
+class DirTests(BasicTests):
+    args = ['-d']
+
+    def testRootDir(self):
+        so, se = self.get('/', 'moo')
+        self.assertEqual(so, b'HTTP/1.0 200 OK\r\nServer: fnord/2.0\r\nConnection: close\r\nContent-Type: text/html; charset=utf-8\r\n\r\n

Directory Listing: /

\n
\n
\n') + self.assertEqual(se, b'10.1.2.3 200 32 moo:80 (null) (null) /\n') + + +unittest.main()