mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
proxy tests: fix leaking sockets
This commit is contained in:
parent
c9529ffe45
commit
928085c597
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user