From 19966a9b9f00f4f0bc4e975910a90f308471f4c6 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Mon, 2 Jan 2017 18:49:14 +0300 Subject: [PATCH 1/5] proxy_from_url: fix PACFetcher construction --- qutebrowser/utils/urlutils.py | 2 +- tests/unit/utils/test_urlutils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index e70cc41fa..1199c73f4 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -614,7 +614,7 @@ def proxy_from_url(url): scheme = url.scheme() if scheme in ['pac+http', 'pac+https']: - return pac.PACFetcher + return pac.PACFetcher(url) types = { 'http': QNetworkProxy.HttpProxy, diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py index 49bc85f07..0db43a0e6 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -765,7 +765,7 @@ class TestProxyFromUrl: @pytest.mark.parametrize('scheme', ['pac+http', 'pac+https']) def test_proxy_from_url_pac(self, 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', [ ('blah', urlutils.InvalidProxyTypeError), From aec002fa29ec4f54e986848f0f4876060653330b Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Mon, 2 Jan 2017 18:49:19 +0300 Subject: [PATCH 2/5] Add more tests for PAC --- tests/unit/browser/webkit/network/test_pac.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/unit/browser/webkit/network/test_pac.py b/tests/unit/browser/webkit/network/test_pac.py index ebb081aff..af03c9859 100644 --- a/tests/unit/browser/webkit/network/test_pac.py +++ b/tests/unit/browser/webkit/network/test_pac.py @@ -125,6 +125,47 @@ def test_invalid_port(): 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 try: From 660e3915a1016461f36e9381e1b6027f536aaec4 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 4 Feb 2017 18:08:53 +0100 Subject: [PATCH 3/5] Update docs --- CHANGELOG.asciidoc | 1 + README.asciidoc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 4c30d2dbb..4a0812ba1 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -38,6 +38,7 @@ Fixed - Fixed hints sometimes not working with Qt 5.8 - `:enter-mode` now refuses to enter modes which can't be entered manually (which caused crashes). - `:record-macro` (`q`) now doesn't try to record macros for special keys without a text. +- Fixed PAC (proxy autoconfig) not working with QtWebKit v0.9.1 ------ diff --git a/README.asciidoc b/README.asciidoc index 10f5a740b..0fa8dc9b0 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -187,6 +187,7 @@ Contributors, sorted by the number of commits in descending order: * Oliver Caldwell * Julian Weigt * Sebastian Frysztak +* Nikolay Amiantov * Jonas Schürmann * error800 * Michael Hoang @@ -197,7 +198,6 @@ Contributors, sorted by the number of commits in descending order: * Tomasz Kramkowski * Samuel Walladge * Peter Rice -* Nikolay Amiantov * Ismail S * Halfwit * David Vogt From 0cc7f845e6c34a729a2c8776ea50f3eebc2d352a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 4 Feb 2017 18:10:34 +0100 Subject: [PATCH 4/5] Simplify test --- tests/unit/browser/webkit/network/test_pac.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/unit/browser/webkit/network/test_pac.py b/tests/unit/browser/webkit/network/test_pac.py index af03c9859..c5c12b1a1 100644 --- a/tests/unit/browser/webkit/network/test_pac.py +++ b/tests/unit/browser/webkit/network/test_pac.py @@ -125,14 +125,10 @@ def test_invalid_port(): res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test"))) -def test_no_function(): +@pytest.mark.parametrize(string, ["", "{"]) +def test_wrong_pac_string(string): with pytest.raises(pac.EvalProxyError): - pac.PACResolver("") - - -def test_fail_eval(): - with pytest.raises(pac.EvalProxyError): - pac.PACResolver("{") + pac.PACResolver(string) @pytest.mark.parametrize("value", [ From 662859c133b0294a298df0128faf1ab0e31535d6 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 4 Feb 2017 18:10:57 +0100 Subject: [PATCH 5/5] Remove unnecessary inheritance on Python 3 --- qutebrowser/browser/network/pac.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/browser/network/pac.py b/qutebrowser/browser/network/pac.py index dfa4d42d6..91f15dfaf 100644 --- a/qutebrowser/browser/network/pac.py +++ b/qutebrowser/browser/network/pac.py @@ -126,7 +126,7 @@ class _PACContext(QObject): return QHostAddress(QHostAddress.LocalHost).toString() -class PACResolver(object): +class PACResolver: """Evaluate PAC script files and resolve proxies."""