Bugfixes, features, etc.
For more details on what affects you, look at the README diff. Most of this was reworking the internals and there were so many changes that I can't really list them all.
This commit is contained in:
parent
c590818d7f
commit
6633423420
11 changed files with 363 additions and 82 deletions
|
@ -62,7 +62,7 @@ def gzip_string(string):
|
|||
return out.getvalue()
|
||||
|
||||
def deflate_string(string):
|
||||
return StringIO.StringIO(zlib.compress(string)).read()
|
||||
return zlib.compress(string)[2:-4]
|
||||
|
||||
def check_response_cookies(exp_pairs, rsp):
|
||||
pairs = rsp.cookies.all_pairs()
|
||||
|
@ -345,8 +345,28 @@ def test_response_cookie_parsing():
|
|||
assert c.path == '/'
|
||||
assert c.secure
|
||||
|
||||
def test_response_cookie_generate():
|
||||
pass
|
||||
def test_response_cookie_blank():
|
||||
# Don't ask why this exists, I've run into it
|
||||
s = ' ; path=/; secure'
|
||||
c = http.ResponseCookie(s)
|
||||
assert c.key == ''
|
||||
assert c.val == ''
|
||||
assert c.path == '/'
|
||||
assert c.secure
|
||||
|
||||
s = '; path=/; secure'
|
||||
c = http.ResponseCookie(s)
|
||||
assert c.key == ''
|
||||
assert c.val == ''
|
||||
assert c.path == '/'
|
||||
assert c.secure
|
||||
|
||||
s = 'asdf; path=/; secure'
|
||||
c = http.ResponseCookie(s)
|
||||
assert c.key == 'asdf'
|
||||
assert c.val == ''
|
||||
assert c.path == '/'
|
||||
assert c.secure
|
||||
|
||||
|
||||
####################
|
||||
|
@ -619,6 +639,8 @@ def test_request_to_json():
|
|||
|
||||
expected_reqdata = {'full_request': base64.b64encode(r.full_request),
|
||||
'response_id': rsp.rspid,
|
||||
'port': 80,
|
||||
'is_ssl': False,
|
||||
#'tag': r.tag,
|
||||
'reqid': r.reqid,
|
||||
}
|
||||
|
@ -646,6 +668,30 @@ def test_request_blank_get_params():
|
|||
assert r.get_params['c'] == None
|
||||
assert r.get_params['d'] == 'ef'
|
||||
|
||||
def test_request_blank():
|
||||
r = http.Request('\r\n\n\n')
|
||||
assert r.full_request == ''
|
||||
|
||||
def test_request_blank_headers():
|
||||
r = http.Request(('GET / HTTP/1.1\r\n'
|
||||
'Header: \r\n'
|
||||
'Header2:\r\n'))
|
||||
|
||||
assert r.headers['header'] == ''
|
||||
assert r.headers['header2'] == ''
|
||||
|
||||
def test_request_blank_cookies():
|
||||
r = http.Request(('GET / HTTP/1.1\r\n'
|
||||
'Cookie: \r\n'))
|
||||
assert r.cookies[''] == ''
|
||||
|
||||
r = http.Request(('GET / HTTP/1.1\r\n'
|
||||
'Cookie: a=b; ; c=d\r\n'))
|
||||
assert r.cookies[''] == ''
|
||||
|
||||
r = http.Request(('GET / HTTP/1.1\r\n'
|
||||
'Cookie: a=b; foo; c=d\r\n'))
|
||||
assert r.cookies['foo'] == ''
|
||||
|
||||
####################
|
||||
## Response tests
|
||||
|
@ -992,3 +1038,15 @@ def test_response_update_from_objects_cookies_replace():
|
|||
'Set-Cookie: baz=buzz\r\n'
|
||||
'Header: out of fucking nowhere\r\n'
|
||||
'\r\n')
|
||||
|
||||
def test_response_blank():
|
||||
r = http.Response('\r\n\n\n')
|
||||
assert r.full_response == ''
|
||||
|
||||
def test_response_blank_headers():
|
||||
r = http.Response(('HTTP/1.1 200 OK\r\n'
|
||||
'Header: \r\n'
|
||||
'Header2:\r\n'))
|
||||
|
||||
assert r.headers['header'] == ''
|
||||
assert r.headers['header2'] == ''
|
||||
|
|
|
@ -1,36 +1,56 @@
|
|||
import pytest
|
||||
import mangle
|
||||
import twisted.internet
|
||||
import twisted.test
|
||||
|
||||
from proxy import ProxyClient, ProxyClientFactory, ProxyServer
|
||||
from testutil import mock_deferred
|
||||
from testutil import mock_deferred, func_deleted, no_tcp, ignore_tcp, no_database, func_ignored
|
||||
from twisted.internet.protocol import ServerFactory
|
||||
from twisted.test import proto_helpers
|
||||
from twisted.internet import defer
|
||||
from twisted.test.iosim import FakeTransport
|
||||
from twisted.internet import defer, reactor
|
||||
|
||||
####################
|
||||
## Fixtures
|
||||
|
||||
@pytest.fixture
|
||||
def proxyserver():
|
||||
def proxyserver(monkeypatch):
|
||||
monkeypatch.setattr("twisted.test.iosim.FakeTransport.startTLS", func_ignored)
|
||||
factory = ServerFactory()
|
||||
factory.protocol = ProxyServer
|
||||
protocol = factory.buildProtocol(('127.0.0.1', 0))
|
||||
transport = proto_helpers.StringTransport()
|
||||
protocol.makeConnection(transport)
|
||||
return (protocol, transport)
|
||||
protocol.makeConnection(FakeTransport(protocol, True))
|
||||
return protocol
|
||||
|
||||
## Autorun fixtures
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def no_mangle(monkeypatch):
|
||||
# Don't call anything in mangle.py
|
||||
monkeypatch.setattr("mangle.mangle_request", func_deleted)
|
||||
monkeypatch.setattr("mangle.mangle_response", func_deleted)
|
||||
|
||||
####################
|
||||
## Basic tests
|
||||
## Unit test tests
|
||||
|
||||
def test_proxy_server_fixture(proxyserver):
|
||||
prot = proxyserver[0]
|
||||
tr = proxyserver[1]
|
||||
prot.transport.write('hello')
|
||||
print tr.value()
|
||||
assert tr.value() == 'hello'
|
||||
proxyserver.transport.write('hello')
|
||||
assert proxyserver.transport.getOutBuffer() == 'hello'
|
||||
|
||||
@pytest.inlineCallbacks
|
||||
def test_mock_deferreds(mock_deferred):
|
||||
d = mock_deferred('Hello!')
|
||||
r = yield d
|
||||
assert r == 'Hello!'
|
||||
|
||||
def test_deleted():
|
||||
with pytest.raises(NotImplementedError):
|
||||
reactor.connectTCP("www.google.com", "80", ServerFactory)
|
||||
|
||||
####################
|
||||
## Proxy Server Tests
|
||||
|
||||
def test_proxy_server_connect(proxyserver):
|
||||
proxyserver.lineReceived('CONNECT www.dddddd.fff:433 HTTP/1.1')
|
||||
proxyserver.lineReceived('')
|
||||
assert proxyserver.transport.getOutBuffer() == 'HTTP/1.1 200 Connection established\r\n\r\n'
|
||||
#assert starttls got called
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
import pytest
|
||||
from twisted.internet import defer
|
||||
|
||||
class ClassDeleted():
|
||||
pass
|
||||
|
||||
def func_deleted(*args, **kwargs):
|
||||
raise NotImplementedError()
|
||||
|
||||
def func_ignored(*args, **kwargs):
|
||||
pass
|
||||
|
||||
@pytest.fixture
|
||||
def mock_deferred():
|
||||
# Generates a function that can be used to make a deferred that can be used
|
||||
|
@ -13,3 +22,21 @@ def mock_deferred():
|
|||
d.callback(None)
|
||||
return d
|
||||
return f
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def no_tcp(monkeypatch):
|
||||
# Don't make tcp connections
|
||||
monkeypatch.setattr("twisted.internet.reactor.connectTCP", func_deleted)
|
||||
monkeypatch.setattr("twisted.internet.reactor.connectSSL", func_deleted)
|
||||
|
||||
@pytest.fixture
|
||||
def ignore_tcp(monkeypatch):
|
||||
# Don't make tcp connections
|
||||
monkeypatch.setattr("twisted.internet.reactor.connectTCP", func_ignored)
|
||||
monkeypatch.setattr("twisted.internet.reactor.connectSSL", func_ignored)
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def no_database(monkeypatch):
|
||||
# Don't make database queries
|
||||
monkeypatch.setattr("twisted.enterprise.adbapi.ConnectionPool",
|
||||
ClassDeleted)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue