mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-03-26 08:54:48 +08:00
Merge pull request #2017 from lymanZerga11/patch-1
Catch ValueErrors from url.parse()
This commit is contained in:
@@ -338,9 +338,10 @@ class FlowListBox(urwid.ListBox):
|
||||
)
|
||||
|
||||
def new_request(self, url, method):
|
||||
parts = mitmproxy.net.http.url.parse(str(url))
|
||||
if not parts:
|
||||
signals.status_message.send(message="Invalid Url")
|
||||
try:
|
||||
parts = mitmproxy.net.http.url.parse(str(url))
|
||||
except ValueError as e:
|
||||
signals.status_message.send(message = "Invalid URL: " + str(e))
|
||||
return
|
||||
scheme, host, port, path = parts
|
||||
f = self.master.create_request(method, scheme, host, port, path)
|
||||
|
||||
21
test/mitmproxy/console/test_flowlist.py
Normal file
21
test/mitmproxy/console/test_flowlist.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import mitmproxy.tools.console.flowlist as flowlist
|
||||
from mitmproxy.tools import console
|
||||
from mitmproxy import proxy
|
||||
from mitmproxy import options
|
||||
from .. import tservers
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class TestFlowlist(tservers.MasterTest):
|
||||
def mkmaster(self, **opts):
|
||||
if "verbosity" not in opts:
|
||||
opts["verbosity"] = 1
|
||||
o = options.Options(**opts)
|
||||
return console.master.ConsoleMaster(o, proxy.DummyServer())
|
||||
|
||||
def test_new_request(self):
|
||||
m = self.mkmaster()
|
||||
x = flowlist.FlowListBox(m)
|
||||
with mock.patch('mitmproxy.tools.console.signals.status_message.send') as mock_thing:
|
||||
x.new_request("nonexistent url", "GET")
|
||||
mock_thing.assert_called_once_with(message="Invalid URL: No hostname given")
|
||||
Reference in New Issue
Block a user