proxy tests: fix leaking sockets

This commit is contained in:
Thomas Kriechbaumer 2017-05-24 12:52:13 +02:00
parent c9529ffe45
commit 928085c597
3 changed files with 15 additions and 14 deletions

View File

@ -48,6 +48,8 @@ class ProxyServer(tcp.TCPServer):
if config.options.mode == "transparent":
platform.init_transparent_mode()
except Exception as e:
if self.socket:
self.socket.close()
raise exceptions.ServerException(
'Error starting proxy server: ' + repr(e)
) from e

View File

@ -13,8 +13,7 @@ from mitmproxy.tools import cmdline # noqa
from mitmproxy import exceptions # noqa
from mitmproxy import options # noqa
from mitmproxy import optmanager # noqa
from mitmproxy.proxy import config # noqa
from mitmproxy.proxy import server # noqa
from mitmproxy import proxy
from mitmproxy.utils import version_check # noqa
from mitmproxy.utils import debug # noqa
@ -49,15 +48,7 @@ def process_options(parser, opts, args):
adict[n] = getattr(args, n)
opts.merge(adict)
pconf = config.ProxyConfig(opts)
if opts.server:
try:
return server.ProxyServer(pconf)
except exceptions.ServerException as v:
print(str(v), file=sys.stderr)
sys.exit(1)
else:
return server.DummyServer(pconf)
return proxy.config.ProxyConfig(opts)
def run(MasterKlass, args, extra=None): # pragma: no cover
@ -74,7 +65,16 @@ def run(MasterKlass, args, extra=None): # pragma: no cover
master = None
try:
unknown = optmanager.load_paths(opts, args.conf)
server = process_options(parser, opts, args)
pconf = process_options(parser, opts, args)
if pconf.options.server:
try:
server = proxy.server.ProxyServer(pconf)
except exceptions.ServerException as v:
print(str(v), file=sys.stderr)
sys.exit(1)
else:
server = proxy.server.DummyServer(pconf)
master = MasterKlass(opts, server)
master.addons.trigger("configure", opts.keys())
master.addons.trigger("tick")

View File

@ -32,8 +32,7 @@ class TestProcessProxyOptions:
opts = options.Options()
cmdline.common_options(parser, opts)
args = parser.parse_args(args=args)
main.process_options(parser, opts, args)
pconf = config.ProxyConfig(opts)
pconf = main.process_options(parser, opts, args)
return parser, pconf
def assert_noerr(self, *args):