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.master
parent
c590818d7f
commit
6633423420
11 changed files with 364 additions and 83 deletions
@ -0,0 +1,37 @@ |
||||
import http |
||||
from twisted.internet import defer |
||||
|
||||
""" |
||||
Schema v2 |
||||
|
||||
Description: |
||||
Adds support for specifying the port of a request and specify its port. This |
||||
lets requests that have the port/ssl settings specified in the CONNECT request |
||||
maintain that information. |
||||
""" |
||||
|
||||
update_queries = [ |
||||
""" |
||||
ALTER TABLE requests ADD COLUMN port INTEGER; |
||||
""", |
||||
|
||||
""" |
||||
ALTER TABLE requests ADD COLUMN is_ssl INTEGER; |
||||
""", |
||||
|
||||
""" |
||||
UPDATE schema_meta SET version=2; |
||||
""", |
||||
] |
||||
|
||||
@defer.inlineCallbacks |
||||
def update(dbpool): |
||||
for query in update_queries: |
||||
yield dbpool.runQuery(query) |
||||
|
||||
# Load each request and save them again for any request that specified a port |
||||
# or protocol in the host header. |
||||
http.init(dbpool) |
||||
reqs = yield http.Request.load_from_filters([]) |
||||
for req in reqs: |
||||
yield req.deep_save() |
@ -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 |
||||
|
Loading…
Reference in new issue