Remove UserInfo and path/query for PAC URLs
This commit is contained in:
parent
5d0c9440f6
commit
9bb5c9fdab
@ -22,7 +22,7 @@
|
||||
import sys
|
||||
import functools
|
||||
|
||||
from PyQt5.QtCore import (QObject, pyqtSignal, pyqtSlot)
|
||||
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, QUrl
|
||||
from PyQt5.QtNetwork import (QNetworkProxy, QNetworkRequest, QHostInfo,
|
||||
QNetworkReply, QNetworkAccessManager,
|
||||
QHostAddress)
|
||||
@ -208,7 +208,10 @@ class PACResolver:
|
||||
Return:
|
||||
A list of QNetworkProxy objects in order of preference.
|
||||
"""
|
||||
result = self._resolver.call([query.url().toString(),
|
||||
string_flags = QUrl.RemoveUserInfo
|
||||
if query.url().scheme() == 'https':
|
||||
string_flags |= QUrl.RemovePath | QUrl.RemoveQuery
|
||||
result = self._resolver.call([query.url().toString(string_flags),
|
||||
query.peerHostName()])
|
||||
result_str = result.toString()
|
||||
if not result.isString():
|
||||
|
@ -171,6 +171,32 @@ def test_fail_return():
|
||||
res.resolve(QNetworkProxyQuery(QUrl("https://example.com/test")))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('url, has_secret', [
|
||||
('http://example.com/secret', True), # path passed with HTTP
|
||||
('http://example.com?secret=yes', True), # query passed with HTTP
|
||||
('http://secret@example.com', False), # user stripped with HTTP
|
||||
('http://user:secret@example.com', False), # password stripped with HTTP
|
||||
|
||||
('https://example.com/secret', False), # path stripped with HTTPS
|
||||
('https://example.com?secret=yes', False), # query stripped with HTTPS
|
||||
('https://secret@example.com', False), # user stripped with HTTPS
|
||||
('https://user:secret@example.com', False), # password stripped with HTTPS
|
||||
])
|
||||
def test_secret_url(url, has_secret):
|
||||
test_str = """
|
||||
function FindProxyForURL(domain, host) {{
|
||||
has_secret = domain.indexOf("secret") !== -1;
|
||||
expected_secret = {};
|
||||
if (has_secret !== expected_secret) {{
|
||||
throw new Error("Expected secret: " + expected_secret + ", found: " + has_secret + " in " + domain);
|
||||
}}
|
||||
return "DIRECT";
|
||||
}}
|
||||
""".format('true' if (has_secret or from_file) else 'false')
|
||||
res = pac.PACResolver(test_str)
|
||||
res.resolve(QNetworkProxyQuery(QUrl(url)))
|
||||
|
||||
|
||||
# See https://github.com/qutebrowser/qutebrowser/pull/1891#issuecomment-259222615
|
||||
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user