9 self
.s
= socket
.socket()
10 self
.s
.connect(("0.0.0.0", self
.port
))
11 # connect throws socket.error on connection refused
18 r
= self
.s
.recv(65536)
26 class TestCases(unittest
.TestCase
):
27 def assertContains(self
, body
, *strings
):
29 self
.assertTrue(s
in body
,
30 msg
="expected %s in %s"%(repr(s
), repr(body
)))
32 def assertIsIndex(self
, body
, path
):
33 self
.assertContains(body
,
34 "<title>%s</title>\n"%path
,
36 '<a href="..">..</a>/',
37 'Generated by darkhttpd')
39 def assertIsInvalid(self
, body
, path
):
40 self
.assertContains(body
,
41 "<title>400 Bad Request</title>",
42 "<h1>Bad Request</h1>\n",
43 "You requested an invalid URI: %s\n"%path
,
44 'Generated by darkhttpd')
47 #def testIndex_HTTP_0_9(self):
48 # body = Conn().get("GET /\n\n")
49 # self.assertIsIndex(body)
51 def testIndex_HTTP_1_0(self
):
52 body
= Conn().get("GET / HTTP/1.0\n\n")
53 self
.assertIsIndex(body
, "/")
55 def testUpDirValid(self
):
56 body
= Conn().get("GET /dir/../ HTTP/1.0\n\n")
57 self
.assertIsIndex(body
, "/dir/../")
59 def testUpDirInvalid(self
):
60 body
= Conn().get("GET /../ HTTP/1.0\n\n")
61 self
.assertIsInvalid(body
, "/../")
63 def testUpDirInvalidFancy(self
):
64 body
= Conn().get("GET /dir/../../ HTTP/1.0\n\n")
65 self
.assertIsInvalid(body
, "/dir/../../")
67 if __name__
== '__main__':
69 #print Conn().get("GET /xyz/../ HTTP/1.0")
71 # vim:set ts=4 sw=4 et: