From 269780c57780d155c4d8bd95fcc2af2104effa5b Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 23 Feb 2013 16:34:59 +1300 Subject: [PATCH] Unit test dummy response functions. --- libmproxy/proxy.py | 3 ++- test/test_server.py | 16 ++++++++++++++++ test/tservers.py | 18 ++++++++++++------ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 6d476c7be..c8fac5f46 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -194,7 +194,8 @@ class ProxyHandler(tcp.BaseHandler): sc.rfile.first_byte_timestamp, utils.timestamp() ) 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: sc.terminate() diff --git a/test/test_server.py b/test/test_server.py index 58dfee580..5cba891c4 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -2,6 +2,7 @@ import socket, time from netlib import tcp from libpathod import pathoc import tutils, tservers +from libmproxy import flow """ 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 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() + diff --git a/test/tservers.py b/test/tservers.py index 4cbdc942a..3fdb8d13a 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -29,16 +29,20 @@ class TestMaster(flow.FlowMaster): flow.FlowMaster.__init__(self, s, state) self.testq = testq - def handle(self, m): - flow.FlowMaster.handle(self, m) + def handle_request(self, m): + flow.FlowMaster.handle_request(self, m) + m.reply() + + def handle_response(self, m): + flow.FlowMaster.handle_response(self, m) m.reply() class ProxyThread(threading.Thread): - def __init__(self, testq, config): - self.tmaster = TestMaster(testq, config) - controller.should_exit = False + def __init__(self, tmaster): threading.Thread.__init__(self) + self.tmaster = tmaster + controller.should_exit = False @property def port(self): @@ -52,6 +56,7 @@ class ProxyThread(threading.Thread): class ProxTestBase: + masterclass = TestMaster @classmethod def setupAll(cls): cls.tqueue = Queue.Queue() @@ -61,7 +66,8 @@ class ProxTestBase: certfile=tutils.test_data.path("data/testkey.pem"), **pconf ) - cls.proxy = ProxyThread(cls.tqueue, config) + tmaster = cls.masterclass(cls.tqueue, config) + cls.proxy = ProxyThread(tmaster) cls.proxy.start() @property