2012-06-09 00:13:01 +00:00
|
|
|
import urllib, urllib2, unittest
|
2012-06-09 08:41:28 +00:00
|
|
|
import time
|
2012-06-07 22:00:16 +00:00
|
|
|
import libpathod.test, requests
|
2012-06-30 03:59:42 +00:00
|
|
|
from netlib import tcp, http
|
2011-03-05 22:21:31 +00:00
|
|
|
import tutils
|
|
|
|
|
2012-06-10 01:17:18 +00:00
|
|
|
"""
|
|
|
|
Note that the choice of response code in these tests matters more than you
|
|
|
|
might think. libcurl treats a 304 response code differently from, say, a
|
|
|
|
200 response code - it will correctly terminate a 304 response with no
|
|
|
|
content-length header, whereas it will block forever waiting for content
|
|
|
|
for a 200 response.
|
|
|
|
"""
|
|
|
|
|
2012-06-14 21:20:10 +00:00
|
|
|
class SanityMixin:
|
2011-03-05 22:21:31 +00:00
|
|
|
def test_http(self):
|
2012-06-10 01:17:18 +00:00
|
|
|
assert self.pathod("304").status_code == 304
|
2012-06-07 22:00:16 +00:00
|
|
|
assert self.log()
|
2011-03-05 22:21:31 +00:00
|
|
|
|
2012-06-13 06:16:47 +00:00
|
|
|
def test_large(self):
|
2012-06-14 21:20:10 +00:00
|
|
|
assert len(self.pathod("200:b@50k").content) == 1024*50
|
2012-06-13 06:16:47 +00:00
|
|
|
|
2011-03-05 22:21:31 +00:00
|
|
|
|
2012-06-14 21:20:10 +00:00
|
|
|
class TestHTTP(tutils.HTTPProxTest, SanityMixin):
|
2012-06-30 03:59:42 +00:00
|
|
|
def test_invalid_http(self):
|
|
|
|
t = tcp.TCPClient("127.0.0.1", self.proxy.port)
|
|
|
|
t.connect()
|
|
|
|
t.wfile.write("invalid\n\n")
|
|
|
|
t.wfile.flush()
|
|
|
|
assert "Bad Request" in t.rfile.readline()
|
|
|
|
|
|
|
|
def test_invalid_connect(self):
|
|
|
|
t = tcp.TCPClient("127.0.0.1", self.proxy.port)
|
|
|
|
t.connect()
|
|
|
|
t.wfile.write("CONNECT invalid\n\n")
|
|
|
|
t.wfile.flush()
|
|
|
|
assert "Bad Request" in t.rfile.readline()
|
2012-06-09 00:13:01 +00:00
|
|
|
|
|
|
|
|
2012-06-14 21:20:10 +00:00
|
|
|
class TestHTTPS(tutils.HTTPProxTest, SanityMixin):
|
2012-06-09 00:13:01 +00:00
|
|
|
ssl = True
|
|
|
|
|
|
|
|
|
2012-06-14 21:20:10 +00:00
|
|
|
class TestReverse(tutils.ReverseProxTest, SanityMixin):
|
2012-06-09 08:41:28 +00:00
|
|
|
reverse = True
|
|
|
|
|
|
|
|
|
2012-06-14 21:47:04 +00:00
|
|
|
class TestTransparent(tutils.TransparentProxTest, SanityMixin):
|
2012-06-14 21:20:10 +00:00
|
|
|
transparent = True
|
|
|
|
|
|
|
|
|
|
|
|
class TestProxy(tutils.HTTPProxTest):
|
2011-03-05 22:21:31 +00:00
|
|
|
def test_http(self):
|
2012-06-10 01:17:18 +00:00
|
|
|
f = self.pathod("304")
|
|
|
|
assert f.status_code == 304
|
2012-01-20 23:43:00 +00:00
|
|
|
|
2011-03-05 22:21:31 +00:00
|
|
|
l = self.log()
|
|
|
|
assert l[0].address
|
2011-07-14 03:59:27 +00:00
|
|
|
assert "host" in l[1].headers
|
2012-06-10 01:17:18 +00:00
|
|
|
assert l[2].code == 304
|