Merge branch 'more-pac' of https://github.com/abbradar/qutebrowser into abbradar-more-pac

This commit is contained in:
Florian Bruhin 2017-02-04 18:07:45 +01:00
commit 4c14b2983b
3 changed files with 43 additions and 2 deletions

View File

@ -614,7 +614,7 @@ def proxy_from_url(url):
scheme = url.scheme() scheme = url.scheme()
if scheme in ['pac+http', 'pac+https']: if scheme in ['pac+http', 'pac+https']:
return pac.PACFetcher return pac.PACFetcher(url)
types = { types = {
'http': QNetworkProxy.HttpProxy, 'http': QNetworkProxy.HttpProxy,

View File

@ -125,6 +125,47 @@ def test_invalid_port():
res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test"))) res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test")))
def test_no_function():
with pytest.raises(pac.EvalProxyError):
pac.PACResolver("")
def test_fail_eval():
with pytest.raises(pac.EvalProxyError):
pac.PACResolver("{")
@pytest.mark.parametrize("value", [
"",
"DIRECT FOO",
"PROXY",
"SOCKS",
"FOOBAR",
])
def test_fail_parse(value):
test_str_f = """
function FindProxyForURL(domain, host) {{
return "{}";
}}
"""
res = pac.PACResolver(test_str_f.format(value))
with pytest.raises(pac.ParseProxyError):
res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test")))
def test_fail_return():
test_str = """
function FindProxyForURL(domain, host) {
return null;
}
"""
res = pac.PACResolver(test_str)
with pytest.raises(pac.EvalProxyError):
res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test")))
# See https://github.com/The-Compiler/qutebrowser/pull/1891#issuecomment-259222615 # See https://github.com/The-Compiler/qutebrowser/pull/1891#issuecomment-259222615
try: try:

View File

@ -765,7 +765,7 @@ class TestProxyFromUrl:
@pytest.mark.parametrize('scheme', ['pac+http', 'pac+https']) @pytest.mark.parametrize('scheme', ['pac+http', 'pac+https'])
def test_proxy_from_url_pac(self, scheme): def test_proxy_from_url_pac(self, scheme):
fetcher = urlutils.proxy_from_url(QUrl('{}://foo'.format(scheme))) fetcher = urlutils.proxy_from_url(QUrl('{}://foo'.format(scheme)))
assert fetcher is pac.PACFetcher assert isinstance(fetcher, pac.PACFetcher)
@pytest.mark.parametrize('url, exception', [ @pytest.mark.parametrize('url, exception', [
('blah', urlutils.InvalidProxyTypeError), ('blah', urlutils.InvalidProxyTypeError),