Unit test dummy response functions.
This commit is contained in:
parent
f203881b0d
commit
269780c577
|
@ -194,7 +194,8 @@ class ProxyHandler(tcp.BaseHandler):
|
||||||
sc.rfile.first_byte_timestamp, utils.timestamp()
|
sc.rfile.first_byte_timestamp, utils.timestamp()
|
||||||
)
|
)
|
||||||
response_reply = self.channel.ask(response)
|
response_reply = self.channel.ask(response)
|
||||||
# Not replying to the server invalidates the server connection, so we terminate.
|
# Not replying to the server invalidates the server
|
||||||
|
# connection, so we terminate.
|
||||||
if response_reply == KILL:
|
if response_reply == KILL:
|
||||||
sc.terminate()
|
sc.terminate()
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import socket, time
|
||||||
from netlib import tcp
|
from netlib import tcp
|
||||||
from libpathod import pathoc
|
from libpathod import pathoc
|
||||||
import tutils, tservers
|
import tutils, tservers
|
||||||
|
from libmproxy import flow
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Note that the choice of response code in these tests matters more than you
|
Note that the choice of response code in these tests matters more than you
|
||||||
|
@ -144,3 +145,18 @@ class TestProxy(tservers.HTTPProxTest):
|
||||||
|
|
||||||
request = self.master.state.view[1].request
|
request = self.master.state.view[1].request
|
||||||
assert request.timestamp_end - request.timestamp_start <= 0.1
|
assert request.timestamp_end - request.timestamp_start <= 0.1
|
||||||
|
|
||||||
|
|
||||||
|
class MasterFakeResponse(tservers.TestMaster):
|
||||||
|
def handle_request(self, m):
|
||||||
|
resp = tutils.tresp()
|
||||||
|
m.reply(resp)
|
||||||
|
|
||||||
|
|
||||||
|
class TestFakeResponse(tservers.HTTPProxTest):
|
||||||
|
masterclass = MasterFakeResponse
|
||||||
|
def test_kill(self):
|
||||||
|
p = self.pathoc()
|
||||||
|
f = self.pathod("200")
|
||||||
|
assert "header_response" in f.headers.keys()
|
||||||
|
|
||||||
|
|
|
@ -29,16 +29,20 @@ class TestMaster(flow.FlowMaster):
|
||||||
flow.FlowMaster.__init__(self, s, state)
|
flow.FlowMaster.__init__(self, s, state)
|
||||||
self.testq = testq
|
self.testq = testq
|
||||||
|
|
||||||
def handle(self, m):
|
def handle_request(self, m):
|
||||||
flow.FlowMaster.handle(self, m)
|
flow.FlowMaster.handle_request(self, m)
|
||||||
|
m.reply()
|
||||||
|
|
||||||
|
def handle_response(self, m):
|
||||||
|
flow.FlowMaster.handle_response(self, m)
|
||||||
m.reply()
|
m.reply()
|
||||||
|
|
||||||
|
|
||||||
class ProxyThread(threading.Thread):
|
class ProxyThread(threading.Thread):
|
||||||
def __init__(self, testq, config):
|
def __init__(self, tmaster):
|
||||||
self.tmaster = TestMaster(testq, config)
|
|
||||||
controller.should_exit = False
|
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
self.tmaster = tmaster
|
||||||
|
controller.should_exit = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def port(self):
|
def port(self):
|
||||||
|
@ -52,6 +56,7 @@ class ProxyThread(threading.Thread):
|
||||||
|
|
||||||
|
|
||||||
class ProxTestBase:
|
class ProxTestBase:
|
||||||
|
masterclass = TestMaster
|
||||||
@classmethod
|
@classmethod
|
||||||
def setupAll(cls):
|
def setupAll(cls):
|
||||||
cls.tqueue = Queue.Queue()
|
cls.tqueue = Queue.Queue()
|
||||||
|
@ -61,7 +66,8 @@ class ProxTestBase:
|
||||||
certfile=tutils.test_data.path("data/testkey.pem"),
|
certfile=tutils.test_data.path("data/testkey.pem"),
|
||||||
**pconf
|
**pconf
|
||||||
)
|
)
|
||||||
cls.proxy = ProxyThread(cls.tqueue, config)
|
tmaster = cls.masterclass(cls.tqueue, config)
|
||||||
|
cls.proxy = ProxyThread(tmaster)
|
||||||
cls.proxy.start()
|
cls.proxy.start()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Reference in New Issue